Get dat from web form and distplay as text in browser

P

patrickbartell

Hi,

What I need to do is to get my form data to display in the webpage
when submit is clicked. I can get the first input box but after that
not the rest. I am trying to loop through all the elements but it just
stops after the first one.

This is my javascript called new.js:

function newText() {

var my_var=document.getElementById("formId");

for (var i=0;i<my_var.length;++i){
document.write(my_var.value + "<br >");

}
}


And this is my form:

<script type="text/javascript" src="new.js"></script>



<form method="post" action="" onsubmit="newText()" id="formId">
<blockquote>
<blockquote>
<table border="0" cellpadding="8" cellspacing="0" width="50%"
style="margin:auto">
<tr>
<td align="right" style="white-space:nowrap">First Name:</td>
<td><input type="text" name="FirstName" size="25" id="formId1"/></td>
</tr>
<tr>
<td align="right" style="white-space:nowrap">Last Name:</td>
<td><input type="text" name="LastName" size="25" id="formId2"/></td>
</tr>
<tr>
<td align="right" style="white-space:nowrap">Poet?</td>
<td>
<input type="radio" name="Poet" value="Yes"/>Yes&nbsp;<input
type="radio" name="Poet" value="No"/>No
</td>
</tr>
<tr>
<td align="right" valign="top" style="white-space:nowrap">Favorite
Poem</td>
<td>
<select name="Poem" size="1">
<option>Paul Revere's Ride</option>
<option>The Day is Done</option>
</select>
</td>
</tr>
<tr>
<td align="right" valign="top" style="white-space:nowrap">Comments</
td>
<td>
<textarea rows="6" name="Comments" cols="29"></textarea></td>
</tr>
<tr>
<td class="center" colspan="2">
<input type="submit" value="Submit Form"/>
<input type="reset" value="Reset Form"/>
</td>
</tr>

</table>
</blockquote>
</blockquote>
</form>
 
D

David Mark

Hi,

What I need to do is to get my form data to display in the webpage
when submit is clicked. I can get the first input box but after that
not the rest. I am trying to loop through all the elements but it just
stops after the first one.

This is my javascript called new.js:

function newText() {

        var my_var=document.getElementById("formId");

Use the forms collection.
        for (var i=0;i<my_var.length;++i){
        document.write(my_var.value + "<br >");


Wipes out the old document, starts a new one. Script is gone.

[snip]
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top