onchange from list menu

Luey
Luey used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
"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

Multitechnician
Top Expert 2014
Commented:
Using the selected index :


<select name="property_type" class="text_field_small" id="property_type" onChange="if(this.selectedIndex == 1) return writeField();">

Open in new window

Author

Commented:
Thanks a bunch
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

leakim971Multitechnician
Top Expert 2014

Commented:
You're welcome! Thanks for the points!

Author

Commented:
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.
leakim971Multitechnician
Top Expert 2014

Commented:
use the logical OR operator || : if(this.selectedIndex == 1 || this.selectedIndex == 5) return writeField();

Author

Commented:
Thanks for all your help!!
leakim971Multitechnician
Top Expert 2014

Commented:
np

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial