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 > combo default value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-04, 21:52
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
Question combo default value

I thought I had already posted this question but I can't find the answer so I will ask again.
This is the code for a combo box, and I would like to make certain value the default value, so that appears unless users select somthing else.

call rs.Open("SELECT * FROM Trim.dbo.luDecisionMaker ORDER BY DecisionMakerName" _
, myCon)

do while not rs.EOF
Response.Write("<OPTION value=" & rs("DecisionMakerID"))
if rs("DecisionMakerID") = nDecisionMaker then
Response.Write(" selected")
end if
Response.Write(">" & _
rs("DecisionMakerName") & "</OPTION>" & Chr(10))
rs.MoveNext
loop

rs.Close

It comes from a table and has PropertyDetailsID(1,2,3,4) and PropertyDetailsname(Fee, 5,10,Other) and for example "Fee" needs to be the dafault value.

Could somebody help me with that please, I am sure a lot of people would need to do this but there is not much out there about this.

Regards and thanks to all
Reply With Quote
  #2 (permalink)  
Old 10-19-04, 22:10
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
This looks good to me.... assuming you are looping inside a select box....

What is actually happening when you use this code??
Reply With Quote
  #3 (permalink)  
Old 10-19-04, 23:21
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
I have had a confusing comment for another forum as well, I am probably not explaining myself properly.

That code populates the combo with values from the table,but there is nothing selected and users want value " Fee" to be selected when the page is loaded as I suppose that is the most used answer,that is all instead of selecting it themselves they want it to be loaded automatically.

And I am thinking is there a way I can alter this code so that I make "Fee" default or how would you do it all.
Reply With Quote
  #4 (permalink)  
Old 10-19-04, 23:59
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
well it is this bit here that is managing the default selection
Code:
if rs("DecisionMakerID") = nDecisionMaker then
  Response.Write(" selected")
end if
if you changed it to the code below then "Fee" would be selected (assuming Fee is a valid entry in the select box...
Code:
if rs("DecisionMakerID") = "Fee" then
  Response.Write(" selected")
end if
Reply With Quote
  #5 (permalink)  
Old 10-20-04, 00:06
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
That code is managing what has been selected and then if you go and edit it, it would have to be selected, but I want "Fee" to appear as a default options selected for example if you went to create a new record, so all the fields are empty because you are still to fill them out but that field because that is the default entry.

I think those are two diferrent things.
Reply With Quote
  #6 (permalink)  
Old 10-20-04, 00:11
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
so you mean something like....
Code:
if rs("DecisionMakerID") = nDecisionMaker then
  Response.Write(" selected")
elseif rs("DecisionMakerID") = "Fee" and (nDecisionMaker="") then
  Response.Write(" selected")
end if
this will make nDecisionMaker the selected value if it exists and if it does not it will select "Fee".

So in theory when the page first loads nDecisionMaker = "" because nothing has been selected so "Fee" will be selected. From that point on whatever was selected will be the default selection....

Oh have a misunderstood again?
Reply With Quote
  #7 (permalink)  
Old 10-20-04, 00:31
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
You have understood this time but it doesn't actually work, it saves fine,but it doesn't make "Fee" default value nor it recognizes what has been selected when you edit that selection.

Thanks for your help once, and once agin.
Reply With Quote
  #8 (permalink)  
Old 10-20-04, 00:34
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
might need to change it to this....
Code:
if rs("DecisionMakerID") = nDecisionMaker then
  Response.Write(" selected")
elseif rs("DecisionMakerID") = "Fee" and isNull(nDecisionMaker) then
  Response.Write(" selected")
end if
if that doesn't work then do some response.writes for your values to figure out why. the logic is sound enough assuming the rest of the code around it follows that standard accepted pattern of asp coding.
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