Click to See Complete Forum and Search --> : javascript + submitting form


jasolio44
06-10-2004, 09:13 PM
hey, i can't figure out how to submit my form upon a javascript being true.

i've got a button that calls my function:
<input name="submit" type="button" value="Submit" onClick="validCCForm(this.form.ccType,this.form.ccnumber,this.form.expdate)">

the
validCCForm(this.form.ccType,this.form.ccnumber,this.form.expdate)
gives a series of popups if the fuction is false, and does nothing if it is true.


i've got a form that looks like this:
<form method="post" name="form2" action="<?php echo $editFormAction; ?>">

here's what the function looks like (it calls up other functions, but they're irrelevent):

function validCCForm(ccTypeField,ccNumField,ccExpField)
{
var result = isValidCreditCardNumber(ccNumField,ccTypeField.value,"Credit Card Number",true) &&
isValidExpDate(ccExpField,"Expiration Date",true);
return result;
}


what do i need to add to the code to make it go:

document.form2.submit();

if it's true

96turnerri
06-10-2004, 10:20 PM
try

<form ... onsubmit="return validCCForm(this.form.ccType,this.form.ccnumber,this.form.expdate)">

or

<form ... onsubmit="validCCForm(this.form.ccType,this.form.ccnumber,this.form.expdate)">

Kor
06-11-2004, 01:53 AM
explanation:

return true/false will let/stop a certain HTML or javascript action.

If using onclick, the only thing to let/stop is click action. Thus you have to use the event handler onsubmit, not onclick, because the action you want to manipulate is submit. Onsubmit is a <form> tag's handler.