简体   繁体   中英

Onclick function of javascript for submit button not working

I have checked the other same posts and I have done numerous changes but nothing seems to work! My goal is to create a form, in html, that when the user is submitting data having clicked on the plane or ship to redirect him in another form A and for the rest (train, bus) to the form B. For that I have the foo function in javascript. But when I click on submit button the onclick function does not work! Any ideas why?

<HTML>
<HEAD> <title> Ticket Choice </title></HEAD> 
   <SCRIPT type="text/javascript">
    function foo(){
        alert("Submit button clicked!");
        if (document.getElementById('buttonCheck1') || 
(document.getElementById('buttonCheck2')) {
document.forms['form0'].action="C:/Users/Jo/workspace/myAskisisDir/WebContent/formA.html";
        }
        else {
            document.forms['form0'].action="C:/Users/Jo/workspace/myAskisisDir/WebContent/formB.html";

        }

    }
</SCRIPT>
<BODY>
<h1> Choice of transfer ticket </h1>
<FORM id = "form0"  method = "GET">
<fieldset title = "plane">
<input type = "radio" onclick = "javascript:IsCheck(1);" name = "button" id =
"buttonCheck1"> PLANE <br>
 </fieldset>
<fieldset title = "ship">
<input type = "radio" onclick = "javascript:IsCheck(2);" name = "button" id =
"buttonCheck2"> SHIP <br>
</fieldset>
<fieldset title = "train">
<input type = "radio" onclick = "javascript:IsCheck(3);" name = "button" id =
"buttonCheck3">train<br>
</fieldset>
 <fieldset title = "bus">
 <input type = "radio" onclick = "javascript:IsCheck(4);" name = "button" id =
"buttonCheck4"> bus <br>
    </fieldset>
<input type="submit" value="submit" onclick = "foo();"/>
<input type = "reset"/>
 </FORM>
</BODY>
</HTML>

syntax error

if (document.getElementById('buttonCheck1')||(document.getElementById('buttonCheck2')) {

should have been

if (document.getElementById('buttonCheck1') || document.getElementById('buttonCheck2')) {

now you can feel stupid :P

Try it, this triggers the onclick function. Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM