Settings a value to new Option()

Hi all,

I have a function, that I am using to change the options in 2 drop down menu’s, function is working no problem, only thing now is, I need to set the value of the option different to the text inside the <option> tag.

The Code:


   <script>
   	function set_options(opt) 
   	{ 
   		var lop = document.isc.lop;
   		var hip = document.isc.hip;
   		
   		lop.options.length = 0; 
   		hip.options.length = 0;
   		
   		if (opt == "5") 
   		{
   			// Set second drop down options
   			lop.options[lop.options.length] = new Option('10000');
 			lop.options[lop.options.length] = new Option('200000');
 			lop.options[lop.options.length] = new Option('300000');
 			lop.options[lop.options.length] = new Option('400000');
 			lop.options[lop.options.length] = new Option('500000');
 			lop.options[lop.options.length] = new Option('750000');
 			lop.options[lop.options.length] = new Option('1000000');
   			
   			// Set third drop down options
 			hip.options[hip.options.length] = new Option('200000');
 			hip.options[hip.options.length] = new Option('300000');
 			hip.options[hip.options.length] = new Option('400000');
 			hip.options[hip.options.length] = new Option('500000');
 			hip.options[hip.options.length] = new Option('750000');
 			hip.options[hip.options.length] = new Option('1000000');
 			hip.options[hip.options.length] = new Option('2000000');
 			hip.options[hip.options.length] = new Option('5000000');
   		}
   		if (opt == "1") 
   		{ 
   			// Set second drop down options
   			lop.options[lop.options.length] = new Option('1000');
   			lop.options[lop.options.length] = new Option('2000');
   			lop.options[lop.options.length] = new Option('3000');
   			lop.options[lop.options.length] = new Option('4000');
   			lop.options[lop.options.length] = new Option('5000');
   			lop.options[lop.options.length] = new Option('7500');
   			lop.options[lop.options.length] = new Option('10000');
   			
   			// Set third drop down options
   			hip.options[hip.options.length] = new Option('2000');
   			hip.options[hip.options.length] = new Option('3000');
   			hip.options[hip.options.length] = new Option('4000');
   			hip.options[hip.options.length] = new Option('5000');
   			hip.options[hip.options.length] = new Option('7500');
   			hip.options[hip.options.length] = new Option('10000');
   			hip.options[hip.options.length] = new Option('20000');
   			hip.options[hip.options.length] = new Option('50000');
   		}
   	} 
   </script>
   <form action="/" method="post" name="isc" target="_parent" id="isc" onsubmit="submit_form();">
 		<select size="1" name="saleorrent" class="formfield" id="letsale" onchange="set_options(document.isc.saleorrent.options[document.isc.saleorrent.selectedIndex].value);">
   			<option value="5">Homes for sale</option>
   			<option value="1">Homes to LET</option>
   		</select>
   
 			<SELECT name="lop" class="formfield" id="select1">
 		 	<option value="100000">&pound;100,000</option>
 		 	<option value="200000">&pound;200,000</option>
 		 	<option value="300000">&pound;300,000</option>
 		 	<option value="400000">&pound;400,000</option>
 		 	<option value="500000">&pound;500,000</option>
 		 	<option value="750000">&pound;750,000</option>
 		 	<option value="1000000">&pound;1,000,000</option>
   			</SELECT>
   
   		<select name="hip" class="formfield" id="select">
 			<option value="200000">Up to &pound;200,000</option>
 			<option value="300000">&pound;300,000</option>
 			<option value="400000">&pound;400,000</option>
 			<option value="500000">&pound;500,000</option>
 			<option value="750000">&pound;750,000</option>
 			<option value="1000000">&pound;1,000,000</option>
 			<option value="2000000">&pound;2,000,000</option>
 			<option value="10000000">&pound;5,000,000 +</option>
   		</select>
 			<input name="Submit" type="submit" id="searchBtn" value="Search">
   	</form>
   

Now how it looks when it loads, is how I need the value’s to come out, does anyone know how to set each value for each option, as new Option() sets the value and the text in the <option> tag as the same.

Any help would be appreciated, and if anyone can see improvements to the function please feel free to comment as I am no javascript guru :slight_smile:

Thanks in advance.

new Option() can take 2 arguments. The first is the text, the second is the value:

new Option(“Display text”,value);

I knew it was going to be something simple!! aarg.

Thanks distinct.

on the same problem, I am using

lop.options[lop.options.length] = new Option(“£100,000”, ‘100000’);

When the Javascript displays the £ sign, it comes up as a question mark, and if I try use £ it writes that out and doesnt display, any idea how to make the £ sign appear?

That’s happening because Javascript can’t believe that the prices are so high.

try \u00A3
:slight_smile:

aaaah, thanks jimfraser! where would I be able to find an extended list of those codes? and what are those codes? or that code? sorry to be a pain!

Check out http://www.unicode.org/charts/