tags:

views:

72

answers:

7

jQuery live click isn't working form me if form contains input named "name". Changing name to something else helps. Can anyone tell me why that happens?

If there is a field name "named" live click is not working when I click input named "value". If I change name from "name" to "name2" clicking on field named "value" works.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"&gt;&lt;/script&gt;

<script>
$('form[name="prepare"] input[name="value"]').live('click', function(){
    alert('Clicked!');
    return false;
});
</script>

<form name="prepare" method="post">
    <input type="text" name="name" />
    <input type="text" name="value" />
</form>
A: 

See original question.

verbal
Please use the edit feature to edit your original post.
Mathias Bynens
A: 

Change the name="prepare" attribute/value pair of the FORM element to id="prepare" and it should work, like so:

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"&gt;&lt;/script&gt;
  <script>
   $('form#prepare input[name=value]').live('click', function() {
    alert('Clicked!');
    return false;
   });
  </script>
 <form id="prepare" method="post">
  <input type="text" name="name">
  <input type="text" name="value">
 </form>
Mathias Bynens
A: 

See original question.

verbal
+1  A: 

if you address your <form> by id instead of by name the bug disappears:

<form name="prepare" method="post" id="myform">

$('form#myform input[id="value"]').click(function(){
Antony Hatchkins
A: 

I can do few things to make this work. Still it bothers me what is why that happens.

verbal
This could be the reason: http://stackoverflow.com/questions/1995166/jquery-issue-with-live-click-and-input-named-name/1995259#1995259
Antony Hatchkins
A: 

@Mathias Bynens (Seems like it’s got nothing to do with the input[name="name"], but with the form[name="prepare"].)

Are you sure? Because when I change inputs name to something else it works but when I change name of the form (and selector of course) it isn't working.

verbal
Changing the `name` attribute of the form won’t help, you have to remove it, like I said in my answer: http://stackoverflow.com/questions/1995166/jquery-issue-with-live-click-and-input-named-name/1995181#1995181
Mathias Bynens
By the way, did you know you can add comments to answers, instead of adding new answers every time? ;)
Mathias Bynens
A: 

html specs:

<form>, name=

Note. This attribute has been included for backwards compatibility. Applications should use the id attribute to identify elements.

Since this attribute is deprecated, jquery may process it incorrectly.

Antony Hatchkins