i am using javascript validation for my input box from javascript-coder but i have 2 problems here.
First: The validator in the script uses name to validate the object, is it possible to change to id in the gen_validatorv4.js and how?
Second: my page reloads itself despite of alert produces by the textbox. it's suppose to stay on the page and allow user to correct error.
below is my script placement
function submitform(){
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("amountperIteration","numeric","Name a price greater than $25");
frmvalidator.addValidation("amountperIteration","gt=25","Name a price greater than $25");
document.forms[0].submit();
}
my html code is simplify to something like that: (my back end is using python)
<form action="{{ request.path }}" name="myform" method="post" enctype="multipart/form-data" onsubmit="return false">
<input type="text" name="amountperIteration">
<input type="submit" value="submit" onclick="submitform&q开发者_StackOverflow社区uot;>
</form>
Any advice?
To answer your second question:
If validation fails, you want to return false
from the submit handler:
function submitForm() {
var result = validate(this);
if ( result === false ) { return false; }
}
That way the form submission process will be canceled.
精彩评论