[Javascript] Re: Javascript probem in HTML Form
Roger Roelofs
rer at datacompusa.com
Fri May 21 08:01:15 CDT 2004
Saurabh,
On May 21, 2004, at 6:57 AM, saurabh sinha wrote:
> 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)
> ...<snip>...
>
> <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.
Either you are a bit unclear about how web forms work or I'm not
understanding your email. I highly reccomend the current edition of
O'Reilly's 'Javascript: The Definitive Guide' if javascript is new to
you. We could be more helpful if you could post a url to this page.
During the onsubmit phase, the state of the radio buttons only exists
in those radio buttons. When the furm is sent to the server for
processing, if the form method is 'get' the browser will create the
querystring based on the form field values. So, if the javascript is
from the same page as the form, the querystring will be empty. If the
javascript is on the 'receiving' page, set in the form's action
attribute, I'd recommend using one of the may url parsing scripts
available at the usual script repositories.
hth,
Roger
-------------------------------------------------------
Roger Roelofs web www.datacompusa.com
Datacomp Appraisal Services web www.mhvillage.com
3215 Eaglecrest Drive, NE Email rer at datacompusa.com
Grand Rapids, MI 49525-4593
More information about the Javascript
mailing list