Hi All,

I'm trying to read/pass a value from a dropdownlist on a ASP.NET page to a PHP page so I can excute the required SQL command in the background. Can anyone assist with this?

Background:

  • jQuery autocomplete search box getting results from PHP page that connects to a SQL database (working fine)
  • Wanting to now have a drop downlist next to the search box that PHP reads in order to know what query to run, e.g. search by first name, or from the dropdown list search by address etc.

Thanks

Recommended Answers

All 6 Replies

Member Avatar for diafol

I'm assuming that this is doable - never tried it.
Show your code.

Default.php

<asp:Panel id="Search" runat="server" HorizontalAlign="Right">
    <asp:DropDownList id="SearchList" runat="server" Width="100">
    <asp:ListItem>Name</asp:ListItem>
    <asp:ListItem>City</asp:ListItem>
    <asp:ListItem>Suburb</asp:ListItem>
    <asp:ListItem>Country</asp:ListItem>
    <asp:ListItem>Company</asp:ListItem>
    </asp:DropDownList>
    <asp:TextBox id="queryString" runat="server" AutoComplete="Off" OnClick="this.value=''" Width="200"/>
    <asp:Button id="btnSearch"  Text="Search" runat="server" OnClick="btnSearch_Click"/>
</asp:Panel> 

Search.php

Need to read 'SearchList' value when the 'Search' button is clicked and based on the value I'll run different SQL select statements. I'm fine with the rest of the coding just need to know how I can read the value, I assume GET or POST.

Any help would be appreciated

Thanks

have you tried response.redirect ?

I haven't coded in C# and VB for a while, but I think that might work for you. I don't remember the proper syntax, but I would guess it could be something like this.

response.redirect('yourpage.php?value=SomeValue');

Another thing is the ListItem control though? Is your application able to use the html form..?

Hi,

Sorry I think I might be leading you down the wrong path here, it needs work without clicking the search button my mistake.

So what I need, is if I selected 'Company' from the dropdown list I could start typing in the autocomplete text field and it will start returning values based on an PHP 'If' statement that looks at the 'Company' row of my SQL database. If I select 'Name' I could start typing the persons name and the 'If' statement would run that SQL query which looks at the 'Name' row. I have the search working by looking directly at the 'Name' row but now I want to add the dropdown list into the equation so people can search based on criteria.

Thanks

Member Avatar for diafol

As long as you pass valid post/get vars to PHP, I don't think it cares where it comes from. It'll 'echo' a response that your ajax script should be able to pick up.

So you have an ASP.NET page that you are accessing to select an item from the dropdown, and you want to use that selection to be sent to a PHP page for processing, correct?

Well..first, you will need to prevent the behavior of the postback in your asp.net page because once you click on an input element or if your drop down list is configured to autopost back, its just going to reload the page.

As diafol metions in the previous post, using Ajax would be an option. I think it would be the best option here.

On your <asp:DropDownList /> control, it will render as a <select /> element. So you execute a javascript function to run based on the onchange event.

Also, we can add the attribute ClientIDMode="Static" to easily work with the ID of the element since asp.net will render a different client ID for the HTML element.

So your drowndown control would look like this...

<asp:DropDownList id="SearchList" runat="server" ClientIDMode="Static" onchange="ajaxFunction(this.value)">
  <asp:ListItem>Name</asp:ListItem>
  <asp:ListItem>City</asp:ListItem>
  <asp:ListItem>Suburb</asp:ListItem>
  <asp:ListItem>Country</asp:ListItem>
  <asp:ListItem>Company</asp:ListItem>
</asp:DropDownList>

Then, somewhere on your page, add a javascript block, and a function called ajaxFunction(val) { .. }. In that function, you setup your ajax code to send/receive data from your PHP page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.