javascript - Why is the first If 'is Not' statement not working? -


I see that except for the first option ("choose one") to see something else, Trying to leave left

Logic: Is it true that the price is not "selected"? If so, return the truth (submit form). I believe that the argument I need to check is whether the price is not the first option. My code seems right, but I think I "!" Operator properly

I have tried these versions "If val is no string, but they do not work.

  if (val! == 'select')   

Example of code below

  & form onsubmit = "Valid valid menu ()" & gt; & lt; Select ID = "dropdown" & gt; Option value = "Select" & gt; select one ... & lt; / option & gt; & lt; option value = "1" & gt; test1 & lt; / option & gt; lt; option value = "2" & gt; test 2 & lt; / option & gt; option value = "3"> test3 & lt; / option & gt; & lt; / select & gt; & lt; input Type = "submit "Value =" select "/>  
Message here: & lt; span id =" myspan "& gt; & lt; / span & gt; ] .text; if (val! = 'Select') {document.getElementById ("mySpan"). InnerHTML = "You have to make a selection.";} And {document.getElementById ("mySpan"). InnerHTML = "Success! You have selected" + txt; Returns;} Return Correct;}

You just flipped your argument backwards Does. If val! = 'Select' , this means that the user has made a selection. However, at that time if you are running for that argument when they are not. Your / if content needs to be flipped:

  function valid Mannu () {var dd = document.getElementById ("dropdown"); Var val = dd.options [dd.selectedIndex]. Values; Var txt = dd.options [dd.selectedIndex] .text; If (val! = 'Select') {document.getElementById ("mySpan"). InnerHTML = "Success! You chose" + txt; Return;} and {document.getElementById ("mySpan"). InnerHTML = "You have to make a selection.";} Return false;}   

However, if you want to keep the status of success as a second for some reason and failure condition If, as you are evaluating in (if), you will need to be on the contrary, so that due to the selection of the first option, be true:

  function is a valid menu ( ) {Var dd = document.getElementById ("dropdown"); Var val = dd.options [dd.selectedIndex] .value; Var txt = dd.options [Dd.selectedIndex] .text; If (val == 'select') {document.getElementById ("mySpan"). InnerHTML = "You have to make a selection."; Return return;} and {document.getElementById ("mySpan"). WinnerHTML = "success! You have selected" + txt;} right;}    ;

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -