0
  <script>
 $(document).ready(function() {
$('form["meldaan"] input').keyup(function() {

    var empty = false;
    $('form["meldaan"] input').each(function() {
        if ($(this).val() == '') {
            empty = true;
        }
    });

    if (empty) {
        $('#register').attr('disabled', 'disabled');
    } else {
        $('#register').removeAttr('disabled');
    }
});
});
</script>

This script works fine with one form, but I have two or three different forms on one page. I want each form to be treated different, if I use this code all fields in ALL forms need to be filled in, which I obviously don't want.

How can I identify the unique forms? Say one form is named name="formone" and the other name="formtwo". How would I implement that? (It's okay if I have to make more functions).

4
  • 1
    Why won't you give ids to your <form>?? Commented Nov 3, 2012 at 22:52
  • @gdoron you could, but names are more usual on forms and form elements. Commented Nov 3, 2012 at 22:56
  • @Christophe. Nonsense. id as much as I'm aware of can be used for any HTML tag. and "usual" ? usual if you need to select individual item when you have multiple, you give it id... Commented Nov 3, 2012 at 22:59
  • @gdoron wrong, id cannot be used on any HTML tag. But anyway that was not my point. Commented Nov 3, 2012 at 23:15

1 Answer 1

4

You just need to adjust your selector:

$('form[name="formone"] > input')

Update: @Andre, in your live example inputs are not direct children of the form element, so you need to use:

$('form[name="formone"] input')

Update 2: if you are using an id:

$('#formid input')
Sign up to request clarification or add additional context in comments.

7 Comments

That doesn't seem to work.. Strange. I tried it with ID too, but that didn't work as well.
@gdoron what do you mean by that?
@Christophe live demo at websiteuniversiteit.nl/new , Aanmelden is the first form and inloggen the second.
@gdoron added that but still doesn't work :( the live website is websiteuniversiteit.nl/new , aanmelden is the form.
@Christophe .. still not working.. See my updated post for the code I have at this point
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.