...

View Full Version : Fetch form value



florida
11-21-2010, 01:28 AM
I am trying to get a form value on an action page using JavaScript to alert the value.

The below doesnt alert anything after I hit the submit button in the one.html page:

one.html


<form action="two.html" method="get" id="myform">
<input type="text" name="city">
<input type="submit">


two.html


<html>
<head>
<script>
alert(document.myform.city.value);
</script>
</head>
<body>
</body>
</html>

Please advise.

DanInMa
11-21-2010, 01:40 AM
I am trying to get a form value on an action page using JavaScript to alert the value.

The below doesnt alert anything after I hit the submit button in the one.html page:

one.html


<form action="two.html" method="get" id="myform" name="myform">
<input type="text" name="city">
<input type="submit">


two.html


<html>
<head>
<script>
alert(document.myform.city.value);
</script>
</head>
<body>
</body>
</html>

Please advise.
try that. I beleive the myform in "alert(document.myform.city.value)" , refers to the name attrib of the form not the id

florida
11-21-2010, 02:18 AM
Still not working.
Please advise.

DrDOS
11-21-2010, 02:27 AM
<form action="two.html" method="get" id="myform" name="myform">

<input type="text" name="city">

<input type="submit" onclick="myval();">

</form>

</div>

<script>

function myval()

{

alert(document.myform.city.value);

}

</script>

florida
11-21-2010, 03:12 AM
Thanks that works on one.html but need the alert to show on the action which would be two.html.

Please advise.

DanInMa
11-21-2010, 03:38 AM
one.html


<form action="/two.html" method="get" id="myform">
<input type="text" name="city">
<input type="submit">
</FORM>


two.html


<html>
<head>
<script>
alert(location.search);
</script>
</head>
<body>
</body>
</html>
how about this? you may have to parse the resulting string ( http://www.eggheadcafe.com/articles/20020107.asp) , also oddly the data wasnt posting into the url without the / in front of two.html when i was trying.

DrDOS
11-21-2010, 04:51 AM
You need to have two forms with two different names and the closing tags.

Philip M
11-21-2010, 10:04 AM
If you are trying to pass a value from one page to another you must use window.name, a query string or a cookie. This subject has been covered very many times in this forum.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum