zeidhaddadin Posted December 17, 2006 Share Posted December 17, 2006 Hi all, I have the following page that have a function to show a value ..... I'm trying to get it to work but it doesn't work.. it just refresh the page when I click on the button. <html><head><title>Distances</title><link type="text/css" rel="stylesheet" href="CSS.css" /><script type="text/javascript"><!--function distance(){var city = F1.T1.value;var value;switch (city){case "aqaba" :value = "Distance between Amman and Aqaba is: 280km";break;case "madaba" :value = "Distance between Amman and Madaba is: 27km";break;case "deadsea" :value = "Distance between Amman and Deadsea is: 37km";break;case "kerak" :value = "Distance between Amman and Kerak is: 88km";break;default :value = "Please choose one from these cities: aqaba,madaba,deadsea,kerak";break;}F1.T2.value = value;}--></script></head><body><p>Here on this page you can find the real distance between any city (Cities in this website) in Jordan and the capital of Jordan "Amman", You just have to enter the name of the city and then click on the button "Find distance" to print the distance from that city to Amman in kilometers, (These distances are taken from Google earth).</p><form name="F1"><p><b>Enter name:</b> <input type="text" name="T1" size="30" /> <input type="submit" name="S1" value="Find distance" onclick="distance()" /></p><br /><p><b>Distance is:</b> <input type="text" name="T2" size="30" /></p></form><p><br />To go back to the main page, Click <a href="Main.html">Here</a>.</p></body></html> Link to comment Share on other sites More sharing options...
MrAdam Posted December 17, 2006 Share Posted December 17, 2006 try using: ;<input type="button" name="S1" value="Find distance" onclick="distance()" /> Link to comment Share on other sites More sharing options...
jesh Posted December 18, 2006 Share Posted December 18, 2006 try using:;<input type="button" name="S1" value="Find distance" onclick="distance()" /> Or, if you don't want to use type="button", you'll have to return false on the onsubmit event so that the form doesn't submit:<input type="submit" name="S1" value="Find distance" onclick="distance(); return false;" /> But I like MrAdam's solution better. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now