Jump to content

onchange to update a variable and pass it through to a query?


lelliott92

Recommended Posts

How can I make my on change in the form pass through the year thats been selected, then use that in the second query?

 

<select name="mySelect" onchange=""> 
	<?php $result= mysql_query('SELECT DISTINCT Year FROM MonthlySales'); ?> 
        <?php while($row= mysql_fetch_assoc($result)) { ?> 
            <option value="<?php echo htmlspecialchars($row['Year']);?>"> 
                <?php echo htmlspecialchars($row['Year']); ?> 
            </option> 
        <?php } ?> 
  </select> 
	     
    <?php

$query="SELECT * FROM MonthlySales WHERE Year = PASS YEAR SELECTED VARIABLE TO THIS BIT HERE";
		$results = mysql_query ( $query, $conn);

Link to comment
Share on other sites

the query is PHP (server side code ran when the page is loaded)

 

onchange triggers javascript (client side code, ran when the menu changes.. well after the page is loaded)

 

---

 

you cannot make the client side code do something on the server side without loading... but you can use ajax to load data sort of "behind the scenes" and make changes from that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.