Re: Javascript and forms
On Friday 15 November 2002 07:06, Try KDE wrote:
> The following works on my Mozilla:
... And with opera.
Thanx a lot, this did the trick.
-- Michael
> <script>
> function check(radio)
> {
> var selected = "";
> for (var i=0; i<radio.length; i++)
> {
> if (radio[i].checked) {
> selected = radio[i].value;
> }
> }
> alert ("The checked value is " + selected);
> }
> </script>
> <form action="http://localhost:1234/cgi">
> <input type="radio" name="r" value="b1" checked="checked" />
> <br>
> <input type="radio" name="r" value="b2" />
> <br>
> <input type="radio" name="r" value="b3" />
> <br>
> <input type="button" value="click" onclick="check(this.form.r)" />
> </form>
>
>
> -tk
>
> Michael Naumann wrote:
> >On Thursday 14 November 2002 03:20, Try KDE wrote:
> >>Your html is ill-formed. The text field should be:
> >> input type="text" name="n1" size=20
> >
> >Well, it is not n1, I had the problem with.
> >Even if I 'correct' it, I still can't see
> >the value of n0 (the radio-button).
> >
> >Anybody knows how to access the value of a radio-button in JavaScript ?
> >
> >-- Michael
> >
> >>-tk
> >>
> >>Michael Naumann wrote:
> >>>I have a small problem accessing form-vars via JavaScript.
> >>>In below example, I have two vars in a form,
> >>> one of type radio (n0)
> >>> and a normal input-var (n1).
> >>>
> >>>In the JavaScript Function CheckInput() I can acces the value of
> >>>n0, but not of n1
> >>>.
> >>>Depending on the browser, I get different results:
> >>> konqueror : always b1
> >>> opera : undefined
> >>> mozilla : undefined
> >>> galeon : undefined
> >>>
> >>>-----------
> >>><html>
> >>> <form name="ArgsForm" onsubmit="return CheckInput()">
> >>> b1 <input type="radio" name="n0" value="b1"><br>
> >>> b2 <input type="radio" name="n0" value="b2"><br>
> >>> string <input name="n1" size=20><br>
> >>> <input type="submit" value=" Execute ">
> >>> </form>
> >>> <Script language="JavaScript">
> >>> function CheckInput()
> >>> {
> >>> alert(document.ArgsForm.n0.value);
> >>> alert(document.ArgsForm.n1.value);
> >>> return false;
> >>> }
> >>> </Script>
> >>></html>
> >>>-----------
> >>>
> >>>So I must be missing something very obvious here.
> >>>Can anybody point me to the right direction?
> >>>
> >>>advTHANXance, Micahel
Reply to: