1

I have created a website with javascript dropdown option menu.

This is my menu.php file

<select onchange="if (this.value) window.location.href=this.value">
<option value="/home.php">Home</option>
<option value="/aboutme.php">About Me</option>
<option value="/work.php">Work</option>
<option value="/contect.php">Contect Me</option>
</select>

I have included this file on every pages of website. It works fine.

Now what I want is : When I click on the aboutMe from dropdown menu in "home" It should redirect me to About Me page and dropdown menu in aboutme page should remain at about me. So far it is redirecting successfully, but dropdown menu always remains on "Home".

Is there a way to solve this ? or Should I create a saparate file for each pages?

I am confused. Please Help.

2
  • set selected property to option elements as per page. it will work fine. Commented Jul 17, 2015 at 9:37
  • 2
    You may need to pass the value via the querystring and use that on the target page to set the drop down accordingly. Commented Jul 17, 2015 at 9:37

1 Answer 1

3

Give your select an id:

<select id="page" onchange="if (this.value) window.location.href=this.value">

and use the script:

<script>
  window.onload = function(){
    document.getElementById('page').value =  window.location.href;
  }
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.