2

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!

1
  • If you are using FireFox, you should be able to pull up any JavaScript errors with CTRL+SHIFT+J. Commented Feb 24, 2011 at 23:00

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

varReplace doesn't have a return, but I'm not sure that's his problem.
I agree with Jakub, you need to be returning in the function.
@mellamokb - since onsubmit doesn't return a value that can be evaluated to true the actual form submit is cancelled. I suspect this is what 'doesn't work'.
Since he's setting a form control value to "it's working" or "it's not working", I would expect he's looking for that change to appear on the form, and it's not. Just my thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.