Link to home
Start Free TrialLog in
Avatar of Luey
LueyFlag for United States of America

asked on

onchange from list menu

Hello i want to run my javascript when only the selection in my list menu of "New Homes for Sale"  and if any other is selected i do not want to run my javascript.
thanks
<html>
<head>
<script type="text/javascript">
function writeField(){
	document.getElementById('field2').value =  document.getElementById('field1').value ;
	return true;
}
</script>
</head>
<body>

  <p>
    <input name="field1" id="field1" type="hidden" value="1">
  </p>
  
  <p>
    <label>
      <input name="field2" type="text" id="field2"  value="0">
    </label>
  </p>
  
            <select name="property_type" class="text_field_small" id="property_type" onChange="return writeField();">
              <option value="Choose Type">Choose Type</option>
              <option value="REAL" >New Home for Sale</option>
              <option value="REAL">Used Home for Sale</option>
              <option value="HOME">Home for Rent</option>
              <option value="LAND">Land for Sale</option>
              <option value="COMS" >New Commercial for Sale</option>
              <option value="COMS">Used Commercial for Sale</option>
              <option value="COMR">Commercial for Rent</option>
            </select>

</body>
</html>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

"New Homes for Sale"

Without the "s" and by check the selected text :



<select name="property_type" class="text_field_small" id="property_type" onChange="if(this.options[this.selectedIndex].text == 'New Home for Sale') return writeField();">

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luey

ASKER

Thanks a bunch
You're welcome! Thanks for the points!
Avatar of Luey

ASKER

One more question. what if i wanted to do an "and" in the selected index.  Say i want to do number 1 and number 5 in the selected index.
use the logical OR operator || : if(this.selectedIndex == 1 || this.selectedIndex == 5) return writeField();
Avatar of Luey

ASKER

Thanks for all your help!!