简体   繁体   中英

onclick window.location.href with variable

I have a select with some options inside and I want the user to be sent to another page with a variable in the URI so that I can extract it.

This is how my select is set up:

<select name="period" onclick="window.location.href = 'test.php?Period=' + this.selectedIndex;">

I should then be able to use $_GET['Period'] to get the value.

However, the user is never sent to test.php.

Why is this?

尝试这个:

<select name="period" onchange="window.location.href = 'test.php?Period=' + this.options[this.selectedIndex].value;">

you can easily read the value when the select triggers the change event:

<select onchange="window.location.href = 'test.php?Period=' + this.value;">
</select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM