Sunday, April 26, 2009

[jQuery] Re: How to select one of the many forms i have

This may help:

Script:
---------
$(document).ready(function(){
$("form[name='form1'] input[name='myRadio']").click(function(){
alert(this.value);
});
});


Form
--------
<form method="POST" action="--WEBBOT-SELF--" name="form1">
<p><input type="radio" value="V1" name="myRadio"></p>
<p><input type="radio" value="V2" name="myRadio"></p>
</form>

On Apr 25, 1:09 am, funkyasl <amritas...@gmail.com> wrote:
> Hi all,
> I'm a jquery newbie. I've been searching around the web a lot, but
> could not find an answer.
>
> My page has multiple forms (forma, formb, formc, etc). I want to
> select one particular form, say formb, without assigning an id to it,
> just by its name itself. How can i achieve this?
> I've tried:
> $("forms[name=formb]")
> but it doesnt work.
>
> My actual motive is to get hold of a radio group in this form, so that
> i can assign a click event to it.
> Something like:
> $("forms[name=formb] myselect").click(function(){
>         alert("radio selected: " + this.value);});
>
> I have no idea how to do this. I'm sure there must be some way to do
> this without assigning ids to it.
>
> Please help me. Thanks in advance :)

No comments: