onchange reload page with value of select

44,699

Solution 1

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;
};

Solution 2

window.addEventListener('load', function(){
    var select = document.getElementById('tv_taken');

    select.addEventListener('change', function(){
        window.location = 'pagename.php?tv_id=' + this.value;
    }, false);
}, false);
Share:
44,699
user1547410
Author by

user1547410

Updated on December 28, 2020

Comments

  • user1547410
    user1547410 over 3 years

    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.