Question

hope someone can give me a hint...

I have to work with mootools and have a form. One of the input fields is just valid if the value is the number 8. Does anyone has an idea how i could do this?

Best regards, Dan

Was it helpful?

Solution

If you post the html of that input I can help better. Otherwise:

var element = document.getElement('input');
//or 
var element = $('inputID');
//or
var element = document.querySelector('input');

Then use

element.value == 8 or element.get('value') == 8

You can check here also the Mootools docs


As @dimitar pointed out and I didn't mention, you need to listen for the submit of the form and then use this the code to check the input value.

Example:

var form = $('myForm');

form.addEvent('submit', function (e) {    // attach event to the form
    e.stop();                             // prevent it from being submited
    var input = this.getElement('input'); // get the input element
    if (input.value != 8) {               // verify the value
        alert('The value is not 8');      // inform the user
        return false;                     // end the function
    } else this.submit();                 // otherwise, continue the submit
});

Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top