Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Setting the value of a <select>

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,59433
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Setting the value of a <select>
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Setting the value of a <select> - 4/23/2008 10:08:49 PM   
  killieblues

 

Posts: 5
Score: 0
Joined: 4/3/2008
Status: offline
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?
 
 
Post #: 1
 
 RE: Setting the value of a <select> - 4/24/2008 12:52:45 AM   
  ebgreen


Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
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

(in reply to killieblues)
 
 
Post #: 2
 
 RE: Setting the value of a <select> - 4/24/2008 1:11:52 AM   
  killieblues

 

Posts: 5
Score: 0
Joined: 4/3/2008
Status: offline
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>

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Setting the value of a <select> - 4/24/2008 1:20:11 AM   
  ebgreen


Posts: 4408
Score: 29
Joined: 7/12/2005
Status: offline
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

(in reply to killieblues)
 
 
Post #: 4
 
 RE: Setting the value of a <select> - 4/24/2008 5:48:20 AM   
  TNO


Posts: 974
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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?

_____________________________

Consolidated Script Component: Now in Testing stage!

A universe of complexity...

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Setting the value of a <select> - 4/26/2008 11:36:51 PM   
  killieblues

 

Posts: 5
Score: 0
Joined: 4/3/2008
Status: offline
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.

(in reply to TNO)
 
 
Post #: 6
 
 RE: Setting the value of a <select> - 4/27/2008 8:14:34 AM   
  TNO


Posts: 974
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
selectedIndex is a setter and a getter. you could do something like this:

<body onload="document.getElementById('mySelect').selectedIndex = 2">

_____________________________

Consolidated Script Component: Now in Testing stage!

A universe of complexity...

(in reply to killieblues)
 
 
Post #: 7
 
 RE: Setting the value of a <select> - 4/29/2008 8:24:18 PM   
  killieblues

 

Posts: 5
Score: 0
Joined: 4/3/2008
Status: offline
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.

(in reply to TNO)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Setting the value of a <select> Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts