user633067
user633067

Reputation: 21

Calling javascript function in onsubmit

so I have this function defined in javascript..

function varReplace(formid)
{
    if (formid.factsc[0].checked == true) {
        formid.adddetails.value == "it's working";
    }
    else {
        formid.adddetails.value == "it's not working";
    }
}   

where I want to give adddetails a certain value if the factsc in html is clicked "yes".

On the html side, I call the function like this..

onsubmit="return varReplace(this.form)"

But it doesn't work.. any help would be much appreciated! Thanks in advance!

Upvotes: 2

Views: 5438

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

You are not returning anything from your function.

Note that in order to cancel the submit event, the onSubmit should be in the form onSubmit="return expression". "return" indicates that the value of the expression should be returned to the submit routine. If the expression evaluates to false, the submit routine is cancelled; if it is true, the submit routine goes forward.

Upvotes: 4

Related Questions