0

I have the following html:

<p>Genre: {{ create_production_form.genre }}</p>
<p>Privacy: {{ create_production_form.privacy }}</p>
<p><input type="submit" name="next" value="Next" disabled="disabled"></p>

How would I make the next button clickable only after Genre and Privacy are filled in? For example, something like:

if ($("id_genre").val() && $("id_privacy").val()) {
    $("input[name=next]").attr("disabled","")
}

The only thing is, it'd need to be 'live', so it can detect when all these fields are filled in.

David542
  • 104,438
  • 178
  • 489
  • 842

5 Answers5

1

Wut? The 'event' handles the delegation, so the 'event handler' needs to have live() or on() depending on the version of jQuery you're using. This means that an essential piece of the equation has been left out.

The 'event' methods I'm speaking of are submit, change or click. You must delegate the code to one of these events -- using the aforementioned live() or on() methods.

Otherwise, if you're just simply looking to enable them if data has been fille din.

$('form :input').change(function(){
  if ($("id_genre").val() && $("id_privacy").val()) {
    $("input[name=next]").attr("disabled","")
  }
});

This wil check the form to see if the inputs change, if they do, it will test the values and you'll get your result.

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
0

Assuming they're both text-inputs, you could validate on keyup, otherwise validating on change would also work.

ahren
  • 16,803
  • 5
  • 50
  • 70
0

try using on hover cause user has to hover over the button before click i hope it helps

$("input[name=next]").hover(function() {


    if ($("id_genre").val()!="" && $("id_privacy").val()!="") {
        $("input[name=next]").removeAttr("disabled")
    }
});
COLD TOLD
  • 13,513
  • 3
  • 35
  • 52
0
 $('form').change(function() {
    if ($("id_genre").val().length > 0 && $("id_privacy").val().length > 0) {
        $("input[type='submit']").prop("disabled", false)
    }
  })
Ram
  • 143,282
  • 16
  • 168
  • 197
0

Demo http://jsfiddle.net/8AtAz/1/

In the demo when you click the valid button it will enable the next button: Please lemme know if I missed any point.

code

$("input[type='submit']").prop('disabled', true);
$("#valid").click(function() {

    $("input[type='submit']").prop('disabled', false);
})​

OR In your case

 if ($("id_genre").val() != "" && $("id_privacy").val() != "") {
        $("input[type='submit']").prop("disabled", false)
    }
Tats_innit
  • 33,991
  • 10
  • 71
  • 77