?
Solved

I'm Trying to get the value of the HTML Select

Posted on 2015-01-25
2
Medium Priority
?
234 Views
Last Modified: 2015-01-26
I have 2 select drop down windows … populated with our database id and name … you select the first golf club brand from the list and I need to capture that value and pass it to the next </select> and database query

please see my code below
                       
<script>
                        $( ".target" ).change(function() {
			var raq_id = $(this).val();
			 alert (raq_id);
			});
			</script>
                        $sql3 = 'SELECT * FROM racquets WHERE branch = rac_id';

Open in new window

<?php
							$conn = new mysqli($servername, $username, $password, $dbname) or die("Connection Failed");
							//$dbname = ("mydev")or die("Connection Failed");
							$sql = "SELECT * FROM racquet_branch";
							$result = $conn->query($sql);
							?>
							<select name="Select_Brand" class="target" id = "raq_brand" name="racquet_brand" style="align-left:250%; width:100%;border:1px solid #CDCDCD;width:302px !important;">
							<?php
							while($row = $result->fetch_assoc()) {
							?>
							<option value="<?php echo $row["id"];?>"> <?php echo $row["name"];?> </option>
							 
							<?php
							}
							?>
							<script>
                           $( ".target" ).change(function() {
								var raq_id = $(this).val();
							  alert (raq_id);
							});
							</script>
							<?php							
							$conn2 = new mysqli($servername, $username, $password, $dbname) or die("Connection Failed");
							//$dbname = ("mydev")or die("Connection Failed");
							$sql3 = 'SELECT * FROM racquets WHERE branch = rac_id';
							$result3 = $conn2->query($sql3);
							?>
							<select name="Select_Model" class="target" id = "raq_brand" name="racquet_brand" style="align-left:250%; width:100%; border:1px solid #CDCDCD;width:302px !important;">
							<?php
							while($row2 = $result3->fetch_assoc()) {
							
							?>
							<option value="<?php echo $row2["name"];?>"> <?php echo $row2["name"];?> </option>
							 
							<?php
							}
							?>
							</select>

Open in new window

0
Comment
Question by:dolamitejenkins
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 40569614
The better way woulb usingAjax to call the php script which executes the query and return the reult to hte javascript to display data.
Bua the simplest way is this:

<script>
                        $( ".target" ).change(function() {
			var raq_id = $(this).val();
			 alert (raq_id);
                         window.location.href = 'php_script.php?raq_id=' + raq_id;
			});
			</script>

Open in new window

I didn't test it, but it should be possible redirect to the same page, checking $_GET array as usual.
0
 

Author Closing Comment

by:dolamitejenkins
ID: 40571003
Thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question