JavaScript - Recording The Id Of A Input-text If A Particular Key Is Pressed
I need a javascript that could record the ID/name of a textbox when the user hit delete or backspace to be used on the next page after submission in a PHP script.
There are 96 text boxes, they are all randomly placed on the screen with a question that came from a randomized array's keys (the script later checks the values of the textboxes with the values from the array's keys that correlate to the textboxes by the name/id of the textbox, which is assigned by a for loop that issues the next($array) to assign everything everywhere. At the same time, it needs to count how many times the backspace/delete were pushed and have that recorded and sent as well. After 45 minutes of research I've been able to solve the "count the backspace/delete key" problem: Code: <script type="text/javascript"> var count = 0; document.onkeypress=function(e){ var e=window.event || e if (e.keyCode == 8) { //8 is backspace count++; document.getElementById('backspace').value=count; //this is a hidden input } if (e.keyCode == 46) { //46 is delete count++ document.getElementById('backspace').value=count; //the hidden input } } </script> But onto the name/id issue: I'm not sure how to go about retrieving the names/id of the textboxes. I would assume a onkeypress event for every textbox, but hope that there could be something I could just add to this code. Thank you for your help. Similar TutorialsHello, I'm using google voice search on a simple form: Code: <form action="http://www.google.com/search"> <input type="search" name="q" speech required onspeechchange="startSearch"> </form> How to activate the voice search, that is generally activated by clicking on the little microphone near the textbox, without clicking it? I want it to start recording the voice after the user starts talking, or alternatively, after a tot # of seconds.. I did not find anything on the API: http://www.w3.org/2005/Incubator/htm...api-draft.html I thank you in advance Hi all can someone guide me (total JS newbie) on this presumably pretty easy task? I have a "parent" page with some text inputs in it (a form). This is what I am after: -when the user clicks a link it pops open a new window via JS - "child" (this is working). -in the "child" window there are also some text inputs (another form) (done). -when the user changes the value for 'testChild_textInput_4' in the child window, then I want it to automatically set this same value, to effectively overwrite, what is currently in 'testParent_textInput_2' in the parent window. Presumably this involves an onChange event, but it is also OK with me if the needful (the text input's value in the parent window being overwritten) happens upon the child window's form submit. If anyone can show me either trick, I would be thrilled! I set up a test page to make this all easy to talk about: http://www.yellow-turtle.com/testDumpMe_parent.html Please let me know! Thanks! -John I am thinking this should be fairly easy but yet I am not getting far. I want to have a form with a single text imput field for a zip code. Depending on which zip code the user enters will determine which url they will be sent to. If they enter a zip code which is not in the script, they would be sent to a default url. I am also assuming this can be accomplished with javascript. Any help is greatly appreciated. i have borrowed a java script to produce a weather forecast using data from my weather station. Quote: //code to get your variables goes here //I've assumed they a // $sager_wind = wind direction // $sager_rumbo = wind change // $sager_hpa = Baro value // $sager_trend = Baro trend // $sager_nubes = Sky condition //now we can prepare them for the Sager script //the sager script wants uppercase, so just to be sure... $sager_wind = strtoupper($sager_wind); //has to be uppercase $sager_rumbo = strtoupper($sager_rumbo); //allow for either of mB or Hg input if ($sager_hpa > 50) { $sager_hpa = $sager_hpa * 0.0295300;} //enumerate the Baro switch ($sager_hpa) { case ($sager_hpa > 30.4): $sager_hpa = 1; break; case ($sager_hpa > 30.1): $sager_hpa = 2; break; case ($sager_hpa > 29.9): $sager_hpa = 3; break; case ($sager_hpa > 29.7): $sager_hpa = 4; break; case ($sager_hpa > 29.5): $sager_hpa = 5; break; case (sager_hpa > 29.2): $sager_hpa = 6; break; case (sager_hpa > 28.: $sager_hpa = 7; break; case (sager_hpa > 28.0): $sager_hpa = 8; break; } //enumerate the Baro trend if (strcasecmp($sager_trend, 'Rising Rapidly') == 0) { $sager_trend = 1; } if (strcasecmp($sager_trend, 'Rising Slowly') == 0) { $sager_trend = 2; } if (strcasecmp($sager_trend, 'Steady') == 0) { $sager_trend = 3; } if (strcasecmp($sager_trend, 'Falling Slowly') == 0) { $sager_trend = 4; } if (strcasecmp($sager_trend, 'Falling Rapidly') == 0) { $sager_trend = 5; } //enumerate the Sky condition if (strcasecmp($sager_nubes, 'Clear') == 0) { $sager_nubes = 1; } if (strcasecmp($sager_nubes, 'Partly Cloudy') == 0) { $sager_nubes = 2; } if (strcasecmp($sager_nubes, 'Mostly Overcast') == 0) { $sager_nubes = 3; } if (strcasecmp($sager_nubes, 'Overcast') == 0) { $sager_nubes = 4; } if (strcasecmp($sager_nubes, 'Rain') == 0) { $sager_nubes = 5; } ?> <html> <!-- standard header stuff goes here --> <!-- and don't forget to include the sager script --> <script src="sager_cast.js" type="text/javascript"></script> <body> <br /> Sager = <span id="forecast">forecast will appear here</span> <script type="text/javascript" language="javascript"> <!-- { //we could do some fancy escaping to directly insert the php variables //into the javascript function call, but this is harder to break. z_wind = "<?php echo $sager_wind?>"; z_rumbo = "<?php echo $sager_rumbo?>"; z_hpa = <?php echo $sager_hpa?>; z_trend = <?php echo $sager_trend?>; z_nubes = <?php echo $sager_nubes?>; document.getElementById('forecast').innerHTML = sager_cast( z_wind, z_rumbo, z_hpa, z_trend, z_nubes); } //--> </script> </body> </html> this basically turns my PHP variables intoa forecast by using the script above and also sager_cast.js (which crunches the numbers). my question is how can i record the output to a text file ie. this bit Quote: <br /> Sager = <span id="forecast">forecast will appear here</span> i know how to run a cron job on my host server but whenever i try to use php to geta at it, it fails. i understand that php and JS and side server / client server / host server different, but surely there must be a way to record the output using my host and the script that i have. my goal is to catch the forecast every 15 mins (with a time stamp) and then look back at the (text) file to see how it has changed. can anyone please help? one suggestion is to turn the number crunching JS script into php so i can 'get at it' but there are thousands of lines of code! thanks in advance, and hello from a newbie poster! Hello there, This seems to be a bit of a sore topic on the forums but at least I think I have good reason for wanting to do it - I've written a script that displays tooltips when your mouse hovers over a link - all this is fine, but when I click on the link and move to another page, then click the back button on the browser to go back, the tooltip for the link I clicked is still visible! It'd be great if there was a way of detecting the button had been pressed so that I can hide it... p.s. I tried onclick = "tooltips.hideToolTip(4); return true;" for the links but no joy... Many thanks Edd Is there a way to stop a form submit after hitting submit? Refresh wouldn't realy be an option. Is abort() what I'm looking for?
how do i make a html button stay down when pressed, until another button within a specified group of buttons is pressed, at which point it is released and the other button stays pressed?
Hi guys, would appreciate some help here. The below is part of the codes of my image matching programme. The programme loads 2 different series of images in the area and the up/down button is supposed to change each set of the series of images. Currently, the codes only allow one set of the images to be changed. Any idea what can be done so that both set get changes when the up/down key is pressed? Thanks! Codes: public void keyReleased(KeyEvent e) { zoom = false; repaint(); } public void keyPressed(KeyEvent e) { System.out.println("" + e.getKeyCode()); switch (e.getKeyCode()) { case 16: zoom = true; zoomPt = getMousePosition(); repaint(); break; case 39: loadImage(true, true); break; case 40: loadImage(false, true); break; case 38: loadImage(false, false); break; case 37: loadImage(true, false); break; } } public void changeDir(File dir) { this.dir = dir; } public void loadImage(boolean isFileA, boolean increase) { File[] fileList = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.toLowerCase().endsWith(".dcm") || name.toLowerCase().endsWith(".dc3") || name.toLowerCase().endsWith(".dic")) { return true; } else { return false; } } }); if (fileList.length < 2) { return; } try { if (isFileA) { a_os = increase? (a_os + 1) % fileList.length : (a_os - 1 + fileList.length) % fileList.length; } else { b_os = increase? (b_os + 1) % fileList.length: (b_os - 1 + fileList.length) % fileList.length; } String ext = fileList[a_os].getName().substring(fileList[a_os].getName().lastIndexOf(".") + 1); Iterator readers = ImageIO.getImageReadersByFormatName(ext); ImageReader reader = (ImageReader) readers.next(); reader.setInput(new FileImageInputStream(fileList[a_os]), true); imgA = ((DICOMImageReader) reader).read(0, null); ext = fileList[b_os].getName().substring(fileList[b_os].getName().lastIndexOf(".") + 1); readers = ImageIO.getImageReadersByFormatName(ext); reader = (ImageReader) readers.next(); reader.setInput(new FileImageInputStream(fileList[b_os]), true); imgB = ((DICOMImageReader) reader).read(0, null); w = Math.max(imgA.getWidth(), imgB.getWidth()); h = Math.max(imgA.getHeight(), imgB.getHeight()); } catch (Exception e) { String fileName; fileName = isFileA ? fileList[a_os].getPath() : fileList[b_os].getPath(); promptError(fileName + " could not be read"); e.printStackTrace(); System.exit(1); } dx = w / 2; dy = h / 2; } public void promptError(String msg) { JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.ERROR_MESSAGE); } public void keyTyped(KeyEvent e) { } Hello all I created a form which has a lot of textboxes, checkboxes and select-lists which are getting filled up by the records from a database table. I am basically creating an edit screen for a record. No I want to check all these input elements using javascript validation. I want this to performed when a button "Archive" is pressed. My problem is this "Archive button" needs to be a submit button. This does run the javascript validation but after completing the validation it submits the form. I want that submission should be stopped when the validation is violated. how can I do this? What I want is a button which acts as a default button (triggers the onclick event when I press enter) but submits only if the form is valid. 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! hi guys. im new to javascript and i require some help on a task so hoping someone on here could help me and possibly push me in the right direction. so i have a website with content on specific pages i need some sort of JS soloution which will fetch an ID/Keyword out of the page content so when a button is clicked it finds the ID/keyword and directs the user to a specific form/page. is this possible and can any1 help? Cheers, Ant. Hi, I have a form with text boxes which I need to display values ie. <input type="text" name="image_ref" value="image1" /> This works no porblem until I enter the below javscript onto the page: <script type="text/javascript"> var level1 = document.getElementById('level1'); level1.style.display = 'none'; var level2 = document.getElementById('level2'); level2.style.display = 'none'; var all_levels = document.getElementById('all_levels'); all_levels.style.display = 'none'; </script> This code is to hide certain parts of the form until they are activated. the problem is when the parts of the form are activated and displayed, the values inthe text input boxes do not show. Any ideas why this is? many thanks in advance. 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. hi friends , i am on make a dynamic input field creation code , my problem is the entered text(value from "add proposition") is washing away , if i press new "add proposition" my java script is PHP Code: <script language="javascript" type="text/javascript"> function add() { k=document.getElementById("num").innerHTML k=parseInt(k); if(!k) {document.getElementById("num").innerHTML=1; k=1;} else{ document.getElementById("num").innerHTML=k+1; k++; } document.getElementById("cat").innerHTML+="<br />type propositon "+(k)+":<input type=\"text\" name=\"prop"+k+"\">is it answer? <input type=\"checkbox\" name=\"ans"+k+"\"> ignore this one:<input type=\"checkbox\" name=\"ign"+k+"\">" } </script> my html code is PHP Code: <form action="new.php" method="post"> <fieldset> <legend>Add Question & answer:</legend> question type:<br /> True or False:<input type="radio" name="radio" value="t"> Objective:<input type="radio" name="radio" value="o"> Other:<input type="radio" name="radio" value="o"> Quesion:<br /> <textarea name="desc" rows="6" cols="35" ></textarea> <br /> <a href="javascript:add()" ><b>add proposition</b></a> <div id="cat"></div> <div id="num" style="display:none;"></div> <br> <input type="submit" name="submit"> </fieldset> </form> how i solve this problem ? Currently I have several forms using the input text "field3". I want to know how I can require an HTML input text field to be required WITHOUT having to use the form name in the javascript and without modifying <body>,<form> or <input type="submit">. Also no HTML5 since not all browsers use it (life would be simple if they did since threres a required tag) So here is my form, for example Code: <form name = "test"> <input type="text" name="field1"> <input type="text" name="field2"> <input type="text" name="field3"> <input type="submit"> </form> In otherwords, I can only edit <input type="text" name="field3"> by putting code directly before, in, or after that input field. With this problem, how can I make it required? thank you hi folks, i needed a text input so the user that will register a product, will make sure to enter the cents, and not just the raw money, making it to be stored incorrectly on my database. for example, if i type "1" the output inside the text field will be automatically "0.01", so the user HAS to type the cents. thanks in advance I'm building a template editor and need some help changing some of the variables. Part 1. Only at DEALERNAME. Must present coupon at time of write-up. Cannot be combined with any other offer. 1 coupon per customer per transaction. Expires: 00/00/00.s I need to be able to fill out two fields to change DEALERNAME and 00/00/00. I found a way to do this but it required the output to be in a field. I need it the output to look no different than before. Part 2. I'm using this to change some text via radio button but I would like an option to select how many details are there is the first place. Say they only want 1 or 2 details and not 3. Head Code: <script language="javascript" type="text/javascript"> function detail1a(){ document.getElementById("detail1").innerHTML = "Up to 5 Quarts"; } function detail1b(){ document.getElementById("detail1").innerHTML = "Synthetic Oil Extra"; } function detail1c(){ document.getElementById("detail1").innerHTML = "Lube Chassis"; } function detail2a(){ document.getElementById("detail2").innerHTML = "Up to 5 Quarts"; } function detail2b(){ document.getElementById("detail2").innerHTML = "Synthetic Oil Extra"; } function detail2c(){ document.getElementById("detail2").innerHTML = "Lube Chassis"; } function detail3a(){ document.getElementById("detail3").innerHTML = "Up to 5 Quarts"; } function detail3b(){ document.getElementById("detail3").innerHTML = "Synthetic Oil Extra"; } function detail3c(){ document.getElementById("detail3").innerHTML = "Lube Chassis"; } </script> Body Code: <span style="font-weight: bold;">Offer Details</span><br /> <p style="margin: 8px 10px"> Detail 1<br /> <input type="radio" name="on/off" onclick="detail1a();" />Up to 5 quarts<br /> <input type="radio" name="on/off" onclick="detail1b();" />Synthetic Oil Extra<br /> <input type="radio" name="on/off" onclick="detail1c();" />Lube Chassis<br /> </p> <p style="margin: 8px 10px"> Detail 2<br /> <input type="radio" name="on/off" onclick="detail2a();" />Up to 5 quarts<br /> <input type="radio" name="on/off" onclick="detail2b();" />Synthetic Oil Extra<br /> <input type="radio" name="on/off" onclick="detail2c();" />Lube Chassis<br /> </p> <p style="margin: 8px 10px"> Detail 3<br /> <input type="radio" name="on/off" onclick="detail3a();" />Up to 5 quarts<br /> <input type="radio" name="on/off" onclick="detail3b();" />Synthetic Oil Extra<br /> <input type="radio" name="on/off" onclick="detail3c();" />Lube Chassis<br /> </p> Output Code: <ul> <li><span id="detail1">Detail 1</span></li> <li><span id="detail2">Detail 2</span></li> <li><span id="detail3">Detail 3</span></li> </ul> This is hopefully a simple fix and I hope someone can help me out, I'm pretty new at coding. I have a form on an html page and I want to make it so when a button is clicked, it adds one to the input to the right of it, and when a button to the right of the input is clicked, it will delete one to the left of that button. I don't want to resort to making a new function for each and every form, because there will be a lot. Here is the form and input parts: Code: <form name="calculate"> <input type="button" onClick="add()" /> <input name="result" type="input" readonly="readonly" value="0" /> <input type="button" onclick="sub()" /> </form> Here is what the function code looks like: Code: function add() { var add = 1 * calculate.name.value; add = add + 1; calculate.name.value = add; } function sub() { var add = 1 * calculate.name.value; add = add - 1; calculate.name.value = add; } Note: where I called the calculate.name.value, that obviously doesn't work, and I need some way, rather than making multiple functions and changing the name part, to be able to call to a name near the button, if at all possible. Any and all ideas are appreciated, Thanks! Newbie here. I could not find the syntax how to set initial value he Code: var indat = window.clipboardData.getData ("Text"); . . . . . <input type="text" name="q" value="xxxxxx" size="40" /> I would like the value to be the indat var value I saw lot of samples with value="xxxxx" (hard coded value) but could not find sample for var value thanks for help !! Hello there, I am having trouble with a javascript snippet that adds text to a textarea when you click on the link. Problem is that when you regularly type into the textarea, the links no longer add text. Here is the links: Code: <a href="javascript:insertText('<b></b> ','textIns');" onClick="void(0)">Bold</a> Here is the javascript Code: <script type="text/javascript"> function insertText(val,e) { document.getElementById(e).innerHTML+=val; } </script> Any ideas or suggestions? |