views:

1349

answers:

1

hi there,

has any one using Spring MVC with Jquery!

i have got a strange problem when handling Spring MVC tags with Jquery.

i used tags of spring MVC to get radiobuttons binded.

<form:form name="Form1" method="post" action="Form1.do" commandName="Page1Command">

<form:radiobutton path="group" value="TTSE" id="DevGroup_TTSE"  />
<form:radiobutton path="group" value="TTDE" id="DevGroup_TTDE"  />

now for some validation task i used Jquery selector as follows:

$("form:radiobutton").click(function() { 
   alert($(this).attr("id"));
 });

now surprisingly i am getting alert with value "Page1Command" the name i have give for commandName.

then i tried with id selector for one perticular radiobutton.

$("#DevGroup_TTDE").click(function(){
     alert($(this).attr("id"));
})

now i am getting the correct value as "DevGroup_TTDE"

what went wrong with this? can't we handle spring MVC tags with Jquery properly.

BTW, i am new to both technologies!

any help?

regards.

+1  A: 

The form: tags are interpreted on the server side, and generate regular HTML tags on the client side. Since jQuery is only running on the client side, it won't be able to find things using the form: tags. Try running the page and viewing the HTML source, then base your jQuery selectors on what you see there.

JacobM
thank you.yes, but why am i getting when i use id as selector
sangram
I don't understand what you are asking. Can you elaborate?
JacobM
oh, thank you jacob . that is working !i asked a stupid question. seems the post itself is stupid!thank you for the help
sangram