Javascript Split Data Into Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gotcha

    Javascript Split Data Into Form

    I need to be able to split data such as this in a line:
    Part A23423 Price 45.00
    into just this A23423 and put that into a form field that I can post.

    I have the following code, but I can't figure out how to just get only
    that part number out of the line and put it in a post form.

    <script>
    var thisValue = '<%=(Recordset1 .Fields.Item("L INEPart").Value )%>'
    arrayOfValues = thisValue.split (' ');
    for (var i=0; i < arrayOfValues.l ength; i++)
    document.write( arrayOfValues[i] + ' <br> ');


    </script>


    <form name="form1" method="post" action="">
    <input name="textfield " type="text" value="WHAT DO I NEED TO PUT
    HERE">


    </form>

    Thanks for any help in advance,
    gil@ambry.com
  • Grant Wagner

    #2
    Re: Javascript Split Data Into Form

    gotcha wrote:
    [color=blue]
    > I need to be able to split data such as this in a line:
    > Part A23423 Price 45.00
    > into just this A23423 and put that into a form field that I can post.
    >
    > I have the following code, but I can't figure out how to just get only
    > that part number out of the line and put it in a post form.
    >
    > <script>
    > var thisValue = '<%=(Recordset1 .Fields.Item("L INEPart").Value )%>'
    > arrayOfValues = thisValue.split (' ');
    > for (var i=0; i < arrayOfValues.l ength; i++)
    > document.write( arrayOfValues[i] + ' <br> ');
    >
    > </script>
    >
    > <form name="form1" method="post" action="">
    > <input name="textfield " type="text" value="WHAT DO I NEED TO PUT
    > HERE">
    >
    > </form>
    >
    > Thanks for any help in advance,
    > gil@ambry.com[/color]

    If you have access to server side code, just use that to insert the value.
    There is no need for client-side JavaScript in your example:

    <%
    // assuming you're using JScript and not VBScript on the server
    var partNoAndPrice = Recordset1.Fiel ds.Item("LINEPa rt").Value;
    var thePrice;
    if (/Price (\d+\.\d+)$/.test(partNoAnd Price)) {
    // the above regexp assumes the value of partNoAndPrice
    // is exactly as you showed "Part A23423 Price 45.00"
    // if the above is NOT the format of partNoAndPrice
    // the regexp will have to be adjusted
    thePrice = RegExp.$1;
    } else {
    thePrice = 'Price could not be retrieved';
    }
    %>
    <input type="text" name="textfield " value="<%= thePrice %>">

    I have no idea why you would want to set a client-side variable from a
    server-side value, then use client-side technology to put it in the
    <input>. And why does Recordset1.Fiel ds.Item("LINEPa rt").Value contain
    such a strange combination of part number and price, why can't you
    retrieve them separately in the first place?

    --
    Grant Wagner <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    Working...