Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox OnChange Event

Status
Not open for further replies.

DaveyCrockett

Programmer
Jul 15, 2003
36
US
Hello Everyone!

This is an extremely tough one, that I have been researching. I a combo box that is populated based on a field in a database. I want to be able to select that item in the combo box and the values corresponding to that Record should be retrieved. Is this possible without submitting the page? If so, how? without using Javascript. Can .NET do it?

Thanks
 
I do this a litle differntly, I use the on thchage to parse the select firld value wherne I have put the rest of htre values from thayt line in the DB

I.E

DAS~IT~495 in the value for a select item

in the select tag I have onchange="updateInfo()"

the update info parses the value DAS~IT~495, splits it into an array and then uses innerHTML to display those items to the user. Let me know if that helps or you need more help.
 
Hey Spazman,

Thanks for the effort, but I just do not understand your reply. Maybe I wasn't too clear of what I wanted to do with the values...

I have 4 combo boxes with the Name of the item in the DB. When the onchange event is triggered for each combo box, I want 4 values populated into a table next to the combo box with data from the DB for the selected item in the combo.

ie.. Let's say that Chicken was selected in the combo box. I want to retrieve from the DB the Calories,Proteins,Carbs and fats. For each of these I want them placed into the <td> column of the table.


<Script Language=&quot;Javascript&quot;>
function HandleChange() {
parent.frmMealPlanner.document.location.href=&quot;combobox3.asp?cbo=&quot; + document.forms[0].cbo11.value;
}
</script>

Meal 1<br>
<table border=&quot;1&quot; >
<tr>
<td>
<Select Name=&quot;cbo11&quot; size=&quot;1&quot; ONCHANGE=&quot;HandleChange();&quot;>
<option value=&quot;1&quot;>Chicken</option>
<option value=&quot;2&quot;>Salmon</option>
</Select>
<td>

Right now, the page will come back with a querystring of ?cbo=35.

Is there a way without preloading all of the values from the DB into DIV tags and having this done on client side. I would like the processing to be done on the serverside to decrease the time it takes to perform this selection process. Any further information or ideas would be appreciated.

PS. my javascript experience is next to NIL. I am used to retrieving the records using ADO in asp or VB. THanks for your help.
 
I think what you need to do is get all the info from the DB for those fields in your select box and Response.Write them into a JavaScript array. Then the HandleChange() function can just get the info right out of this array and stick it somewhere on the page.

The processing time will be next to nothing. To be clear, you will get the info from your DB on the server side using ASP/VBscript or whatever, then you will write it into the page. Then when the client receives the page they will have a client-side array with all the details. This will be accessed & displayed when the select box is changed.

Hope that helps.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Sorry I was not specific enough. What I do is I query my db, and get back a record(s)

AAA | 495 | IT
CCC | 495 | IT
BBB | 555 | IT

Then when I create the drop doen list in ASP, in select box I put all these values seperated by a ~
<option value=&quot;AAA~495~IT&quot;>AA</option>

Then when the user selects AAA, I split the value AAA | 495 | IT and put each value into a field value
Then your page does not need to go back to the DB, since the page already contains the rest of the values form the DB, 495 | IT. I hope that clrifies it for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top