I have a table displaying results, I want to give people the ability to update the results of a cell/field individually without needing a whole 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 tell its a select box with a list of users. Now the only problem is i need to pass the new selected value in the url string, so i want the new value of the select.
So lets say it was mary and someone chooses 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 on is there a way to pass the changed value via php or will I need a javascript solution?
Ill then use an
IF if(isset($_GET['tv_id']))
{
Do the update
}
This is not a public site so I'm guessing there is a more secure way to do this but this should probably suffice since it will only be team members using it who would be required to login before they can see this page.
You'll want to use JavaScript to achieve this.
Here's a jQuery solution:
$('#tv_taken').change(function() {
window.location = "samepage.php?update=tv_taken&update_id=" + $(this).val();
});
And here's a vanilla JavaScript solution:
document.getElementById('tv_taken').onchange = function() {
window.location = "samepage.php?update=tv_taken&update_id=" + this.value;
};
window.addEventListener('load', function(){
var select = document.getElementById('tv_taken');
select.addEventListener('change', function(){
window.location = 'pagename.php?tv_id=' + this.value;
}, false);
}, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With