JavaScript - Textbox Enter Key Issue
I have a textbox on my webpage where you can enter a title. I then have a button that goes to my javascript and starts a timer. Well if the user presses enter on the text box I want it to start the time. Well it goes to the code, but then like refreshes the website and starts from the start. How can I get around this? When I click the button there is no issues at all.
Textbox: <input type="text" id="titleMainT" value="N/A" size="27" onkeypress="startTimer();"/> Button: <input type="button" id="startbutton" value="Start Timer" onclick="startTimer();" /> Similar TutorialsI've got this form on my page that contains a search box and a select box full of employee names. When you type a few letters in the search box it scrolls through the listbox to the first match and then if you click on that name it executes a function. Today though one of my coworkers pointed out that some people would just hit enter inside the search box and he's right about that. So I looked around and found the solution for it, it's the onkeydown event I added to the search box. Weird thing is though when you type a name in the box and hit enter it executes properly and then the page immediately reloads Without the onkeybown event, hitting Enter still makes the page reload so it's gotta be something about the form. Can anyone pick out the bug? Thanks. <form name="people_form" style="margin: 0px"> <input type="text" id="peoplesearch" name="peoplesearch" onkeydown="if (event.keyCode == 13) search_onblur()" onblur="search_onblur()" onkeyup="suggestName();" onfocus="this.value=''" style="margin: 0px 0px 5px 0px; padding: 0px; width: 215px"></input> <select onchange="display.apply(this, this.value.split(','))" size="15" id="People" name="People" style="border-style: none; height:244px; width:220px; margin-bottom: 15px;"> <option>Loading</option> </select> </form> Looking for an example of how to take the value typed in one textbox to be calculated and update the value of a second texbox on the fly. The calculation is, (2.9% X first textbox value) + $0.30 = second textbox value My problem is the following. I have an editable <div>: <div class='edit' id='divContent' name='divContent' ContentEditable>some text</div> If I press 'enter' two lines are skipped. I know that if I press 'shift+enter' only one line will be skipped. If I check the unformatted code of the contenteditable div, 'enter' gives me <p> and 'shift+enter' gives me <br>, which makes sense because <p> is formatted differently than <br>. So I want to change 'enter' into 'shift+enter' I have already found something to capture and kill 'return' function killReturn() { key = event.keyCode; if (key == 13) return false; } But now for some means to replace the killed 'enter' with 'shift+enter'? Thanks a lot in advance for any advise! Good day! I have a question regarding textbox properties. In my textbox username I want to happen is when I input a letter for example is "l" all the letter started in "l" in my field username was appear, so that the user can choose what she want to type to lessen the time in typing like in the google search. Is it possible?How can I do that? Thank you in advance Hi.. I have form and i want to input data using barcode and it will display on textbox and after input on the first textbox the focus will go to next textbox untill it will go on the last textbox and on the last textbox it will automatically save the data's on the database. How is it possible? here is my sample code: Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <head> <script type="text/javascript"> function ini() { // Retrieve the code var code =document.getElementById ("code_read_box1").value; var code =document.getElementById ("code_read_box2").value; var code =document.getElementById ("code_read_box3").value; var code =document.getElementById ("code_read_box4").value; var code =document.getElementById ("code_read_box5").value; var code =document.getElementById ("code_read_box6").value; // Return false to prevent the form to submit return false; } </script> </head> <body onLoad="document.barcode.code_read_box1.focus()"> <form name=barcode onsubmit = "return ini()"> <input type="text" id="code_read_box1" value="" /><br/> <input type="text" id="code_read_box2" value="" /><br/> <input type="text" id="code_read_box3" value="" /><br/> <input type="text" id="code_read_box4" value="" /><br/> <input type="text" id="code_read_box5" value="" /><br/> <input type="text" id="code_read_box6" value="" /><br/> </form> </body> </html> Hello. I've been teaching myself HTML and CSS for a while, and now I've moved into the world of Javascript (but I'm still very much a beginner). For practice, I've been building a sample sign up form for a mock website, and I'm having problems with the birthdate section. The idea I had was to have MM, DD, and YYYY be the default values of my 3 textboxes (as an example for users), then set the value to nothing when the box gained focus. That all works fine, but I ran into problems when I tried to write an if statement to set the value back to MM, DD, or YYYY if the value was still nothing when the user clicked away. As it is now it just replaces the text inputted into the textbox (which of course is not good). Any ideas for what the problem might be? Code: <form name="signup" action="javascript:void(0);" method="post"> <table> <tr> <td>Date Of Birth:</td> <td> <input name="DOBmonth" type="text" value="MM" size="2" style="color: #555555;" onFocus="clearDOBmonth()" onBlur="restoreDOBmonth()" /> <input name="DOBday" type="text" value="DD" size="2" style="color: #555555;" onFocus="clearDOBday()" /> <input name="DOByear" type="text" value="YYYY" size="4" style="color: #555555;" onFocus="clearDOByear()" /></td> </tr> <tr> <td></td> <td><button name="Submit" type="submit" style="font-size: 1em;">Sign Up</button></td> </tr> </table> </form> <script type="text/javascript" language="javascript"> <!-- document.signup.DOBmonth.value="MM"; document.signup.DOBday.value="DD"; document.signup.DOByear.value="YYYY"; function clearDOBmonth() { document.signup.DOBmonth.value="";} function clearDOBday() { document.signup.DOBday.value="";} function clearDOByear() { document.signup.DOByear.value="";} function restoreDOBmonth() { if ('document.signup.DOBmonth.value = ""') { document.signup.DOBmonth.value = "MM"; // alert(document.signup.DOBmonth.value); } } //--> </script> Another side question, if I set a variable equal to the value of a textbox, then change the value of the variable, does that also change the value of the textbox? or is the variable no longer associated with the textbox. Example: Code: var a = document.form.textbox.value; a = blue; does document.form.textbox.value = blue? or is var a now completely independent of the textbox value? Thanks! Hi, Just wondering if you guys can help me to make the following script to work when the enter/return key is pressed, intead of having to click on the button? Code: <Script language=JavaScript> function read_model (form) { ModelVar =form.model_input.value; window.location= ("http://www.sony.co.uk/product/dsc-t-series/" + ModelVar + "/tab/technicalSpecs"); } </script> <form name=model_form action="" method=GET> Enter Sony Model Number (e.g. dsc-tx5): <input type=text name=model_input value="" size=9> <input type=button name=model_button value=Click onClick="read_model(this.form)"> </form> <script language=JavaScript> document.model_form.model_input.focus(); </script> I've searched the net for ways of achieving this, but for some reason none of the code i've tried works..! Also, if this make a difference, the page will mainly be used in Firefox. I'd be really greatfull if someone can help me with this, Thanks! I have this which runs on keyup in a textbox but i dont want it to run if the pressed key is enter, how would i go about that? Code: function getList() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { showDiv('#', 'result'); document.getElementById("result").innerHTML=xmlhttp.responseText; } } var user = document.getElementById('friendsSearch').value; xmlhttp.open("GET","../friendSearch.php?username="+user,true); xmlhttp.send(); } Good day! I created a login page and I have the username which is a textbox type, department and i use option and a submit button.. I want that when i open my webpage automaticallt the cursor was on the textbox and when i am done in typing my username and i press the enter key the focus would be on the option which where i can choose my department and when i am done choosing my department and i press the enter key i automatic login and go to the department page. Here is the code: PHP Code: <?php session_start(); //require_once 'conn.php'; $db_name="dspi"; mysql_connect("localhost", "root", "") or die("Cannot connect to server"); mysql_select_db("$db_name")or die("Cannot select DB"); $department = mysql_real_escape_string($_POST['department']); $username = mysql_real_escape_string($_POST['username']); $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); $ct = mysql_num_rows($sql); if($ct == 1) { $row = mysql_fetch_assoc($sql); if($row['Department']=='Accounting') { header('location: Company.php'); } elseif($row['Department']=='Engineering') { header('location: Company.php'); } elseif($row['Department']=='Finishing_Goods') { header('location: Company.php'); } elseif($row['Department']=='HRAD') { header('location: Company.php'); } elseif($row['Department']=='MIS') { header('location:Company.php'); } elseif($row['Department']=='Packaging_and_Design') { header('location:Company.php'); } elseif($row['Department']=='Production') { header('location:Company.php'); } elseif($row['Department']=='Purchasing_Logistic') { header('location:Company.php'); } elseif($row['Department']=='QA_and_Technical') { header('location:Company.php'); } elseif($row['Department']=='Supply_Chain') { header('location:Company.php'); } else { header('location:dspi_login.php'); echo"Incorrect Username or Department"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login</title> <script> function searchKeyPress(e) { // look for window.event in case event isn't passed in if (window.event) { e = window.event; } if (e.keyCode == 13) { document.getElementById('submit').focus(); } } </script> <style type="text/css"> <!-- BODY { background-image: url(layout_image/bgroundv09.png); background-attachment: fixed; } #Dept_Frame { position:absolute; width:229px; height:49px; z-index:1; left: 441px; top: 262px; } #Department_Option { position:absolute; width:186px; height:32px; z-index:2; left: 455px; top: 275px; } #Submit_Frame { position:absolute; width:82px; height:35px; z-index:3; left: 516px; top: 320px; } #Submit_Button { position:absolute; width:60px; height:29px; z-index:4; left: 525px; top: 328px; } #Username_ImageText { position:absolute; width:130px; height:55px; z-index:5; left: 319px; top: 208px; } #User_Frame { position:absolute; width:230px; height:46px; z-index:6; left: 441px; top: 216px; } #Username_Textbox { position:absolute; width:182px; height:23px; z-index:7; left: 457px; top: 228px; } --> </style> </head> <body> <form id="form1" name="form1" method="post" action=""> <div id="Department_Option"> <select name="department" onkeypress="searchKeyPress(event);"> <option>Choose your Department. . . . . . </option> <option value="Accounting" <?php if($_POST['department'] == 'Accounting') echo "selected='selected'"; ?>>Accounting</option> <option value="Engineering" <?php if($_POST['department'] == 'Engineering') echo "selected='selected'"; ?>>Engineering</option> <option value="Finishing_Goods" <?php if($_POST['department'] == 'Finishing_Goods') echo "selected='selected'"; ?>>Finishing Goods</option> <option value="HRAD" <?php if($_POST['department'] == 'HRAD') echo "selected='selected'"; ?>>HRAD</option> <option value="MIS" <?php if($_POST['department'] == 'MIS') echo "selected='selected'"; ?>>MIS</option> <option value="Packaging_and_Design" <?php if($_POST['department'] == 'Packaging_and_Design') echo "selected='selected'"; ?>>Packaging and Design</option> <option value="Production" <?php if($_POST['department'] == 'Production') echo "selected='selected'"; ?>>Production</option> <option value="Purchasing_Logistic" <?php if($_POST['department'] == 'Purchasing_Logistic') echo "selected='selected'"; ?>>Purchasing and Logistics</option> <option value="QA_and_Technical" <?php if($_POST['department'] == 'QA_and_Technical') echo "selected='selected'"; ?>>QA and Technical</option> <option value="Supply_Chain" <?php if($_POST['department'] == 'Supply_Chain') echo "selected='selected'"; ?>>Supply Chain</option> </select> </div> <div id="Submit_Button"> <input type="Submit" name="submit" value="Submit" id="submit" onclick="doSomething();"/> </div> <div id="Dept_Frame"><img src="layout_image/subframev02.png" width="229" height="50" /></div> <div id="Submit_Frame"><img src="layout_image/subframev02.png" width="80" height="46" /></div> <div id="Username_ImageText"><img src="layout_image/userv01.png" width="131" height="62" /></div> <div id="User_Frame"><img src="layout_image/subframev02.png" width="229" height="50" /></div> <div id="Username_Textbox"> <input name="username" type="text" size="30" /> </div> </form> </body> </html> I hope that somebody help me to solve my problem Hello everyone, I got this cool javascript for an all-in-one search engine at javascriptkit.com: http://www.javascriptkit.com/script/cut130.shtml I can already execute the script by clicking on the submit button, but I also want to execute the script by pressing the enter key within the text area. Can anyone please guide me through accomplishing this goal? Thanks, RK2 ============================== The code is as follows: Code: <script language="JavaScript"> <!-- // // Script by Jari Aarniala [www.mbnet.fi/~foo -- foo@mbnet.fi] // // This script makes it easy to choose with which search engine // you`d like to search the net. You may use this if you keep this // text here... // function startSearch(){ searchString = document.searchForm.searchText.value; if(searchString != ""){ searchEngine = document.searchForm.whichEngine.selectedIndex + 1; finalSearchString = ""; if(searchEngine == 1){ finalSearchString = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=" + searchString; } if(searchEngine == 2){ finalSearchString = "http://av.yahoo.com/bin/query?p=" + searchString + "&hc=0&hs=0"; } if(searchEngine == 3){ finalSearchString = "http://www.excite.com/search.gw?trace=a&search=" + searchString; } if(searchEngine == 4){ finalSearchString = "http://www.hotbot.com/?SW=web&SM=MC&MT=" + searchString + "&DC=10&DE=2&RG=NA&_v=2&act.search.x=89&act.search.y=7"; } if(searchEngine == 5){ finalSearchString = "http://www.infoseek.com/Titles?qt=" + searchString + "&col=WW&sv=IS&lk=noframes&nh=10"; } if(searchEngine == 6){ finalSearchString = "http://www.lycos.com/cgi-bin/pursuit?adv=%26adv%3B&cat=lycos&matchmode=and&query=" + searchString + "&x=45&y=11"; } if(searchEngine == 7){ finalSearchString = "http://netfind.aol.com/search.gw?search=" + searchString + "&c=web&lk=excite_netfind_us&src=1"; } location.href = finalSearchString; } } // --> </script> <basefont face="Verdana, Arial, sans-serif"> <form name="searchForm"> <table width=320 border cellpadding=3 cellspacing=2 bgcolor=444444> <tr> <td bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search for:<br> <td bgcolor=lightblue><font size=1 face="Verdana, Arial, sans-serif">Search from: <td bgcolor=lightblue> <tr> <td bgcolor=navajowhite><input style="background: dddddd" name="searchText" type="text"> <td bgcolor=navajowhite> <select style="background: dddddd" name="whichEngine"> <option selected>Altavista <option>Yahoo! <option>Excite <option>Hotbot <option>Infoseek <option>Lycos <option>AOL Netfind </select> <td bgcolor=navajowhite><input type="button" value="Send" onClick="startSearch()"> </select> </table> </form> <font size=1>Script by <a href="http://www.mbnet.fi/~foo/">Jari Aarniala</a>, <a href="mailto:foo@mbnet.fi">foo@mbnet.fi</a> I am trying to get my form which is in PHP to submit when pressing the Enter key This is what I am using Code: <script type="text/javascript"> function submitFormWithEnter(myfield,e) { var keycode; if (window.event) { keycode = window.event.keyCode; } else if (e) { keycode = e.which; } else { return true; } if (keycode == 13) { myfield.form.submit(); return false; } else { return true; } } </script> PHP Code: <div id='aboutForm'> <span class='headerbox'><b>Your Profile Headline:</b></span> <span class='textbox'><input type='text' name='headline' class='zip' size='67 ' value='$headline' onKeyPress="return submitFormWithEnter(this,event)\"></span> </div> Anyway I can get this to work? Seems to be an issue with the "text" input Hi all, just before i kick off im not looking for the code just a push in the right direction. I am using a wysiwyg editor (tiny mce) which is basicaly a textarea with content in it. What i am looking to do is when a presses enter withing the textarea a <br/> tag is placed where the text curser is. Code: <textarea> <p>dfsdfdfdfdfdf dsfsdfdf dsfdsfdsf dsfdsfds dsfdfdss [enterpressed]<br/> dffdsf dfs dsfd sdf sdfs fdsf</p> </textarea> secondly, if a user users the arrow keys to navigate where to edit, when they get to the begining or the end of a tag, i want the arrows to be disabled. Code: <textarea> <p>||<df<sdf<dfd<fdfdf dsfsdfdf dsfdsfdsf dsfdsfds dsfdfdss [enterpressed]<br/> dffdsf> dfs> dsfd s>df sdfs>> fds>f||</p> </textarea> (<> represents arrow press, || represents blocked, and can go no further) any help much appreciated. I have a basic code for geocoding. I use this code for learning. There is only ONE button on the screen My Questions: 1. How can I set focus on this button so it will be activated when I click Enter ? 2. is it possible to initialize the textbox with the clipboard contents when the hta is loaded ? 3. Is it possible to simulate a click on the button each time the hta is loaded ? Here is the code Many thanks !!! Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Gonen title</title> <script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAkpclZCcw0Dd8N7urilPb8RTwi2g_12bF65p4zEDwX2jt7cD0dhQvH8snORVwA2VqfU-YMqHbC23bgg" type="text/javascript"></script> <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAkpclZCcw0Dd8N7urilPb8RTwi2g_12bF65p4zEDwX2jt7cD0dhQvH8snORVwA2VqfU-YMqHbC23bgg" type="text/javascript"></script> <script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script> <style type="text/css"> @import url("http://www.google.com/uds/css/gsearch.css"); @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");</style> <script type="text/javascript"> //<![CDATA[ var map; var geocoder; function load() { map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(38.134557,-95.800781), 3); geocoder = new GClientGeocoder(); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()) ; // bind a search control to the map, suppress result list } // addAddressToMap() is called when the geocoder returns an // answer. It adds a marker to the map with an open info window // showing the nicely formatted version of the address and the country code. function addAddressToMap(response) { map.clearOverlays(); if (!response || response.Status.code != 200) { alert("Address cannot be geocoded"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); marker = new GMarker(point); map.addOverlay(marker); // place coordinates on clipboard var input = String(place.Point.coordinates) window.clipboardData.setData('Text',input); // will close the window window.close(); marker.openInfoWindowHtml(place.address + '<br />' + '<b>Coordinates:</b> ' + place.Point.coordinates); } } // showLocation() is called when you click on the Search button // in the form. It geocodes the address entered into the form // and adds a marker to the map at that location. function showLocation() { // value from input box // var address = document.forms[0].q.value; // value from clipboard var address = window.clipboardData.getData ("Text") geocoder.getLocations(address, addAddressToMap); } // findLocation() is used to enter the sample addresses into the form. function findLocation(address) { document.forms[0].q.value = address; showLocation(); } //]]> GSearch.setOnLoadCallback(load); </script> <script type="text/javascript"> function getposOffset(overlay, offsettype){ var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop; var parentEl=overlay.offsetParent; while (parentEl!=null){ totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; parentEl=parentEl.offsetParent; } return totaloffset; } function overlay(curobj, subobjstr, opt_position){ if (document.getElementById){ var subobj=document.getElementById(subobjstr) subobj.style.display=(subobj.style.display!="block")? "block" : "none" var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0) subobj.style.left=xpos+"px" subobj.style.top=ypos+"px" return false } else return true } function overlayclose(subobj){ document.getElementById(subobj).style.display="none" } </script> </head> <body onload="load()" onunload="GUnload()"> <table> <tr> </tr> </table> <br /> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <form action="#" onsubmit="showLocation(); return false;" name="geoForm"> <b>Click:</b> <input type="text" name="q" value="" size="0" /> <input type="submit" name="find" value="Get from Clipboard and Map It" /> <br /> </form> <div id="map" style="width: 100%; height: 480px"></div> <hr size=1 align=left width=90% color=#000000 style='border: dotted;'> </form> </body> </html> Hey, I currently have an input box which submits my input box value to php script with a bit of JS: Code: <input type="text" class="cssShoutForm" name="sbText" onSubmit="this.disabled=true; shoutIt()"> <input type="button" name="Shout" value="Submit" class="cssShoutButton" onClick="this.disabled=true; shoutIt()"> Now when a use clicks the submit button and submits the text - input box clears which is perfect but if a user hits enter the value stays in the input box which is a pain cos you have to delete it to type in the next line. Why is this? This is my JS: Code: function shoutIt() { document.fShout.admin.value = ""; document.fShout.submit(); setTimeout("document.fShout.sbText.value=''", 1000); setTimeout("document.fShout.Shout.disabled=false", 1000); } How can i get it to also clear on a user hitting enter? Hi everyone. I'm 100% not a programmer so I need some help with this issue. We have a page for an e-mail newsletter sign up form. The site is built in Joomla. My question : is it possible for a URL link (from say, an email) to send a user to this sign up form and also to fill in a hidden value called channelmemberID? The code is
Code: <input type=hidden name="ChannelMemberID" value="101369"> and I would like to be able to change the value 101369 to anything else. Code samples would be generous and greatly appreciated. The sign up page is here temporarily hosted here http://seoul.directrouter.com/~dancker/?Itemid=82 Hello, I have the following: Code: function search(text) { address = "/cgi-bin/room.cgi?" + text + "-search" + "-1"; location.href=address; } <input type="text" id="query" name="query" size="17" maxlength="32" class="select1" value=""> <input type ="submit" name="cmdSearch" onClick="search(document.getElementById('query').value); value="Search"> Works perfectly in IE. In FF or Chrome works fine when I click the button but not when I press "Enter". Thanks! Hi all, I'm self learning JavaScript and this got me stumpped. I've wrote a very similar function that works perfect but no matter what i do here, the result is always the same. I can't seem to enter a 2 digit number in the second box for weight and therfore won't work. It seems to work fine for up to 9 lbs though. can anyone shed light to this? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script> //this array contains strings that can be broken down //into Shipping Zone, Shipping Range, Shipping Charges //This array is for origin zip 532xx. Weight max is 10lbs var PriorityMailArray = new Array("1 01 04.90", "2 01 04.90", "3 01 04.95", "4 01 05.05", "5 01 05.15", "6 01 05.25", "7 01 05.35", "8 01 05.55", "1 02 05.00", "2 02 05.00", "3 02 05.35", "4 02 05.95", "5 02 07.50", "6 02 08.10", "7 02 08.60", "8 02 09.55", "1 03 05.70", "2 03 05.70", "3 03 06.55", "4 03 07.50", "5 03 09.00", "6 03 09.95", "7 03 10.70", "8 03 12.70", "1 04 06.45", "2 04 06.45", "3 04 07.55", "4 04 08.60", "5 04 11.90", "6 04 13.00", "7 04 13.80", "8 04 15.30", "1 05 07.65", "2 05 07.65", "3 05 08.75", "4 05 09.85", "5 05 13.50", "6 05 14.85", "7 05 15.85", "8 05 17.65", "1 06 08.30", "2 06 08.30", "3 06 09.65", "4 06 11.00", "5 06 15.05", "6 06 16.65", "7 06 17.80", "8 06 19.90", "1 07 08.95", "2 07 08.95", "3 07 10.55", "4 07 11.75", "5 07 16.80", "6 07 18.40", "7 07 20.05", "8 07 22.40", "1 08 09.60", "2 08 09.60", "3 08 11.45", "4 08 13.30", "5 08 18.20", "6 08 20.20", "7 08 22.05", "8 08 25.10", "1 09 10.25", "2 09 10.25", "3 09 12.35", "4 09 14.40", "5 09 19.75", "6 09 22.00", "7 09 23.95", "8 09 27.95", "1 10 10.90", "2 10 10.90", "3 10 13.25", "4 10 15.70", "5 10 21.35", "6 10 23.75", "7 10 26.30", "8 10 30.40" ); //this function makes sure the user has entered zone and weight //and then goes through the array and finds the correct zone and weight that //fits into - then sets the value of the charges field //to the correct charge function FindCharges(){ var Zone = document.getElementById("Zone").value; var Weight = document.getElementById("Weight").value; var Charges = 0 if (Zone.length != 1) { alert("You must enter Shipping Zone!"); document.getElementById("Zone").focus();} if (Weight.length != 1) { alert("You must enter shipping weight!"); document.getElementById("Weight").focus(); return; } else{ Zone = parseFloat(Zone); Weight = parseFloat(Weight); } var curRangeStart, curRangeEnd, Zone, Weight, Charges; for (var i = 0; i < PriorityMailArray.length; i++) { curRangeStart = parseFloat(PriorityMailArray[i].substring(0, 1)); curRangeEnd = parseFloat(PriorityMailArray[i].substring(2, 4)); if (Zone == curRangeStart && Weight == curRangeEnd) { Charges = parseFloat(PriorityMailArray[i].substring(5, 10)); document.getElementById("Charges").value = Charges; return; } } alert("You entered in an invalid zone!"); document.getElementById("zone").focus(); } </script> </head> <body> Enter shipping zone and weight: <input type="text" id="Zone" size="1" onkeydown="document.getElementById('Zone').value=''"> <input type="text" id="Weight" size="5" onKeyDown="document.getElementById('Weight').value=''"> <input type="button" onclick="FindCharges()" value="Find Charges"> Shipping is: <input type="text" id="Charges" size="5" disabled> </body> </html> Thanks for the help Hell All Can some1 give me a function for Alert Visitor before the page Load if he /she Sure wants to See the Page . I have function Onclick alert message but i want the function is when click and go to the page and before the page load to ask 'if want realy to see the page' if yes return true if cancel or no to go back to where he come from. Thank you and hope such function exist. Hello, I need your help. I basically need, when the enter button is pressed on the keyboard to trigger a button. Currently, my code works but it just refreshes the page and does not actually trigger the desired button: Code: //HERES MY CUSTOM BUTTON: <BUTTON TYPE="submit" onMouseOver="goLite(this.name)" onMouseOut="goDim(this.name)" onclick="javascript:v7_search()" CLASS="btn_std" NAME="btn_search" > ? Search </BUTTON> Here's the code to make the enter button work: Code: <form name="frmIMTS" onkeydown="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('btn_search').click();}};" > Any help with this is greatly appreciated. Cheers, J Hi All, Im a newbie when it comes to Javascript and trying to learn as I go along. I am working on an internal work site. In the site I have a text box and on entering a specific code I want it to open a new page that links to a document that has the same name. ie. if user types red, I want it to find the document red.html in a folder. To make my colleagues job easier, I want the text box to autocomplete. Below is a section of the code I plan to use Code: <script> var arrValues = ["red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown"]; </script> </head> <body> <h2>Autocomplete Textbox Example</h2> <p>Type in a color in lowercase:<br /> <input type="text" value="" id="txt1" onkeypress="return autocomplete(this, event, arrValues)" /></p> </body> </html>Can anyone help me to modify this to: 1) link the text entered to the document I want opened 2) open this document upon 'enter' pressed If anyone can provide help it will be greatly appreciated. Thanks Glen |