SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member delhipro's Avatar
    Join Date
    Jul 2004
    Location
    India
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.location not working

    I have the following html page, but the window.location command is not working, while the next line alert("this is ms office") works perfectly, why window.location is not moving me to abc.html, if the user enters mso in the text box and clicks submit.

    <html>
    <head>
    <script type="text/javascript">

    function passcode()
    {
    course=document.serialenter.course.value;

    if (course=="mso")
    {
    window.location = "abc.html";
    alert("this is ms office");
    }
    else
    {
    alert("You have entered a wrong serial number");
    }

    }

    //-->>
    </script>



    </HEAD>
    <BODY>
    <form name=serialenter>
    <table width=100% border=0>
    <tr width=100% align=center><TD colspan=3>
    Please fill in the course code:
    <input type=text size=3 maxlength=3 name=course>
    <input type=submit value="Submit" name=submit onclick=passcode()>

    </td></tr>

    </table>
    </form>

    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try with something like this:


    <input type=text size=3 maxlength=3 id="course">
    <input type=submit value="Submit" name=submit onclick=passcode()>

    js:

    function passcode(){
    course = document.getElementById("course").value;
    if (course == "mso"){
    window.location = "abc.html";
    alert("this is ms office");
    }
    else
    {
    alert("You have entered a wrong serial number");
    }
    }


    OR


    function passcode(){
    course = document.getElementById("course");
    if (course.value == "mso"){
    window.location = "abc.html";
    alert("this is ms office");
    }
    else
    {
    alert("You have entered a wrong serial number");
    }
    }

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by delhipro View Post
    I have the following html page, but the window.location command is not working, while the next line alert("this is ms office") works perfectly, why window.location is not moving me to abc.html
    Because you're still submitting the form.

    Code:
    <script type='text/javascript'>
    
    function passcode(f)
    {
    course=f.course.value;
    
    if (course=="mso")
    {
     f.action='abcd.htm';
    }
    else
    {
    alert("You have entered a wrong serial number");
    }
    return false;
    }
    
    
    </script>
    
    <input type=submit value="Submit"  onclick='return passcode(this.form)'>
    Tab-indentation is a crime against humanity.

  4. #4
    SitePoint Member delhipro's Avatar
    Join Date
    Jul 2004
    Location
    India
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think logic ali is saying correct, but I am not able to correct my code, can you please help correcting my code, particularly i could not understand

    onclick='return passcode(this.form)'

    javascript code mentioned I can understand

  5. #5
    SitePoint Member delhipro's Avatar
    Join Date
    Jul 2004
    Location
    India
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I now tried this, but this is also not working

    <script type='text/javascript'>

    function passcode(f)
    {
    course=f.course.value;

    if (course=="mso")
    {
    f.action='abcd.htm';
    }
    else
    {
    alert("You have entered a wrong serial number");
    }
    return false;
    }


    </script>

    <form name=serialenter >
    <table width=100% border=0>
    <tr width=100% align=center><TD colspan=3>
    Please fill in the course code:
    <input type=text size=3 maxlength=3 name=course>
    <input type=submit value="Submit" onclick='return passcode(this.form)'>
    </table>
    </form>

  6. #6
    SitePoint Member delhipro's Avatar
    Join Date
    Jul 2004
    Location
    India
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now This is working, thanks every body for your help and you may use the below code, if any body else face the same problem, below is working example


    <script type="text/javascript">

    function passcode()
    {
    course=document.serialenter.course.value;


    if (course=="mso")
    {

    window.location = "activation.html";
    //alert("this is ms office");


    }
    else
    {
    alert("You have entered a wrong serial number");
    }

    }

    //-->>
    </script>



    </HEAD>
    <BODY>

    <form name=serialenter onsubmit="return passcode()">
    <table width=100% border=0>
    <tr width=100% align=center><TD colspan=3>

    <input type=text size=3 maxlength=3 name=course id=course>
    <input type=button value="Submit" onclick=passcode() >

    </td></tr>

    </table>
    </form>

    </body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •