Setting the value of a <select>

Author Message
killieblues

  • Total Posts : 6
  • Scores: 0
  • Reward points : 0
  • Joined: 4/3/2008
  • Status: offline
Setting the value of a <select> Wednesday, April 23, 2008 11:08 PM (permalink)
0
Hi all,
 
I'm having trouble setting the value of a <select> in a form.
 
I am reading in information from a database (MSAccess) and then pre-populating the form with the data so that the user can amend the information if required.
 
The problem I am having is this...
 
I get the data for the Genre by the following code:
 
egenrex = rsRecordSet("Type")
 
...and on checking this using response.write it gives me the value of 2 (which is correct).
 
However, I can't find how to plug this into my form?
 
I've tried the following code with eventupdate being the name of the form, and egenre being the name of the <select>
 
eventupdate.egenre.value = egenrex
 
but I get the message;
 
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/promotions/eventform.asp, line 415
 
I can replace this code with response.write "<p>egenrex = " & egenrex & "</p>" and I get the correct value appearing on the screen.
 
Can anyone assist?
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: Setting the value of a &lt;select&gt; Thursday, April 24, 2008 1:52 AM (permalink)
    0
    Could you please show your code so we can understand how everything goes together?
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      killieblues

      • Total Posts : 6
      • Scores: 0
      • Reward points : 0
      • Joined: 4/3/2008
      • Status: offline
      RE: Setting the value of a &lt;select&gt; Thursday, April 24, 2008 2:11 AM (permalink)
      0
      Here's the relevant area of the asp file
       
          <!-- get the event information from the database if applicable -->
          <%
           eventID = request.form("eventid")
           
           dim egenrex, ename, eband, ename, eband, edate, etime, elocation, eprice, etickets, eimage, epromotion, ediscount
           
           egenrex = ""
           ename = ""
           eband = ""
           edate = ""
           etime = ""
           elocation = ""
           eprice = ""
           etickets = ""
           eimage = ""
           epromotion = ""
           ediscount = ""
           
           ' only query the database if not a new event being created
           
           if eventID <> "new" then
           
            'Create an ADO connection odject
            Set adoConnection = Server.CreateObject("ADODB.Connection")
            'Set an active connection to the Connection object using a DSN-less connection
            adoConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("NewDawn.mdb")
            'Create an ADO recordset object
            Set rsRecordSet = Server.CreateObject("ADODB.Recordset")
            'Initialise the strSQL variable with an SQL statement to query the database
            strSQL = "SELECT * FROM tblEvent WHERE EventID = " & eventID & ";"
            'Open the recordset with the SQL query
            rsRecordSet.Open strSQL, adoConnection
            'Loop through the recordset
            Do While not rsRecordSet.EOF
             
             egenrex = rsRecordSet("Type")
             ename = rsRecordSet("Name")
             eband = rsRecordSet("ArtistName")
             edate = rsRecordSet("Date")
             etime = rsRecordSet("StartTime")
             elocation = rsRecordSet("Venue")
             eprice = rsRecordSet("TicketPrice")
             etickets = rsRecordSet("maxTickets")
             eimage = rsRecordSet("ImagePath")
             epromotion = rsRecordSet("Promotion")
             ediscount = rsRecordSet("Discount")
             
             'Move to the next record in the recordset
             rsRecordSet.MoveNext
            Loop
            'Reset server objects
            rsRecordSet.Close
            adoConnection.Close
            Set rsRecordSet = Nothing
            Set adoConnection = Nothing
           end if
          %>
          
          <td bgcolor = "#ddddff" colspan = "6" valign = "top" width = "690">
           <div id = "content">
            <table>
             <form name = "eventupdate" method = "post" action = "updevent.asp">
              <!-- set the pageid value to eventupdate as that is where we want to redirect to -->
              <input type = "hidden" name = "pageid" value = "eventupdate.asp"/>
              <tr>
               <td>
                <p>Genre</p>
               </td>
               <td>
                <select name = "egenre">
                 <%
                  'Create an ADO connection odject
                  Set adoConnection = Server.CreateObject("ADODB.Connection")
                  'Set an active connection to the Connection object using a DSN-less connection
                  adoConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("NewDawn.mdb")
                  'Create an ADO recordset object
                  Set rsRecordSet = Server.CreateObject("ADODB.Recordset")
                  'Initialise the strSQL variable with an SQL statement to query the database
                  strSQL = "SELECT * FROM tblGenre;"
                  'Open the recordset with the SQL query
                  rsRecordSet.Open strSQL, adoConnection
                  'Loop through the recordset
                  Do While not rsRecordSet.EOF
                   
                   'Write the HTML to display the current record in the recordset
                   response.write ("<option value = """ & rsRecordSet("GenreID") & """>" & rsRecordset("Description") & "</option>")
                   'Move to the next record in the recordset
                   rsRecordSet.MoveNext
                  Loop
                  
                  'Reset server objects
                  rsRecordSet.Close
                  Set rsRecordSet = Nothing
                  Set adoConnection = Nothing
                  
                 %>
                </select>
      <%
      eventupdate.egenre.value = egenrex
      %>
               </td>
              </tr>

       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        RE: Setting the value of a &lt;select&gt; Thursday, April 24, 2008 2:20 AM (permalink)
        0
        Ehh...too much ASP for me. You're going to need one of the web dev types (which I am not) to look at it. As a matter of fact I'm going to move this to the ASP forum.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          TNO

          • Total Posts : 2094
          • Scores: 36
          • Reward points : 0
          • Joined: 12/18/2004
          • Location: Earth
          • Status: offline
          RE: Setting the value of a &lt;select&gt; Thursday, April 24, 2008 6:48 AM (permalink)
          0
          The page loads and the <select> element has a list of data already prefilled when I go to the page correct?

          and you want to update this information? Does the user ask to update this? At what point does is this information supposed to change?
          To iterate is human, to recurse divine. -- L. Peter Deutsch
           
          #5
            killieblues

            • Total Posts : 6
            • Scores: 0
            • Reward points : 0
            • Joined: 4/3/2008
            • Status: offline
            RE: Setting the value of a &lt;select&gt; Sunday, April 27, 2008 12:36 AM (permalink)
            0
            The page loads with the dropdown list being pre-populated from a database.
             
            I then want the dropdown list to show the correct selected field.
             
            Example,
             
            Peter Kay, Comedy, Glasgow SECC
             
            I would want Comedy selected in the genre list (from Music,Comedy,Theatre,Sport) and Glasgow SECC selected in the location list (from Glasgow King Tut, Edinburgh Queens Hall etc.)
             
            I am basically looking for the opposite of SelectedIndex which gives you the position currently seleted. I want to somehow set this value to be 1 in the above scenario instead of it defaulting to 0.  A way round it I suppose would be to force the database value to be at the top of the list, but then that may lead to confusion among users with the dropdown list being presented in a different order than the usual one.
             
             
            #6
              TNO

              • Total Posts : 2094
              • Scores: 36
              • Reward points : 0
              • Joined: 12/18/2004
              • Location: Earth
              • Status: offline
              RE: Setting the value of a &lt;select&gt; Sunday, April 27, 2008 9:14 AM (permalink)
              0
              selectedIndex is a setter and a getter. you could do something like this:

              <body onload="document.getElementById('mySelect').selectedIndex = 2">
              To iterate is human, to recurse divine. -- L. Peter Deutsch
               
              #7
                killieblues

                • Total Posts : 6
                • Scores: 0
                • Reward points : 0
                • Joined: 4/3/2008
                • Status: offline
                RE: Setting the value of a &lt;select&gt; Tuesday, April 29, 2008 9:24 PM (permalink)
                0
                Hi,
                 
                I still couldn't get it to work in the suggested manner.
                 
                HOWEVER, I did manage to find the 'selected' attribute in <option> and I've used that instead which works a treat.
                 
                Thanks for the suggestions guys.
                 
                #8

                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • New Messages
                  • No New Messages
                  • Hot Topic w/ New Messages
                  • Hot Topic w/o New Messages
                  • Locked w/ New Messages
                  • Locked w/o New Messages
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2012 ASPPlayground.NET Forum Version 3.9