Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Load Webpage in JS condition

Load Webpage in JS condition

Scheduled Pinned Locked Moved JavaScript
javascriptcomhelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14916200
    wrote on last edited by
    #1

    I have the following code and if the condition is true it should load a web page but it dont. Help would be appreciated: Enter your aggretate for your Matric final exam First name: Last name: function myFunction(){ var fname = document.getElementById("fname").value; if(fname > 40); window.location.href = "http://www.w3schools.com"; else alert("Condition xxxxx met") }

    Z Richard DeemingR O 3 Replies Last reply
    0
    • M Member_14916200

      I have the following code and if the condition is true it should load a web page but it dont. Help would be appreciated: Enter your aggretate for your Matric final exam First name: Last name: function myFunction(){ var fname = document.getElementById("fname").value; if(fname > 40); window.location.href = "http://www.w3schools.com"; else alert("Condition xxxxx met") }

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      This is very easy to debug, but only you can do it. We don't have access to your code. What is the value of fname when the if statement is hit?

      Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

      1 Reply Last reply
      0
      • M Member_14916200

        I have the following code and if the condition is true it should load a web page but it dont. Help would be appreciated: Enter your aggretate for your Matric final exam First name: Last name: function myFunction(){ var fname = document.getElementById("fname").value; if(fname > 40); window.location.href = "http://www.w3schools.com"; else alert("Condition xxxxx met") }

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Member 14916200 wrote:

        if(fname > 40);

        You have a syntax error in your script. If you check your browser's developer console, you should see an error logged telling you that the else is not expected. That's because you've got an extra semicolon at the end of your if line, which turns your code into:

        if (fname > 40) {
        // Do nothing
        }

        // Outside of the "if" block now...
        window.location.href = "...";

        // Invalid "else" statement:
        else {
        alert("...");
        }

        Remove the extra semicolon and your code should work. You should also put braces around the branches:

        if (fname > 40) {
        window.location.href = "...";
        }
        else {
        alert("...");
        }


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • M Member_14916200

          I have the following code and if the condition is true it should load a web page but it dont. Help would be appreciated: Enter your aggretate for your Matric final exam First name: Last name: function myFunction(){ var fname = document.getElementById("fname").value; if(fname > 40); window.location.href = "http://www.w3schools.com"; else alert("Condition xxxxx met") }

          O Offline
          O Offline
          Otekpo Emmanuel
          wrote on last edited by
          #4

          Hi there, As pointed by Richard Deem, there are many syntax errors. Editing your code as below should work.

          function myFunction(){
          var fname = document.getElementById("fname").value;

          if(fname > 40)
          {

          window.location.href = "http://www.w3schools.com";
          }
          else {
          alert("Condition xxxxx met");

          }
          }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups