Javascript Split Data Into Form

G

gotcha

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("LINEPart").Value)%>'
arrayOfValues = thisValue.split(' ');
for (var i=0; i < arrayOfValues.length; i++)
document.write(arrayOfValues + ' <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,
(e-mail address removed)
 
G

Grant Wagner

gotcha said:
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("LINEPart").Value)%>'
arrayOfValues = thisValue.split(' ');
for (var i=0; i < arrayOfValues.length; i++)
document.write(arrayOfValues + ' <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,
(e-mail address removed)


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.Fields.Item("LINEPart").Value;
var thePrice;
if (/Price (\d+\.\d+)$/.test(partNoAndPrice)) {
// 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.Fields.Item("LINEPart").Value contain
such a strange combination of part number and price, why can't you
retrieve them separately in the first place?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top