JavaScript - Enter Press Replaced With Tag
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. Similar TutorialsHey: I have several "submit" buttons on a form. I want users to be able to hit the "enter" key to submit the form. The page used to "post" the information checks for specifically what form button was pushed to submit the form before executing the appropriate code. I am automatically submitting the page when the enter key is hit, but it is defaulting to the first option of executed code in the post page. Example - I have an "update" button and a "delete" button on the form. On the post page, I first check to see if the delete button was hit. When I press enter on the form, it simply answers yes to the first question (did they click the delete button), and the code is executed. I really wanted to emulate that the update button was hit. So -- is there a way to hit the enter button, and in the js code, mandate that it was the "update" button that was clicked? Thanks. 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! Hello guys, This problem I've had for nearly 2 weeks now because of it I cannot progress any deeper with my project. Here is a live demo http://dcourt.zxq.net/dcourt/ try to login pkedpker and password doesn't matter then click on the new image that pops out.. press Done now you will be at stat setting window.. which you will see doesn't work.. but if you run statsetting window instead of login.php it will work perfectly whats wrong? I know it's not a <form> error.. because form is there in the index I have. PHP Code: <?php session_start(); ini_set('display_errors', '1'); //show errors. //include_once 'functions.php'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript"> function updateUI(str) { var ajaxObj = new XMLHttp(); var url = 'ajax.php'; var method = 'POST'; var params = 'page='+str; makeRequest(ajaxObj, method, url, params, 'maincontent'); ajaxObj = null; } </script> </head> <body> <table border="1" align="center" width="440" height="330"> <tr> <th scope="col"> <form name="UI" id="UI" action="" onsubmit="return false;"> <div id="maincontent"> <?php include 'ajax/login.php'; ?> </div> </form> </th> </tr> </table> </body> </html> ajax.php is simply the data outputter. PHP Code: <?php $page = (isset($_POST['page']) ? $_POST['page'] : ''); if ($page == "login") { include 'ajax/login.php'; } elseif ($page == "dologin") { include 'ajax/dologin.php'; } elseif ($page == "startingstats") { include 'ajax/startingstats.php'; } elseif ($page == "rankings") { include 'ajax/rankings.php'; } elseif ($page == "updates") { include 'ajax/updates.php'; } elseif ($page == "howto") { include 'ajax/howto.php'; } else { include 'ajax/login.php'; } ?> now the ajax folder has all the scripts that get outputted.. lets say the login.php page in ajax folder for now PHP Code: <script type="text/javascript"> <!-- var ubool = 0; var pbool = 0; var jsuser = ''; var jspw = ''; function userCheck(user) { jsuser = user; ubool = (user.length > 0) ? 1 : 0; if(ubool && pbool) document.getElementById("login").style.visibility = "visible"; else document.getElementById("login").style.visibility = "hidden"; } function pwCheck(pass) { jspw = pass; pbool = (pass.length > 0) ? 1 : 0; if(ubool && pbool) document.getElementById("login").style.visibility = "visible"; else document.getElementById("login").style.visibility = "hidden"; } function doLogin() { var ajaxObj = new XMLHttp(); var url = 'ajax.php'; var method = 'POST'; var params = 'page=dologin&user='+jsuser+'&pw='+jspw; makeRequest(ajaxObj, method, url, params, 'maincontent'); ajaxObj = null; } //--> </script> <div style="position: fixed; top: 222px; margin-left: 120px; color: white;">Welcome Kongregate Name</div> <div style="position: fixed; top: 252px; margin-left: 2px; color: white;">Hero Name:</div> <div style="position: fixed; top: 282px; margin-left: 2px; color: white;">Password:</div> <div style="position: fixed; top: 252px; margin-left: 90px;"><input type="text" name="user" id="user" size="12" maxlength="20" value="" onInput="javascript:userCheck(this.value)" onpropertychange="javascript:userCheck(this.value)" /></div> <div style="position: fixed; top: 282px; margin-left: 90px;"><input type="text" name="pw" id="pw" size="12" maxlength="20" value="" onInput="javascript:pwCheck(this.value)" onpropertychange="javascript:pwCheck(this.value)" /></div> <div id="login" style="position: fixed; top: 252px; margin-left: 210px; visibility: hidden;"><input type="image" src="images/quest.jpg" width="96" height="64" onClick="javascript:doLogin()" /></div> <div style="position: fixed; top: 252px; margin-left: 334px;"><input type="submit" name="rankings" value="Ranking List" onClick="javascript:updateUI('rankings')"></div> <div style="position: fixed; top: 282px; margin-left: 357px;""><input type="submit" name="updates" value="Updates" onClick="javascript:updateUI('updates')"></div> <div style="position: fixed; top: 312px; margin-left: 300px;"><input type="submit" name="howto" value="How to get started" onClick="javascript:updateUI('howto')"></div> <img src="images/splash.jpg" width="440" height="330" /> yes it has no forms in the page above so javascript shouldn't function right? Wrong look at index.php it has a <form> wrapper that wraps the <div> which gets updated by the ajax.php outputter that outputs ajax folder pages. Note okay that works.. the javascript functions on it all wonderfully. Now in this ajax/login.php thats loaded if you login with lets say pkedpker it checks it using index.php's javascript ajax call to ajax.php which calls dologin.php page in ajax folder. ajax/dologin.php is simply PHP Code: <?php //if(isset($_POST['user']) &&isset($_POST['pw'])) { // echo "user and password both set"; if($_POST['user'] == "pkedpker") { //and IS ALSO NEWBIE! STATING SCREEN COMES NEXT ?> <div style="background-color: #000000; color: #FFFFFF; font-weight: bold; width: 440px; height: 330px;"> A young hero arises from the plebium masses! <div style="position: fixed; top: 312px; margin-left: 300px;"><input type="submit" name="login" value="Done" onclick="javascript:updateUI('startingstats')"></div> </div> <?php } elseif($_POST['user'] != "pkedpker") { ?> <div style="background-color: #000000; color: #FFFFFF; font-weight: bold; width: 440px; height: 330px;"> Error: Hero Not Found [ <?php echo $_POST['user'] ?> ] <div style="position: fixed; top: 312px; margin-left: 300px;"><input type="submit" name="login" value="Done" onclick="javascript:updateUI('login')"></div> </div> <?php } else { ?> <div style="background-color: #000000; color: #FFFFFF; font-weight: bold; width: 440px; height: 330px;"> Error/Hack Attempt?: Username or password were found to be empty! <div style="position: fixed; top: 312px; margin-left: 300px;"><input type="submit" name="login" value="Done" onclick="javascript:updateUI('login')"></div> </div> <?php } ?> Nothing important just a few little tests I've setup.. the test that is interesting me is the 'A young hero arises' which has a ajax call to index.php that calls ajax.php which then includes a page from ajax folder called startingstats This is the ajax/startingstats.php code PHP Code: <script type="text/javascript"> <!-- var buildPts = 20; function buildPointsCheck(skill, direction, isMoney) { if(isMoney === 0) { if(direction == 1 && buildPts > 0) { buildPts--; skill.value++; } else if(direction === 0 && skill.value > 0) { buildPts++; skill.value--; } } else { var curMoney = (skill.value >= 25) ? skill.value / 25 : 0; if(direction == 1 && buildPts > 0) { buildPts--; curMoney++; } else if(direction === 0 && curMoney > 0) { buildPts++; curMoney--; } skill.value = (curMoney * 25); } if(buildPts === 0) { document.getElementById("login").style.visibility = "visible"; } else { document.getElementById("login").style.visibility = "hidden"; } document.getElementById("buildpoints").value = buildPts; } function buildOptionsCheck(buildOption) { if(buildOption.checked) { if(buildOption.name == "wizard" && buildPts >= 9) { buildPts-=9; } else if(buildOption.name == "trader" && buildPts >= 10) { buildPts-=10; } else if(buildOption.name == "warrior" && buildPts >= 8) { buildPts-=8; } else if(buildOption.name == "sage" && buildPts >= 12) { buildPts-=12; } else { buildOption.checked = false; } } else { if(buildOption.name == "wizard") { buildPts+=9; } else if(buildOption.name == "trader") { buildPts+=10; } else if(buildOption.name == "warrior") { buildPts+=8; } else if(buildOption.name == "sage") { buildPts+=12; } } if(buildPts === 0) { document.getElementById("login").style.visibility = "visible"; } else { document.getElementById("login").style.visibility = "hidden"; } document.getElementById("buildpoints").value = buildPts; } function setStats() { var ajaxObj = new XMLHttp(); var url = 'ajax.php'; var method = 'POST'; var params = 'page=startingstats&guts='+document.getElementByName("guts").value+'&wits='+document.getElementByName("wits").value+'&charm='+document.getElementByName("charm").value+'&money='+document.getElementByName("money").value+'&wizard='+document.getElementByName("wizard").value+'&trader='+document.getElementByName("trader").value+'&warrior='+document.getElementByName("warrior").value+'&sage='+document.getElementByName("sage").value; makeRequest(ajaxObj, method, url, params, 'maincontent'); ajaxObj = null; } //--> </script> <div style="background-color: #0000FF; color: #FFFFFF; font-weight: bold; width: 440px; height: 330px;"> <table border="1" align="center"> <th colspan="3"><span style="color: #00FF00; font-weight: bold;">stepansky</span></th> <tr> <td> <div align="center"><span style="color: #FFFF00; font-weight: bold;">Guts</span><br /> <table> <tr> <td><input name="button" type="button" value="+" onClick="javascript:buildPointsCheck(this.form.guts, 1, 0)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> <td rowspan=2><input type="text" name="guts" value="4" size="5"></td> </tr> <tr> <td><input name="button2" type="button" value="-" onClick="javascript:buildPointsCheck(this.form.guts, 0, 0)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> </tr> </table> </div> </td> <td> <div align="center"><span style="color: #FFFF00; font-weight: bold;">Wits</span><br /> <table> <tr> <td><input name="button" type="button" value="+" onClick="javascript:buildPointsCheck(this.form.wits, 1, 0)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> <td rowspan=2><input type="text" name="wits" value="4" size="5"></td> </tr> <tr> <td><input name="button2" type="button" value="-" onClick="javascript:buildPointsCheck(this.form.wits, 0, 0)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> </tr> </table> </div> </td> <td> <div align="center"><span style="color: #FFFF00; font-weight: bold;">Charm</span><br /> <table> <tr> <td><input name="button" type="button" value="+" onClick="javascript:buildPointsCheck(this.form.charm, 1, 0)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> <td rowspan=2><input type="text" name="charm" value="4" size="5"></td> </tr> <tr> <td><input name="button2" type="button" value="-" onClick="javascript:buildPointsCheck(this.form.charm, 0, 0)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> </tr> </table> </div> </td> </tr> <tr> <td colspan="2"> <div align="center"><span style="color: #FFFF00; font-weight: bold;">Options</span> <table width="100%" border="0"> <tr> <td><input type="checkbox" name="wizard" value="" onClick="javascript:buildOptionsCheck(this.form.wizard)"> Wizard 9p</td> <td><input type="checkbox" name="trader" value="" onClick="javascript:buildOptionsCheck(this.form.trader)"> Trader 10p</td> </tr> <tr> <td><input type="checkbox" name="warrior" value="" onClick="javascript:buildOptionsCheck(this.form.warrior)"> Warrior 8p</td> <td><input type="checkbox" name="sage" value="" onClick="javascript:buildOptionsCheck(this.form.sage)"> Sage 12p</td> </tr> </table> </div> </td> <td> <div align="center"><span style="color: #FFFF00; font-weight: bold;">Money(1p=$25)</span><br /> <table> <tr> <td><input name="button" type="button" value="+" onClick="javascript:buildPointsCheck(this.form.money, 1, 1)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> <td rowspan=2><input type="text" name="money" value="25" size="7"></td> </tr> <tr> <td><input name="button2" type="button" value="-" onClick="javascript:buildPointsCheck(this.form.money, 0, 1)" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;"></td> </tr> </table> </div> </td> </tr> <tr> <td> <div align="center"><span style="color: #FFFF00; font-weight: bold;">Build Points left</span><br /> <input type="text" id="buildpoints" name="buildpoints" value="20" size="5"> </div> </td> <td> <div id="login" style="visibility: hidden;"> <input type="image" src="images/quest.jpg" width="96" height="64" onClick="javascript:setStats()" /> </div> </td> <td> <center> <input type="image" onClick="javascript:updateUI('login')" src="images/exit.jpg" /> </cener> </td> </tr> </table> </div> Now just including ajax/startingstats.php in index.php instead ajax/login.php IT FUNCTIONS perfectly!. Now if I let it all run normal using dologin.php to make the startingstats.php page load up which it does.. the javascript doesn't function tell me why? can someone please tell me why I've attached the whole project if someone wants to test it No MYSQL required.. just PHP Thank you! Hey all, Objective: - when you select other the pull down menu is replaced by the text field. Currently: - Gotten it to the level of when you select the other the text field appears. Question: - HOw can I modify the code so when I select the other menu option from the pull down menu and it replaced by the text field? Quote: <script type="text/javascript"> function togglefield(val) { var o = document.getElementById('other'); (val == 'Other')? o.style.display = 'block' : o.style.display = 'none'; } </script> and the form: <form action="" method="post"> <select name="sel" id="sel" onChange="togglefield(this.value);"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="Other">Other</option> </select> <input type="text" name="other" id="other" style="display: none;"> </form> hi friends, i got a two textboxes,my requirement is when i enter two charectors in textbox1,automatically cursor must point to textbox2. but in my case it is not happening like above,when ever i enter charector3,curosr is entering textbox2 along with the entered charector, please find my code below and help me in modifying it. 1.abc.ascs.cs file code is: txtCategory.Attributes.Add("OnKeyPress", "Focus1(this.id);"); 2.abc.ascx file code is: <script type="text/javascript"> function Focus1(that) { if (document.getElementById(that).value.length>1) { //If Len(.Text) = 2 Or Len(TXTbox.Text) = 5 Then document.getElementById('ShippedQtyAdjEntry1_txtDetail').disabled=false; document.getElementById('ShippedQtyAdjEntry1_txtDetail').style.backgroundColor="White"; document.getElementById('ShippedQtyAdjEntry1_txtDetail').focus(); } Hi, Hi, I want to simulate user KEY PRESS (not mouse clicking) automatically on a screen every time that a pop up window (script error message) is opened on the screen OR detecting when an an iframe gets focus. My goal: Automatically closes the pop up window. If anybody know the exact code please post it. FG I want to detect the double-press of the space key. However, I want a single press of a space key to have a different function. The double-tap of space should only count if the taps of space are no more than, say, a half second apart. For example: The user hits space once, and javascript begins performing one action. 1/3rd of a second later, they hit the space bar again, and since that is within our threshold of 1/2 of a second, the action that began because the user hit the spacebar once should be cancelled, or undone (which I can write later) and the action when the user hits the spacebar twice should begin. Anyone have an idea how to do this? Thanks! Hello, I've been working on creating a script that zooms the entire webpage. Other than using "CTRL" + "+" keys (generally compatible with all browsers) to zoom in inside a web browser, I want to put it in a different format, as a button; it would be even easier to use. The problem is that I can't figure out how to make it work/ why it does not work. The following is my code: Code: <html> <head> <script type = "text/javascript"> document.onkeydown = function(zoomin) { var key; zoomin = zoomin || event; key = zoomin.keyCode; key == 43; return false; if (key == 17) { return true; function(zoomin){; return false; } } }</script> </head> <body> <h1>Is this appearing to get bigger?</h1> <button onclick="javascript: function('zoomin');">Zoom in</button> </body> </html> Basically I was trying to use a DEC code as the code for the "CTRL" and "+" keys; then put them into a function. The "return true" under the IF statement means that I want it to hold so that the "+" key can be read as part of the script, and therefore make the page zoom in. Once that happens, it returns false. I would appreciate any help/ suggestions. I will also try to look for a way to reset the page (100%) or zoom out as well. Hello, I have a script that enables a certain button when some conditions are met. I'm having an issue with it, so I made a simple script to get to the core of what I'm trying to do. This is the script that I'm using: Code: function disable() { document.form.button2.disabled='false'; } Code: <form name="form"> <input type="button" name="button1" value="Enable Button 2" onclick="disable()" /> <input type="button" name="button2" value="Button 2" disabled="true" /></form> Basically when you press button 1, button 2 enables. If I reverse it (button 2 enabled by default, pressing button 1 enables it) it is fine. But for some reason this way round nothing happens when I press button 1. What am I doing wrong? Hi I am trying to trigger an event once the user clicks the browsers back/forward buttons, I have built a system just like facebook where if the user has javascript turned on they get the full feature of the site which includes fast switching for example if someone goes to this page "example.com/index.php" and click a link to contact.php it would change the url to "example.com/index.php#!/contact.php" but what I need to know is if there is any way to change the pages content when the user goes back and forth through the fast switch pages? something like "history.back !== -1" or something like that. If anyone can help please reply, thank you. Here is my example code Code: <html> <head> </head> <body onload="addtext()"> How do I keep the cursor position after the " has been replaced with &quot;?<br><br> <form name="update" id="update" method="post" action=""> <textarea name="description" id="description" value="" cols="55" rows="15" onKeyUp="addtext()">Type a quote here[] and see the cursor move to the end he </textarea> <br> Result:<br> <div name="outputtext" id="outputtext"></div> </form> </body> <script language="javascript" type="text/javascript"> function addtext() { var newtext = document.update.description.value; document.getElementById('outputtext').innerHTML = newtext.replace(/\r\n|\n/g,"<br />"); document.getElementById('description').value = newtext.replace(/"/g,"""); } </script> </html> Hi, I have a form that when you click submit gives a warning box asking if to continue code below Now when I type in the text field and press enter it doesn't submit nor does it pop up the warning box, how would I do this Code for submit button Code: <script LANGUAGE="JavaScript"> <!-- function submitMyForm() { var agree=confirm("ARE YOU SURE ?"); if (agree) return true ; else return false ; } // --> </script> Code: <form action="admin-delete.php" method="post" name="cp_delete" id="cp_delete"> <input type="text" name="cp_delete_bg" id="cp_delete_bg"> <input type="submit" name="submit" value="submit" onclick="return submitMyForm()"/> </form> 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 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(); } 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! 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 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, 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 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 |