Click to See Complete Forum and Search --> : Return multiple name/value pairs with SELECT
jackson
01-10-2003, 06:12 AM
I need for a select statement to return not one but two name/value pairs for each option and am wondering if this can be done with javascript.
In psuedocode, I am looking for something like this:
<select size="1" name_1="layout" name_2="orderby" >
<option value_1="orders" value_2="open_orders.Customer_PO_No">Open Orders By PO</option>
<option value_1="orders" value_2="open_orders.Customer_Part_No">Open Orders By Part Number</option>
<option value_1="orders" value_2="open_orders.Request_Date">Open Orders By Request Date</option>
<option value_1="shipments" value_2="recent_shipments.Customer_PO_No">Shipments By PO</option>
<option value_1="shipments"value_2="recent_shipments.Customer_Part_No">Shipments By Part Number</option>
<option value_1="shipments" value_2="recent_shipments.Shipped_Date">Shipments By Date Shipped</option>
</select>
Webskater
01-10-2003, 07:08 AM
The code you have posted will work as it is. In a select box that displays a list of names I usually include in each option tag the phone, fax and email details of the contact. When a name is selected other fields are then automatically populated with the phone, fax and email. As many name/value pairs as you like can be accessed.
jackson
01-10-2003, 08:05 AM
Hmm.. Could you elaborate or point me to an example site?
I've tried it exactly as posted (name_1= name_2= ... value_1= value_2=...) and also without the subscripts (name= name=, value= value=) and I don't seem to be passing the second name/value pair.
Webskater
01-11-2003, 01:20 PM
Sorry for the delay. Here's an example.
First the select box with multiple name/value pairs. The code here may look a bit odd as the select bit was html and the option tag is written in vbscript. (So the variables are coming from a recordset and there might be the wrong number of inverted commas - but the principle should be clear.)
<select name=suppcontact onchange="getdetails()">
<option value=" & SupRS("SuppContactID") & " CPhone='" & SupRS("Direct") & "' CFax='" & SupRS("WorkFax") & "' CEmail='" & SupRS("Email") & "'>" & SupRS("Contact") & "</option>"
</select>
The function below retrieves the values from the option tags and populates three text boxes on the page that are called ContactPhone, ContactFax and ContactEmail.
function getdetails()
{
ContactPhone.value = suppcontact.options[suppcontact.selectedIndex].CPhone;
ContactFax.value = suppcontact.options[suppcontact.selectedIndex].CFax;
ContactEmail.value = suppcontact.options[suppcontact.selectedIndex].CEmail;
}
The above code writes a contact's phone, fax and email numbers within an option tag and, when the contact is selected in the select box the getdetails() function extracts the values and populates the page with them. I think this is what you are trying to do.
jackson
01-11-2003, 03:24 PM
Thanks for the help folks.
I went with a modified version of Dave's "Another method..." and it does exactly what I needed.
Thanks again.
Webskater
01-13-2003, 03:26 AM
a·pos·tro·phe1 ( P ) Pronunciation Key (-pstr-f)
n.
The superscript sign ( ' ) used to indicate the omission of a letter or letters from a word, the possessive case, or the plurals of numbers, letters, and abbreviations
inverted comma
n : a punctuation mark used to attribute the enclosed text to someone else
I always enclose values in a string with either single or double inverted commas - as appropriate. I never use apostrophes.