1 Replies - 1262 Views - Last Post: 24 June 2013 - 10:53 AM

#1 Static Hazard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-November 09

Passing selected Combobox value into a sql query

Posted 24 June 2013 - 08:59 AM

Let me preface this by saying that I have no idea what I'm doing. I was asked to work on a website while my boss is on vacation, and I don't have too much experience with this.

On my website I have two comboboxes. The data of the second dropdown is dependent on the selection of the first, so once the user selects a value in the first dropdown, I'd like to take that value, pass it to a Javascript function, query the database with the selected value as a parameter, and then populate the second dropdown with the data yielded from the query. It sounds simple, but I've scoured the internet and still can't find what I'm looking for!

It's important to know that the dropdowns are populated dynamically by tables that potentially have thousands of values, so the items are not hardcoded in. Also, this code is a little obfuscated to no private information from my company is revealed.

HTML:
<rad: RadComboBox ID="ctlFrom" runat="server" AutoPostBack="true" onchange="PopulateSecondDropdown()" AppendDataBoundItems="true" DataSourceID="odsRepsFrom" DataTextField="SALE_ID" DataValueField="SALE_ID"/>

<rad: RadComboBox ID="ctlTo" runat="server" AutoPostBack="true" AppendDataBoundItems="true" DataSourceID="odsRepsTo" DataTextField="SALE_ID" DataValueField="SALE_ID"/>



JS: this is never getting called. I need to add the functionality to call the SQL query to run again to repopulate the second dropdown here, but I don't know how.
function PopulateSecondDropdown(){
        var comboFromRepValue = document.getElementById("ctlFrom");
        window.alert(comboFromRepValue);
}



NOTE: The queries work fine. When I open the page the information is displayed correctly, but when the user changes to another selection in the first dropdown, I need to refresh the second one with the new information. I think the "onchange="refresh function" is the right way to go...either that or onclick, but I don't know if that works with Comboboxes.

This post has been edited by Static Hazard: 24 June 2013 - 09:01 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Passing selected Combobox value into a sql query

#2 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,866
  • Joined: 30-April 10

Re: Passing selected Combobox value into a sql query

Posted 24 June 2013 - 10:53 AM

function PopulateSecondDropdown(){
        var comboFromRepValue = document.getElementById("ctlFrom");
        window.alert(comboFromRepValue);
}



You are not getting the value of #ctlFrom, you are just selecting the element.

Try this:
function PopulateSecondDropdown(){
        var comboFromRepValue = document.getElementById("ctlFrom").value;
        window.alert(comboFromRepValue);
}



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1