Onchange reload page with select value

I have a table showing the results, I want to give people the opportunity to update the results of a cell or field separately, without requiring a full update form

Here is what I have:

echo "<select name='tv_taken' id='tv_taken' onchange='window.location=\"samepage.php?update=tv_taken&update_id=$tv_id\" '>"; 

As you can probably specify its selection box with a list of users. Now the only problem is that I need to pass the new selected value to the url string, so I want a new select value.

So let's say that it was mary, and someone selects a new user, John, I want something like this

 echo "<select name='tv_taken' id='tv_taken' onchange='window.location=\"samepage.php?update=tv_taken&update_id=$tv_id&user_name=$find_username\" '>"; 

What I'm not sure is there a way to pass the changed value through php or do I need a javascript solution?

Then i use

 IF if(isset($_GET['tv_id'])) { Do the update } 

This is not a public site, so I assume that there is a safer way to do this, but it will probably be enough, since it will be only team members using it who need to be logged in before they can see this page .

+4
source share
2 answers

You will want to use JavaScript for this.

Here is the jQuery solution:

 $('#tv_taken').change(function() { window.location = "samepage.php?update=tv_taken&update_id=" + $(this).val(); }); 

And here is the vanilla JavaScript solution:

 document.getElementById('tv_taken').onchange = function() { window.location = "samepage.php?update=tv_taken&update_id=" + this.value; }; 
+8
source
 window.addEventListener('load', function(){ var select = document.getElementById('tv_taken'); select.addEventListener('change', function(){ window.location = 'pagename.php?tv_id=' + this.value; }, false); }, false); 
0
source

Source: https://habr.com/ru/post/1433134/


All Articles