简体   繁体   中英

html page direct

hello i am new at html i am designing a quiz in html. this is example with 2 questions only.when i click a submit button i want to calculate marks show it in a alert box and then go to result.htm page .but when i click submit alert box shows answer but page is not redirected forward to result.htm.

my code is:

            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title></title>
                <style type="text/css">
                   .d1
                   {
                       background-color:#FFFFCC;

                       } 

                    #Submit1
                    {
                        width: 67px;
                    }

                </style>
                <script language="javascript" type="text/javascript">

                    function Submit1_onclick() {
                        var i = 0;
                        var a = document.getElementById("Radio1");
                        if (a.checked == true) {
                            i++;
                        }
                        var b = document.getElementById("Radio8");
                        if (b.checked == true) {
                            i++;
                        }
                        alert(i);


            }

                </script>
            </head>
            <body>

                <p>
                    &nbsp;</p>
                    <form name="f1" method="post" action="d://result.htm">
                <div class="d1">
                Q1 What is your name ?
                <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                   a <input id="Radio1" name="R1" type="radio" value="t" />
                    b <input id="Radio2" name="R1" type="radio" value="f" />
                      c <input id="Radio3" name="R1" type="radio" value="f" />
                      d <input id="Radio4" name="R1" type="radio" value="f" /></div>
                       <br />  <br />  <br />   
                        <div class="d1">
                Q1 What is your Id ?
                <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                   1 <input id="Radio5" name="R11" type="radio" value="V1" />
                    2 <input id="Radio6" name="R11" type="radio" value="r1" />
                      3 <input id="Radio7" name="R11" type="radio" value="as1" />
                       4 <input id="Radio8" name="R11" type="radio" value="pop1" /></div>
                       <br />  <br />  <br /> 
                        <div class="d1">

                      <input id="Submit1" type="submit" value="submit" onClick="return(Submit1_onclick())"/><br />  
                    <br />  <br />
                </form>


            </body>
            </html>

As the last line of your function call

<script language="javascript" type="text/javascript">

                    function Submit1_onclick() {
                        var i = 0;
                        var a = document.getElementById("Radio1");
                        if (a.checked == true) {
                            i++;
                        }
                        var b = document.getElementById("Radio8");
                        if (b.checked == true) {
                            i++;
                        }
                        alert(i);
                        location.href="result.htm";

            }

                </script>

This will redirect the page

Change your markup to this:

<input id="Submit1" type="submit" value="submit" onclick="Submit1_onclick();"/>

and add this to your javascript:

function Submit1_onclick() {
    ...
    alert(i);
    return true;
}

Returning true from an event handler will tell the browser to continue the default behavior (in this case, submit the form).

Sounds like you're trying to submit a POST between two static files in an IIS server, which you can't do. You can change the files to .aspx and it should work as expected.

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