javascript - how would you write the if(...) statement for selection options in a form? -


how write if statement select option using javascript?

i wrote form , made select option list. want write if statement if option selected.

js

function name(obj) {     if (option.value == "cat") {         document.getelementbyid("owner").jim.disabled = true;     } } 

html

<p>     selection:*     <select id="sone" name="selection" size="1">         <option>select</option>         <option value="cat" onclick="name(this);">cat</option>         <option value="dog" onclick="name(this);">dog</option>         <option value="bird" onclick="name(this);">bird</option>         <option value="other" onclick="name(this);">other</option>     </select> </p> 

<select id= "sone" name="selection" onchange="check()"> <option value="cat">cat</option>  <option value="dog">dog</option> </select> <input type="text" id="res" size="25"/> 

and function :-

function check() {  var val = document.getelementbyid('sone').value;  if(val=='cat') {   document.getelementbyid('res').value = "thanks selecting cat";  } else {   document.getelementbyid('res').value = "please select cat";  } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -