Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Malaysia
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is it possible to make the listbox text always default?

    Hi, I have the following listbox which, together with another javascript, able to perform unit conversions.

    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.

    Code:
    <select name="L_Units" class="style4" style="width:61px;" onChange="Units_Conversion1()">
    <option selected>m</option>
    <option value="mm">mm</option>
    <option value="inch">inch</option>
    <option value="ft">ft</option>
    </select>
    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)...?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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?

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Malaysia
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi glenngv,

    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.

    When the user enters say, 1000 in the textbox, if he means it to be 1000 meter, then he doesn't have to select any other options in the listbox because the default is already meter (m). But if he means it to be 1000 inch, he will need to select the "inch" option so that the background javascript will automatically convert the 1000 inch to 25.40 meter. And so on...

    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...

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    onChange="Units_Conversion1()">

    Where is your function?


    <option selected>m</option>

    Since it is selected, just reset the form.


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Put this after the conversion in Units_Conversion1() function

    document.forms[0].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.
    Code:
    <select name="L_Units" class="style4" style="width:61px;" onChange="Units_Conversion1(this)">
    ...
    function Units_Conversion1(objLUnits){
       ...
       //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.

  • #6
    New Coder
    Join Date
    Aug 2002
    Location
    Malaysia
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys! That is exactly what I want


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •