|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
won't stop submitting
I have got a validation script off the internet and for some reason when i perform the checkForm2 and checkForm3 functions they don't stop the form from submitting once the alert has been dismissed.
below is the code for my validation script. the validation script is called via onSubmit on the form. any help would be gratefully recieved // requires regex to be passed as a parameter function checkField(theForm, theField, theFieldDisplay, objRegex) { objField = eval("document." + theForm + "." + theField); if(!objRegex.test(objField.value)) { alert("Please enter a valid " + theFieldDisplay + "") objField.select(); objField.focus(); objField.style.border = "2px solid #c30" return (false); } objField.style.border = "2px solid #000000"; return (true); } // regex for the various form fields objReference = /^[0-9]{6}$/; objLender = /^[a-zA-Z]{3}$/; objTime = /^([0-9]{2})+([:0-9]{3})/; objComment = /([a-zA-Z])/; objFeedback = /([a-zA-Z]{1,100})/; function checkForm(theForm) { if(checkField(theForm, "reference", "Ref", objReference) && checkField(theForm, "lender_code", "Lender Code", objLender) && checkField(theForm, "time", "Time hh:mm", objTime)) { return true; } else { return false; } } function checkForm2(theForm) { if(checkField(theForm, "comment", "Comment", objComment)) { return true; } else { return false; } } function checkForm3(theForm) { if(checkField(theForm, "feedback", "Feedback", objFeedback)) { return true; } else { return false; } } |
|
#2
|
||||
|
||||
|
Quote:
|
|
#3
|
|||
|
|||
|
<form method=post name="name" onSubmit="checkForm('name')">
|
|
#4
|
|||
|
|||
|
HTML error
<form method=post name="name" onSubmit="checkForm('name')"> should be <form method=post name="name" onSubmit="return checkForm('name');"> |
|
#5
|
|||
|
|||
|
thankyou it finally works, now my boss won't gut me!
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|