tags:

views:

53

answers:

4

Hello,

This is my part of my html

<input type="text" name="age" />
<input type="text" name="poscode" />
<input type="submit" name="submit" value="Next >>" disabled="disabled"/>

This is my script

<script type="text/javascript">
$(function(){
var enable = false;
if($("input[name='age']").val != "")
enable = true;
if($("input[name='poscode']").val != "")
enable = true;
if(enable == true) $("input[name='submit']").attr('disabled', '');
});
</script>

This is not working, any idea what i'm doing wrong?

After user filled up two input age & poscode, the submit button should become active ( disabled at start)

+1  A: 

Give this a shot, here is a fiddle that I created so you can play with it.

http://jsfiddle.net/9sxwN/

Matthew J Morrison
+3  A: 

You can do something like this:

$('input[name="age"], input[name="poscode"]').change(function(){
  if ($(this).val())
  {
    $("input[name='submit']").removeAttr('disabled');
  }
});
Sarfraz
`x.attr('disabled', boolean)` also works.
KennyTM
@KennyTM: Agreed, I find myself more used to `removeAttr` in those cases :)
Sarfraz
A: 

Did you attach this to the input fields in any way? The way your code is written, I believe the function is called once, after the document has been loaded, and then simply discarded. Give your function a name and attach it to onblur or onchange.

Christopher Creutzig
damien
A: 

Like sAc already mentioned, you have to remove the attribute 'disabled' altogether.

nyn3x