If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > display default value in drop down box?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-15-04, 05:48
zakyk zakyk is offline
Registered User
 
Join Date: Mar 2003
Posts: 32
Question 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
Reply With Quote
  #2 (permalink)  
Old 09-15-04, 06:37
RBARAER RBARAER is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 09-15-04, 21:06
zakyk zakyk is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 09-16-04, 05:34
RBARAER RBARAER is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 09-16-04, 07:09
zakyk zakyk is offline
Registered User
 
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.
Reply With Quote
  #6 (permalink)  
Old 09-16-04, 07:52
RBARAER RBARAER is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On