I'm creating a form that will not be submitted but it will be printed. The 'print form' button's 'onClick event' calls the print function, but I need to add a validation function before the print option comes up. Any ideas?
Surely you can reference a "validation" function from within the print function i.e (v.loosely):
function validateForm(element)
{
/* any validation code ..
can include notification and re-focus on failure..
alert("Your entries are invalid" ..
element.focus(); ..
return 0 if passes validation, else return -1
*/
}
function printForm()
{
if (validateForm(document.yourform.element) == 0)
{
.. put your current print function here ..
}
}
Hope that it is of some help. There are lots of validation scripts on the web, or I can post "numbers only" or "chars only" examples if you want.
You can code pure javascript in an onClick event, so you could do onClick="fnValidate() ? fnPrint() : void();"
Which basically means ... when I click the button, call fnValidate to validate the form. If it's valid, then call fnPrint to print it, otherwise do nothing.
This also assumes fnValidate will return a value indicating success of failure.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.