JavaScript - Change Input Background On Enter
How do I change a text input's background when the user hits "Enter" or Key #13.
The text-input field currently light's up to blue when hovered over, then it turns green when it is focused on, and now I want it to turn pink when you submit it. (This can be seen at http://ocmd.co.nr/ap) ------------------ Also, if anyone knows how I can redirect the user depending on there input, that'd be great. Regularly, it just runs a Google Search, but if I could get it so that when someone typed in, "chat room 1" for example, it'd open up a link or a new window w/ that. Similar TutorialsHey, 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? I have a very small script that simply displays a search box and redirects a user to a URL if they enter 29401 or 29455, else they go to a default page. The script works fine, but I cannot figure out how to make value="enter a zip code" in the input box so that it disappears when you click in the box. I also can't get the form to submit by pressing enter, you have to click "check". I can get all this working in straight HTML but the same won't work w/ javascript. Any help please? <SCRIPT LANGUAGE="JavaScript"> function zipValidate(){ val = document.zipForm.zip.value; switch(val){ case "29401": case "29455": document.location = 'http://www.gohere.com'; break; default: document.location = 'http://www.or-go-here.com'; break; } } </SCRIPT> <form name="zipForm" id="zipForm" method="post" action=""> <input name="zip" type="text" id="zip" maxlength="5" /> <input name="zipButton" type="button" id="zipButton" value="Check" onclick="zipValidate()" /> </form> 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! Still need assistance, thanks Okay, so here's an example code of what I'm needing: Code: <html> <head> <title></title> <style type="text/css"> #greenrow { background-color:#090; } #redrow { background-color:#F00; } </style> <script type="text/javascript"> if (calculate.level.value >= calculate.getElementById('shrimp').value){ class = greenrow; } else { class = redrow; } </script> </head> <body> <form name="calculate"> <table> <tr> <td><label> Level<input name="level" type="text" size="5" /></label> </td> </tr> <tr id="shrimp"> <td>Shrimp</td> <td align="center"><label> <input type="text" name="shrimp" /> </label></td> <td colspan="3" align="left">10</td> </tr> </table> </form> </body> </html> Okay so what I want to be done is to get information from the input text area "level" and IF "level" is >= 10...for this one certain row, I want it to get the class #greenrow. Else, class = #redrow. Thanks hi i wants to change one input to texarea when i select one from radio, plz any suggestion how i would do that? my code PHP Code: <input type="text" name="other" value="this need to become textarea" /> <input type="radio" name="inputtext" />Text <input type="radio" name="inputtext" />Textarea so when i click inputtext radio name"other" will become a textrea rather then input type text. thanks for any help. I'm trying to change a row of input fields to have the value(s) of a table row. When I click a button called Next, I want to pull in the value(s) that are already on the display. If I click Next again, I want to pull in the next row's values or if I click the button called Previous I want to get the prior lines values. Can someone please help or push me in the right direction? Thanks. Code: <script type="text/javascript"> function copyLine() { document.getElementById("pitem").value=document.getElementById("p1item").value; document.getElementById("ploc").value=document.getElementById("p1loc").value; document.getElementById("plot").value=document.getElementById("p1lot").value; document.getElementById("pqty").value=document.getElementById("p1qty").value; } </script> <table> <tr> <td><input type="text" name="item" id="pitem" size="15" value=""></td> <td><input type="text" name="loc" id="ploc" size="7" value=""></td> <td><input type="text" name="lot" id="plot" size="7" value=""></td> <td><input type="text" name="qty" id="pqty" size="10" value=""></td> </tr> <tr> <td><input type="button" value="Next" onclick="copyLine()"> <input type="button" value="Previous" /></td> </tr> <tr> <td id="p1item">Item 1</td> <td id="p1loc">Location 1</td> <td id="p1lot">Lot 1</td> <td id="p1qty">100</td> </tr> <tr> <td id="p2item">Item 2</td> <td id="p2loc">Location 2</td> <td id="p2lot">Lot 2</td> <td id="p2qty">200</td> </tr> <tr> <td id="p3item">Item 3</td> <td id="p3loc">Location 3</td> <td id="p3lot">Lot 3</td> <td id="p3qty">300</td> </tr> </table> Hi there, I'm working on a site: ocmd.co.nr And it features a lot of handy little web gadgets and apps for users. I was interested in creating a page, where two iframes are shown side-by-side both with the width of 50% and the height of 100%, with adressbars on top of each of them. So, essentially, what I need is just a code that allows the user to edit the iframe's src and get it to a different site. well title says it all i have a search form, and the default value is "enter text here" when the user click the submit button, i would like to check if the value of my text input is "enter text here" and if it is, then don't submit the form (popup a warning or something) how can i do that? thanks a lot! Hello, I am trying to change the value of #name and #category inputs based on the value of select. A friend gave me the code below, but I can't get it to work. Thanks so much for your help Code: <script type="text/javascript"> $('#Gift_Type').change(function(){ if ($(this).val() == 'Monthly'){ $('#name').val('Partnership') $('#category').val('Partnership') } else { $('#name').val('Donation') $('#category').val('Donations') } }) </script> Code: <SELECT NAME="sub_frequency" ID="Gift_Type" onchange="OnSelectionChanged (this)"> <OPTION VALUE="1m">Monthly</OPTION> <OPTION VALUE="">One Time</OPTION> </SELECT> Code: <input type="text" id="name" name="name" value="Partnership" /> <input type="text" id="category" name="category" value="Partnership" /> I'm trying to use an onclick function in a radio button to change the value of a hidden input in another form. What I want to happen is, when the user changes the value of the radio button (0 or 1), the value of the input named 'repeat' is set to 0 or 1 accordingly. The goal being that when I submit the form with input name='repeat' it will send the number indicated by the radio button. (Due to the structure of my page the radio button and the hidden input need to be two separate forms, but I don't think that should be a problem.) The code below isn't working -- the alert("changerepeat called") never even appears. It seems like the problem is that the onclick isn't even activating at all. Any ideas? Code: <script type="text/javascript"> function changerepeat(theval) { alert("changerepeat called"); document.forms[0].elements[0].value = theval; } function tellme() { alert("repeat = "+document.forms[0].elements[0].value); } </script> <form> <input type='hidden' name='repeat' value=''> <input type='button' value='tellme' onclick='tellme()'> </form> <form> <input type='radio' name='changerepeat' onclick='changerepeat(\'0\')'> 0 <input type='radio' name='changerepeat' onclick='changerepeat(\'1\')'> 1 </form> Thanks very much for reading! I have a script where I need to change input values automatically, and I just can't find the right code for it. Here's a little of my code below, can anyone help me, please? Code: document.getElementById("Id").innerHTML="Text here"; I have a problem thats above my head, im new to javascript. I want to be able to control the first three characters of an input string on a login form. If a user types GP15555 or JP15555 I want it to change to GPL5555 or JPL5555 respectively changing the "1" to an "L" on the prefix is this at all possible? any point in the right direction would be great. heres my code Code: </script> <script language="JavaScript" type="text/javascript"> //<![CDATA[ function Login(form) { var password = form.password.value; var pin = form.pin.value; var product = form.product.value; if (password) { var htsite = product + "/" + password + "/" + pin + "/index.html"; window.location = htsite; } else { alert("Please enter your password and pin."); } } // End --> //]]> </script> /thanks gp I wrote a function, to change a input value to show a key, which PHP later recognizes and makes addition changes too. However I can't seem to get this simple function to work, can you see anything wrong with it? Code: function quote(id) { var shout = document.getElementById('shout'); var currentShout = '; '.shout.value; var prefix = '@'.id; shout.value = prefix.currentShout; } I call it by Code: <a href="#" onclick="javascript: quote('2');">Comment</a> the input that changes is written as Code: <input id="shout" name="shout" type="text" onKeyPress="return submitenter(this,event);"> I have been working on this code for a few days now and it works. Or at least it appears to be working. I would like to have the tot 1, tot 2, tot 3 return with currency formatting. Is there a way to add something to my code to accomplish this? Thank you in advance for any suggestions. Regards Code: <html> <head> <script type="text/javascript" src="autoCurrency.js"></script> <script type="text/javascript"> function doCalc() { var v1 = document.getElementById('value1').value; var v2 = document.getElementById('value2').value; var v3 = document.getElementById('value3').value; document.getElementById('total1').value = ((v1*5)+(v2*1)) * (1-v3/100); document.getElementById('total2').value = ((v1*10)+(v2*1)) * (1-v3/100); document.getElementById('total3').value = ((v1*15)+(v2*1)) * (1-v3/100); } </script> <style type="text/css"> button { width: 80px; } input { margin: 10px 0; } input[type='text'] { width: 50px; } </style> </head> <body> <div> <input id="value1" type="text" value="0" /> <br /> </div> <div> <input id="value2" type="text" value="0" /> <br /> </div> <div> <input id="value3" type="text" value="0" /> <br /> </div> Tot 1:<input id="total1" type="text" /><br /> Tot 2: <input id="total2" type="text" /><br /> Tot 3: <input id="total3" type="text" /><br /> <button class="long" onclick="doCalc();">Calculate</button> </body> </html> Hi! I want to insert flash player on my page, that user can change flv source. But I dont know how to make input field that change flv source. I tried to insert input field and button but dont know how to make it working, please help me Here is my flvplayer embed code: <script type="text/javascript" src="http://flvplayer.com/free-flv-player/flvplayer/swfobject/swfobject.js"></script> <div id="embed_player"> <h1>Please Upgrade Your Flash Player</h1> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <script type="text/javascript"> var flashvars = { flvpFolderLocation: "http://flvplayer.com/free-flv-player/flvplayer/", flvpVideoSource: "http://flvplayer.com/media/audi_tdi_commercial.mp4", flvpWidth: "640", flvpHeight: "375", flvpInitVolume: "50", flvpTurnOnCorners: "true", flvpBgColor: "#FFFFFF" }; var params = { bgcolor: "#FFFFFF", menu: "true", allowfullscreen: "true" }; swfobject.embedSWF("http://flvplayer.com/free-flv-player/FlvPlayer.swf", "embed_player", "640", "375", "9.0.0", "http://flvplayer.com/free-flv-player/flvplayer/swfobject/expressInstall.swf", flashvars, params); </script> Hi there, I am a new javascript guy - struggling a bit but marching on - The following code works fine to set a form field - Code: document.getElementById("ZS_Land").value = (empLand.innerHTML); However, I changed to form field into a select with option list, and I need it to set an option from the select now - the select has the same name/id as the field had, but is not working Any ideas how I do that ? Many thanks in advance Glorifindal Hi All, I quite new to JavaScript and find myself stuck while trying to change the background colour of an input box. I have an external js file and everything seems to work perfectly but for some reason I cant get the colour to change. Any help is REALLY appreciated! Code: function validateID(id, name, value) { var regEx = /(abc)/; var result = regEx.test(value); alert(value + " " + result + " " + regEx + " " + name); if (result == true) { userFeedback(id, '<--Input Is Valid'); document.getElementsByName(name).style.backgroundColor='green'; } else { userFeedback(id, '<--Error: Input Is Not Valid'); } } Reply With Quote 01-12-2015, 11:35 AM #2 VIPStephan View Profile View Forum Posts Visit Homepage The fat guy next door Join Date Jan 2006 Location Halle (Saale), Germany Posts 8,989 Thanks 6 Thanked 1,054 Times in 1,027 Posts Don’t change styles with JavaScript. In order to separate the concerns (content/style/behavior) you should add/remove a class to the element and apply styles with CSS using that class as selector. Every contemporary browser has a developer console built in, look into the JS console and see if there are any errors coming up. Other than that, it helps if you posted a link to your page so we can see ourselves without having to guess. Reply With Quote 01-12-2015, 11:59 AM #3 murtagh View Profile Hello, I'm currently working on http://footytweets.co.uk and would like to add an input field to my twitter feed widgets, which allows users to change which twitter account tweets are dispalyed. An example is here; https://twitter.com/about/resources/...widget_profile You can see in the example how you can enter a different twitter user account, then hit 'test settings', leading to related twees being displayed. I can see how to do it but Im a super novice at JS so thought Id ask for assistance . Any code help is very much appreciated. Thx Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks I currently have a web site in which I am using some Javascript to change the Background of a DIV. The DIV is defined as follows : <div id="outerscreen"> <div id="mainscreen"> </div> </div> and the Javascript I am using is as follows : var docEl = document.getElementById('outerscreen'); docEl.style.backgroundImage = "url('pics/intro.gif')"; My problem arises where this function works perfectly on IE but fails for Chrome, FF and Safari. Can anyone shed any light on what the problem is and how I might be able to resovle this. Thanks in advance Chris |