Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a button perform two functions?

Status
Not open for further replies.

ss1

Programmer
Dec 7, 2000
4
US
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?

Thanks,
Sally
 
you can have it call a function that calls two functions... or you can add the validation to the print function
 
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.

Andy.
 
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.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top