Jump to content

problem with forms


Recommended Posts

<form name="myform" id="myform"><input type="text" name="mytext" id="mytext" /><input type="submit" value="enter text" /></form><script type="text/javascript"><!--var text = document.myform.mytext.value;document.write(text);--></script>

Why does this not work?

Link to post
Share on other sites
<form name="myform" id="myform"><input type="text" name="mytext" id="mytext" /><input type="submit" value="enter text" /></form><script type="text/javascript"><!--var text = document.myform.mytext.value;document.write(text);--></script>

Why does this not work?

It may becuase there is no submit type and no method in there try this:
<form name="myform" id="myform" method="get"><input type="text" name="mytext" id="mytext" /><input type="submit" value="enter text" onclick="showForm(this.form);"></form><script type="text/javascript"><!--function showForm(form1){for(var i=0; i<form1.length;i++){var text = document.getElementById('mytext').value;document.write(text);}}--></script>

Ok, over kill a little bit, but I only added the loop incase you have multiple inputs like name, day, country.. so on. Anyways you submit the form with the onclick event to the function showForm. anyways the variable text will get the data (note: use IDs with every input, becuase its easier to get using Jscript) of mytext.Then it simply prints out.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...