Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

919 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

14 Experts available now in Live!

Get 1:1 Help Now