1

lets say i have got two html pages which both contain the same select box:

<select onchange="this.options[this.selectedIndex].value && (window.location =    this.options[this.selectedIndex].value);">
<option value="/site1.php">Site1</option>
<option value="/site2.php">Site2</option>
</select>

I am looking for a way to pass the value of selectedIndex to the next page, so I can use it at the second page select box too. Any suggestions?

Thanks in advance

Dede1989
  • 53
  • 1
  • 8

2 Answers2

1

localStorage

Store:

localStorage.userEdits=this.options[this.selectedIndex].value;

Get, on the other page :

var yourIndex = localStorage.userEdits;

hash

Set:

window.location.href="yourURL#index="+this.options[this.selectedIndex].value;

Get:

var yourIndex=window.location.hash.replace("index=","").parseInt();
nicael
  • 18,550
  • 13
  • 57
  • 90
0

You can use query parameters:

window.location = 'YOUR_URL?selectedIndex=' + this.options[this.selectedIndex].value

Using query params forces you to parse them. This is explained here (you can do just fine with pure JS).

Community
  • 1
  • 1
Jenian
  • 552
  • 1
  • 5
  • 18