Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collecting data from input text boxes and displaying it in the table

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
0
0
US
Hello.

Let's say I grab data from database and displaying it in the input text boxes. When user presses on the button I want to grab the data from those textboxes and display it in the table that will be generated in the new opened window. I can collect the data from input text boxes with the code similar to the one below. But how can I then grab that info and place it inside the table in the new window. Can anybody help?

<script>

function cycle() {
var aData = '';
for (var i = 0; i<document.pricesform.elements.length; i++) {
if ((document.pricesform.elements.type == 'text') || (document.pricesform.elements.type == 'hidden')) {
aData += document.pricesform.elements.value + ',';
}
}
alert(aData);
}
</script>

<form name=&quot;pricesform&quot;>
<input type=&quot;text&quot; name=&quot;myTextA&quot; value=&quot;apple&quot; size=&quot;20&quot;>
<input type=&quot;text&quot; name=&quot;myTextB&quot; value=&quot;orange&quot; size=&quot;20&quot;>
<input type=&quot;text&quot; name=&quot;myTextC&quot; value=&quot;banana&quot; size=&quot;20&quot;>
<br>
<input type=&quot;text&quot; name=&quot;myTextD&quot; value=&quot;pear&quot; size=&quot;20&quot;>
<input type=&quot;text&quot; name=&quot;myTextE&quot; value=&quot;peach&quot; size=&quot;20&quot;>
<input type=&quot;text&quot; name=&quot;myTextF&quot; value=&quot;grape&quot; size=&quot;20&quot;>
<br>
<input type=&quot;hidden&quot; name=&quot;myTextG&quot; value=&quot;pumpkin&quot; size=&quot;20&quot;>
<input type=&quot;hidden&quot; name=&quot;myTextH&quot; value=&quot;cranberry&quot; size=&quot;20&quot;>
<input type=&quot;hidden&quot; name=&quot;myTextI&quot; value=&quot;tomato&quot; size=&quot;20&quot;>
<input type=&quot;button&quot; onClick=&quot;cycle()&quot; value=&quot;Check&quot;> </p>
</form>
 
The only client-side way I know of to do this would be to submit the form via the &quot;get&quot; method and then parse the window.location for variables and put them into your table.

For instance:

<form name=&quot;pricesform&quot; method=&quot;get&quot; action=&quot;page.html&quot;>

If you submit this form, you'll see you get the name/value pairs amended to the end of the URL. It starts at the question mark, and each pair is separated by an ampersand. I.e.:

Code:
[URL unfurl="true"]http://www.example.com/page.html?myTextD=pear&myTextE=peach[/URL]
                                ^            ^
                                start        separator
                                        ^                ^
                                       pair             pair

From there, I'd investigate string functions, specifically the built-in split() function.

Good luck.

P.S. This gets very easy with a server-side scripting language at your disposal. I know of know way to mimick that behavior in JavaScript (via the 'post' and 'get' variables).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top