Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2003
    Posts
    32

    Question Unanswered: display default value in drop down box?

    here come my problem. i have drop down box which listing record from db and have onchange function which can populate textbox. my problem is how can i display in drop down default value like "-SELECT-" or just blank " ". i've try many ways but still didnt workout.

    'drop down code
    <select name="cboproc" size=1" id="cboproc" onChange="PopulateTextbox()">
    <% do until rstproc.eof
    lID = rstproc("pgprdc")%>
    <option value="<%=lID%>" selected><%=rstproc("pgdesc")%> </option>
    <%
    rstproc.MoveNext
    loop
    %>
    </select>

    <%
    rstproc.MoveFirst
    while not rstproc.EOF
    %>

    'for populate textbox
    <input name="HIDDEN" type=HIDDEN ID="intValue<%=rstproc("PGPRDC")%>" value="<%=rstproc("PGPRDC")%>">
    <input name="HIDDEN" type=HIDDEN ID="intCost<%=rstproc("PGPRDC")%>" value="<%=FormatNumber(rstproc("PGLPCO"),2)%>">
    <%rstproc.MoveNext
    wend
    rstproc.Close
    set rstproc.ActiveConnection = nothing
    set rstproc = nothing
    %>


    <script language=VBScript>
    sub window_onLoad
    PopulateTextbox
    end sub

    sub PopulateTextbox
    lID = document.frmTest.cboproc.value
    document.frmTest.txtValue.value = document.all("intValue" & lID).value
    document.frmTest.txtCost.value = document.all("intCost" & lID).value
    end sub
    </script>

    any idea ..pls help me out ? thank v much

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    My html/asp is a little bit rusted, but I think you just have to add the default choice at the beginning of your drop down, before getting db results :

    Code:
    'drop down code
    <select name="cboproc" size=1" id="cboproc" onChange="PopulateTextbox()">
    <option value="default" selected> - SELECT - </option>
    <% do until rstproc.eof
    lID = rstproc("pgprdc")%>
    <option value="<%=lID%>"><%=rstproc("pgdesc")%> </option>
    <% 
    rstproc.MoveNext
    loop
    %>
    </select>
    Also make this first option "selected", not the others, and make sure you don't populate your textbox when the user chooses this option.

    Regards,

    RBARAER

  3. #3
    Join Date
    Mar 2003
    Posts
    32
    hai..thanks

    anyway i've try your idea but still didnt work. the list in drop down display the last value not default value.

  4. #4
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    In your original code, all your options where "selected", that's why the last one is finally selected. Just set the FIRST one (default) to "selected". That should work.

    Regards,

    RBARAER

  5. #5
    Join Date
    Mar 2003
    Posts
    32

    Thumbs up

    i got u. it's works. i'll put at last for default value and alter vbscript. thank you very much.

  6. #6
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    You don't have to put the default option last, you can still put it first. Just make IT "selected", while all other options are NOT "selected" : the "selected" option is the one which will be displayed when the page is loaded. Of course, if all options are stated as "selected", the one to be displayed will be the last one you created. So ONLY ONE OPTION like this :

    <option value="some_value" selected>some_text</option>

    , that is the one to be displayed just after the page is loaded. All others should be like this :

    <option value="some_value">some_text</option>

    I hope it gets clearer for you now.

    Regards,

    RBARAER

Posting Permissions

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