-1

Can I have yout help pleas there,I make a validation field for a popup form :

 function prepareEventHandlers() {
document.getElementById("contact").onsubmit = function () {
if (document.getElementById("message").value == '') {
    document.getElementById("errorMessage").innerHTML = 'the field should not be empty!';
    return false;
}
else {
    document.getElementById("errorMessage").innerHTML = '';
    return true;
}
};
}


window.onload = function () {
prepareEventHandlers();
}

then the html code :

<div id="form-content" class="modal hide fade in" style="display: none;">

        <div class="modal-body">
            <form class="contact" name="contact" >
                <label class="label" for="message">Enter a Message</label><br>
                                    <textarea id="message" name="message" class="input-xlarge"></textarea>             
                                    <p><span id="errorMessage"></span></p>
            </form>
        </div>
        <div class="modal-footer">
            <input class="btn btn-success" type="submit" value="Send!" id="btnsubmit">
            <a href="#" class="btn" data-dismiss="modal">No!</a>
        </div>

and I got this error :

TypeError: document.getElementById(...) is null document.getElementById("contact").onsubmit = function () {

Any Idea?

Edit:

OK I add id="contact" to my form so the error is gone but now the popup form is displyaed but when I try to click send with empty or not empty value nothing is happened...

4

1 回答 1

1

</form>之后才关闭<input class="btn btn-success" type="submit" value="Send!" id="btnsubmit">

并将html表单ID更改为contact

于 2013-07-08T12:07:39.877 回答