View Full Version : Is it possible to make the listbox text always default?
08-30-2004, 04:10 AM
So the user enters a value in a textbox, and by selecting for e.g. inch, the value will be automatically converted to its meter equivalent.
<select name="L_Units" class="style4" style="width:61px;" onChange="Units_Conversion1()">
Since meter will always be the default unit, I wonder if this is possible: if the user selects millimeter/inch/feet from the listbox, rather than showing the label mm/inch/ft, the listbox label will automatically goes back to m (meter)...?
08-30-2004, 04:51 AM
Do you mean you want to restrict selection of mm/inch/ft options and only allowing m (meter)? Why not just put the meter option?
08-30-2004, 05:05 AM
Thanks for reply. Actually what I meant is the listbox is needed to tell which unit to convert, therefore I can't allowing only meter (m) option.
Because now the user has selected "inch", the listbox shows "inch" as the selected option. Since the conversion has already taken place, it might be confusing to the user as later he might think that is 25.40 inch and not 25.40 meter.
So I thought there could be a way of making the listbox option back to "m" immediately after the user selects "inch" and after the conversion taken place...
08-30-2004, 05:50 AM
Where is your function?
Since it is selected, just reset the form.
08-30-2004, 05:54 AM
Put this after the conversion in Units_Conversion1() function
document.forms.L_Units.selectedIndex = 0;
Or you can optimize your function by passing the this keyword that refers to the current element which is the L_Units combobox.
<select name="L_Units" class="style4" style="width:61px;" onChange="Units_Conversion1(this)">
//reset to default selected
objLUnits.selectedIndex = 0;
So all references to the L_Units combobox in the Units_Conversion1() function should be changed to just objLUnits.
08-30-2004, 06:37 AM
Thanks guys! That is exactly what I want :thumbsup:
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.