Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183

    Question Unanswered: 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

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    This looks good to me.... assuming you are looping inside a select box....

    What is actually happening when you use this code??

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

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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

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

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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?

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

  8. #8
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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.

Posting Permissions

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