http://www.davesite.com/webstation/js/theory1jump.shtml
Drop Down List URL Jump Box
Scenario: I have three web sites I want to link to. I also don't want to bore my friends by having them all lined up in a row, or in a long unordered list. I want them to click a little drop down box, and have that site automatically load.
To accomplish this, I need to use a blank form, and I need to place a selection list on it. I need to add options for each of the three sites, and then I need to do a little JavaScript magic.
Caution: Why do I need a form? Compatibility. Without the form surrounding the drop down list, some browsers will refuse to allow the JavaScript to work properly.
Form and List without JavaScript
<form name="jump1">
<select name="myjumpbox">
<option selected>Please Select...
<option value="http://www.davesite.com/">davesite.com
<option value="http://www.neonlollipops.com/">neonlollipops.com
<option value="http://www.about.com/">about.com
</select>
</form>
Okay, well, now all we need to do is politely ask the web browser software change the current page location (address) to the one selected when someone chooses something from the drop down box. We'll use the event OnChange.
<form name="jump1">
<select name="myjumpbox"
OnChange="location.href=jump1.myjumpbox.options[selectedIndex].value">
<option selected>Please Select...
<option value="http://www.davesite.com/">davesite.com
<option value="http://www.neonlollipops.com/">neonlollipops.com
<option value="http://www.about.com/">about.com
</select>
</form>
Feel free to try the jump box, and hit the back button to return to this page.
You are probably feeling a little like I did the first time I used this code. What does all of that line of gibberish mean?
OnChange="location.href=jump1.myjumpbox.options[selectedIndex].value"
Here's the simple explanation. OnChange is the event. location.href is the browser's current location. We are telling the browser to look at jump1 (our form), then look at myjumpbox on jump1 (our listbox), then figure out which of our options is selected, and then copy whatever value that option has into the browser's current location.
So if we choose davesite.com, the browser gets this:
location.href=http://www.davesite.com/
Cha-Ching. We're at davesite.com.
Note: If you're using frames, and you want the link selected to load in the entire window and not just inside the current frame, change location.href to top.location.href.
If we want to be slick, we can tell the browser to open the page into a new browser window.
<form name="jump2">
<select name="myjumpbox"
OnChange="window.open(jump2.myjumpbox.options[selectedIndex].value)">
<option selected>Please Select...
<option value="http://www.davesite.com/">davesite.com
<option value="http://www.neonlollipops.com/">neonlollipops.com
<option value="http://www.about.com/">about.com
</select>
</form>
It sure looks silly, but all jump2.myjumpbox.options[selectedIndex].value holds is the value of the currently selected drop down list item.
分享到:
相关推荐
Probability: Theory and Examples,by Durrent,概率论专业经典教材。答案很少见,特意贡献~~~ 教材电子版已更新至第四版,可以在Durrent‘s homepage下载~!
Information theory and statistics.part1.rar
《Antenna Theory and Design》第三版由Warren L. Stutzman与Gary A. Thiele两位教授共同编写,他们是该领域的权威专家。本书深入探讨了天线技术的基本原理及其在现代通信系统中的应用。 ### 关键知识点概述 #### ...
这本书《Probability: Theory and Examples》是由Rick Durrett所著的概率论领域的重要学术作品。在本书中,作者深入探讨了概率论的基本理论及其应用实例,涵盖了概率空间、分布、随机变量、积分理论、期望值计算、...
《Vehicle Dynamics: Theory and Application》这本书正是为工程学学生提供了一个系统学习这一领域的平台。书中首先介绍了汽车动力学的基础知识,这些知识对于开发分析汽车行驶性能(如乘坐舒适性、操控性和优化)的...
Chapter 2 covers the main elements of Shannon’s approach to cryptography, including the concept of perfect secrecy and the use of information theory in cryptography. Chapter 3 is a lengthy ...
The definitive textbook and professional reference on Kalman Filtering - fully updated, revised, and expanded This book contains the latest developments in the implementation and application of ...
《Model Predictive Control: Theory and Design》是一本深入探讨模型预测控制(MPC)理论与设计的专业教材,广泛应用于国内外高等教育领域。MPC作为一种先进的控制策略,近年来在自动化、过程控制以及众多工程领域...
Theory and Applications of Image Registration By 作者: Arthur Ardeshir Goshtasby ISBN-10 书号: 1119171717 ISBN-13 书号: 9781119171713 Edition 版本: 1 出版日期: 2017-08-21 pages 页数: 499 A hands-...
The Applied and Numerical Harmonic Analysis (ANHA) book series aims to provide the engineering, ...the interleaving of theory and applications and their creative symbiotic evolution is axiomatic.
Organized for use as a text for an introductory course in stochastic processes at the senior level and as a first-year, graduate-level course in Kalman filtering theory and applications, this book ...
This book constitutes the refereed proceedings of the Second International Conference on Language and Automata Theory and Applications, LATA 2008, held in Tarragona, Spain, in March 2008. The 40 ...
《Theory and Design of CNC Systems》是一本探讨计算机数控(CNC)系统理论与设计的书籍,由韩国作者撰写。尽管该书可能在严谨性上不如美国或日本同类作品,但相较于国内如《数控技术》(王永章)或《新编机床数控...
线性系统设计涉及选择适当的系统参数以满足特定性能指标,如带宽、增益、相位响应等。这通常需要优化技术,例如根轨迹法、频率响应法或者状态空间设计方法。陈启宗的解决方案可能提供了这些设计方法的具体应用实例。...
《Graph Theory and Applications》是一本非常全面且实用的图论教材,不仅涵盖了图论的基础理论,还深入探讨了其在实际问题中的应用。通过大量的习题和问题,本书能够有效地帮助学习者掌握图论的核心概念和技术,...
Electromagnetic Theory and Plasmonics for Engineers Electromagnetic Theory and Plasmonics for Engineers.part1.rar (15 MB, 下载次数: 129 ) Electromagnetic Theory and Plasmonics for Engineers.part...
书中可能还会讨论到板壳结构设计中的一些实际问题和挑战,比如局部屈曲、稳定性分析、疲劳分析等。这些问题的解决对于确保结构的安全性和可靠性至关重要。例如,板壳结构中的局部屈曲问题,就需要通过理论计算和实验...