user2397282
user2397282

Reputation: 3818

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?

Upvotes: 2

Views: 64527

Answers (2)

Mehran Hatami
Mehran Hatami

Reputation: 12961

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

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

Upvotes: 1

Goran.it
Goran.it

Reputation: 6299

Try this:

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

Upvotes: 5

Related Questions