By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,945 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,945 IT Pros & Developers. It's quick & easy.

How can I put htm pages to link it with this JavaScript?

P: 1
I just want to do (drop down list) , I get script code but how can I insert page to link it with this code

for example if I have (3 page) to go to them by this code:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function gotoUrl(url) {
  3. if (url == "")
  4. return;
  5. location.href = url;
  6. }
  7. function newWin(url) {
  8. // url of this function should have the format: "target,URL".
  9. if (url == "")
  10. return;
  11. window.open(url.substring(url.indexOf(",") + 1, url.length),
  12. url.substring(0, url.indexOf(",")));
  13. }
  14. function fnOnChange(){
  15. gotoUrl(selector.options[selector.selectedIndex].value);
  16. return true;
  17. }
  18. var selector = (document.getElementById)? document.getElementsByName("formselect1")[0] : document.all.formselect1;
  19. selector.onchange=fnOnChange;
  20. </script>
Feb 12 '12 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Create a select element with name "formselect1" (though I'd change the JavaScript code to get the element by its ID).

Then add options with the values set to the URLs, e.g.
Expand|Select|Wrap|Line Numbers
  1. <select ...>
  2. <option value="http://somesite.com/">Some Site</option>
  3. ...
  4. </select>
Feb 27 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.