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)
You can do something like this:
$('input[name="age"], input[name="poscode"]').change(function(){
if ($(this).val())
{
$("input[name='submit']").removeAttr('disabled');
}
});
To enable/disable when key is pressed do this way:
$('input[name="age"], input[name="poscode"]').keyup(function(){
if ($(this).val())
{
$("input[name='submit']").removeAttr('disabled');
}else{
$("input[name='submit']").attr('disabled','disabled');
}
});
Give this a shot, here is a fiddle that I created so you can play with it.
http://jsfiddle.net/9sxwN/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With