Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys,

Im having a problem in my code, i want to change the text of my drop-down list after i select and click a button, i want to select the default text of my drop-down list which is "Select" after clicking a button,
For example i choose "PCS" in my list after i click the button the list should change its text to Select.
I've been stock on this process and don't know what do, can you please give me a hand, here's my sample code. Thank you very much.

<script>
function Request()
{

var list= document.getElementsByName('unit')[0].text= 'Select';

}
</script>

	
$listof_products .='<select id="unit" name="unit" style="margin-left: 10px;">
        <option value="" selected="selected">Select</option>
	
	<option value="PCS">PCS</option>
       
        <option value="RMS">RMS</option>
	
	
	<option value="PKG">PKG</option>
	
		
        $listof_products .='</select>';



  <button name="addtocart" title="Request Quotation Price" class="redButton" type="submit"  önclick="Request()"><span><span>Request Quote</span></span></button>
Posted
Updated 20-Jul-11 16:51pm
v2
Comments
walterhevedeich 20-Jul-11 22:58pm    
By quickly looking at your onclick, it seems you have spelled it with an ö instead of o. This might solve the issue?
[no name] 20-Jul-11 23:08pm    
I've already change that, sorry just typo error, but still the code is stil not working, do you have any idea?
walterhevedeich 21-Jul-11 1:30am    
Can you describe more what you mean by its not working? Are there any errors? Or what should it do that it is not doing?
[no name] 21-Jul-11 2:08am    
what i mean by it's not working is that, nothing happens and the list text didn't change, am i doing wrong in my code?

Try using this Javascript function

C#
<script>
function Request()
{
   document.getElementById('unit').value= 'Select';
}
</script>
 
Share this answer
 
Comments
[no name] 21-Jul-11 3:21am    
its not working, i want to change the text of the list, not the value of it.
[no name] 21-Jul-11 3:37am    
maybe the text cannot be change, i think the approach must be change the selected of the list.
Plz try this

function Request()
{
document.getElementsByName('unit').value = "";
}
 
Share this answer
 
Comments
[no name] 21-Jul-11 3:21am    
its not working, i want to change the text of the list, not the value of it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900