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. Trying to compare cancel from prompt dialog not working

Trying to compare cancel from prompt dialog not working

Scheduled Pinned Locked Moved JavaScript
toolshelp
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.
  • R Offline
    R Offline
    RabbitTrail
    wrote on last edited by
    #1

    Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.

    <!--
    var color = prompt("Enter a color","Enter red, white, or blue.")

    function colorTest(){

        //\*\*\*\*\*\*\*\*\*\* if statement not working properly
    if(color === null){
    	break;
    }
    
    switch(color){
    case "red":
    	alert("You have entered the color ' red '");
    	break;
    case "white":
    	alert("You have entered the color ' white '");
    	break;
    case("blue"):
    	alert("You have entered the color ' blue '");
    	break;
    default:
    	alert("You did not enter a valid color");
    	
    }
    

    }//end function

    //-->

    Kornfeld Eliyahu PeterK Z T 3 Replies Last reply
    0
    • R RabbitTrail

      Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.

      <!--
      var color = prompt("Enter a color","Enter red, white, or blue.")

      function colorTest(){

          //\*\*\*\*\*\*\*\*\*\* if statement not working properly
      if(color === null){
      	break;
      }
      
      switch(color){
      case "red":
      	alert("You have entered the color ' red '");
      	break;
      case "white":
      	alert("You have entered the color ' white '");
      	break;
      case("blue"):
      	alert("You have entered the color ' blue '");
      	break;
      default:
      	alert("You did not enter a valid color");
      	
      }
      

      }//end function

      //-->

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      That break inside the if does nothing...only jumps out of the if and continues to the switch! You meant return I think...

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      1 Reply Last reply
      0
      • R RabbitTrail

        Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.

        <!--
        var color = prompt("Enter a color","Enter red, white, or blue.")

        function colorTest(){

            //\*\*\*\*\*\*\*\*\*\* if statement not working properly
        if(color === null){
        	break;
        }
        
        switch(color){
        case "red":
        	alert("You have entered the color ' red '");
        	break;
        case "white":
        	alert("You have entered the color ' white '");
        	break;
        case("blue"):
        	alert("You have entered the color ' blue '");
        	break;
        default:
        	alert("You did not enter a valid color");
        	
        }
        

        }//end function

        //-->

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

        Just put a breakpoint and see what the value of color is.

        There are only 10 types of people in the world, those who understand binary and those who don't.

        1 Reply Last reply
        0
        • R RabbitTrail

          Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.

          <!--
          var color = prompt("Enter a color","Enter red, white, or blue.")

          function colorTest(){

              //\*\*\*\*\*\*\*\*\*\* if statement not working properly
          if(color === null){
          	break;
          }
          
          switch(color){
          case "red":
          	alert("You have entered the color ' red '");
          	break;
          case "white":
          	alert("You have entered the color ' white '");
          	break;
          case("blue"):
          	alert("You have entered the color ' blue '");
          	break;
          default:
          	alert("You did not enter a valid color");
          	
          }
          

          }//end function

          //-->

          T Offline
          T Offline
          twseitex
          wrote on last edited by
          #4

          prompt returns a string var to check an var take if(color!=null) ... to check the value of var take if(color!='') and so on break-statement is not a member of if-statement

          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