Riad Ahmed
Riad Ahmed

Reputation: 1

Automatically select drop-down after visiting on specific page

I have drop-down list, where user can select any options when they register on my site. I like to make it more easier for example if user vist specific url. They will automatically selected on Publishers opinion when they visit on domain.com/register#publishers

here is my code:

<div class="select_box">
 <select name="registared_as" id="registared_as">
 <option value="0">Students / Experts</option>
 <option value="1">University Academics</option>
 <option value="2">Publishers</option>
 </select>
 </div>

Upvotes: 0

Views: 34

Answers (1)

Mihai Lupu
Mihai Lupu

Reputation: 67

If the trigger is an url anchor, like your example with domain.com/register#publishers you can get the url anchor using javascript vanilla like this:

var anchor = window.location.hash.substr(1);

Then, you must select the option, also with javascript:

if (anchor == "publishers") {
     document.getElementById("registared_as").selectedIndex = 2;
}

And so on for each option..

Upvotes: 1

Related Questions