Solved

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

Posted on 2015-01-25
2
190 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 30

Accepted Solution

by:
Marco Gasi earned 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to dynamically set the form action using jQuery.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now