[Javascript] Re: Javascript probem in HTML Form
saurabh sinha
sourav_s10 at yahoo.co.in
Fri May 21 05:57:11 CDT 2004
Hi,
I am facing a problem in the following:
There are two radio buttons within <form> tag. Initially none of the radio buttons is selected by default.
Now if any button (e.g. Football) is selected by user then after clicking on Submit button the radio button 'Football' should be shown as checked. (Code is given below)
Note that there is one query string 'Qstring' which returns the value, if any, that was provided by the user when they clicked 'submit'.
This means
If the user clicks on 'Football' button it will come as 'Qstring=FOOT' and for 'Cricket' it is 'Qstring=CRIC'.
When there is a value in the Qstring argument (i.e FOOT/CRIC), then the corresponding radiobutton should be checked when the form is presented again.
This is the html code:
<form name="form1">
<input type="radio" name="rd" value="FOOT"/>Football
<br />
<input type="radio" name="rd" value="CRIC"/> Cricket
<input type="Submit" value="Submit" />
</form>
JavaScript Code:
function on_submit()
{
var qry=location.search.substring(1,location.search.length);
var aa=qry.indexOf('Qstring=');
alert(aa);
if(aa!=-1)
{
var ss=qry.substring(aa+11,aa+17);
alert(ss);
if(ss=="FOOT")
{
form1.rd[0].checked=True;
}
else
{
form1.rd[1].checked=True;
}
}
}
I am calling the function 'on_submit()' from <input type="Submit" value="Submit" onclick="'on_submit()"/> but not getting the result.
Any help is highly appreciated.
Thanks & Regards,
Saurabh Sinha
Yahoo! India Matrimony: Find your partner online.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20040521/3c0e4eea/attachment.htm>
More information about the Javascript
mailing list