JavaScript - Deactivate $(document).keydown(function(e) When Textarea Is Selected?
Hi, i have this jquery script on my photo galery page, it detects left and right key down on keyboard and acts uppon key down.
Is there any way to deactivate it when I click on a text area that is located below each photo? this must be a common issue I think... Textareas id="comment_" Code: <script type="text/javascript"> $(document).keydown(function(e){ if (e.keyCode == 37) { window.location = "photo.php?phot=$prev_file_p&p_id=$prev_file" return false; } else if (e.keyCode == 39) { window.location = "photo.php?phot=$next_file_n&p_id=$next_file" return false; }}); </script> Similar TutorialsHow can I get the selected text of a textarea with JavaScript? example: Code: <form name="reportForm"> <textarea name="report"></textarea> <br /> <input type="button" onClick="GetSelectedText();" /> </form> Thanks IC I searched about this problem over Internet and found the same result many times, I found this example on stack overflow but this example didn't work in my project; I am making a toolbar with buttons that insert HTML tags around the selected text in a <textarea>, this exemple didn't work because when the user click on a button the selected text won't be selected anymore because <textarea> loses focus and selected text will be unselected, I am targeting Firefox and compatible browsers so you don't need to give me the IE code; jQuery codes are accepted; so, have you any idea?
This seems like it should be easy but I can't figure it out. I am trying to set up a drop down list to interpret an abbreviation and to also hyper link to a site about the object. I want it to stay in the <textarea> and not write a new document but it is the only way I have been able to get a hyperlink. Any suggestions would be appreciated. Here is my HTML and JS HTML: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>ACRONYMS</title> <script type= "text/javascript" src="abbs2.js"> </script> <style type="text/css" media="Screen"> fieldset { border: 5px solid #555555; padding: 20px; width:350px; word-wrap: normal; } </style> </head> <body> <fieldset style="width:410px; height: 250px;"> <h2>DESCRIPTION BY ABBV</h2> <form name = "listNAME"> <select name="abbWRD"> <option value=AIR>AIR</option> <option value=CCVT>CCVT</option> </select> </form><br> <input value="Click for Description" onclick="findMEAN()" type="button"> </br></br> <textarea id="resultbox" style="width:400px; height:75px;"></textarea> </fieldset><br> </body> </html> And JS: Code: /** * @author zero3ree */ function findMEAN(){ var abb = document.listNAME.abbWRD.value; if (abb == "AIR"){ abbs = ("AIR Commercial Real Estate") ; abbslnk = document.write("" + abbs.link("http://www.airea.com") + "");} else if (abb == "CCVT"){ abbs = ("COUPLING CAPACITOR VOLTAGE TRANSFORMER") ; abbslnk = document.write("" + abbs.link("http://www.abb.com/product/db0003db002618/c12573e7003302adc1256ffd001d1256.aspx") + "");} { var result=document.getElementById("resultbox"); result.value = abbslnk } } Thanks in advance. function Button1_onclick() { var v = 'parser2.php?data='+document.getElementById('message').value; ShowWebSite(v); } This is my code. I want to retain the \n in end of each line so that PHP can handle the input more well. But document.getElementById removes the \n. Is their any way to prevent this? A third-party script i have no control over is interfering with my script's arrow key functions, so i wanted to find a way to nullify that script's use of the keys. After blindly punching my keyboard, I came up with this: Code: <script> function killArrows(e){ if({ 37:1, 38:1, 39:1, 40:1 }[e.which||e.keyCode]) window.event.keyCode = 0; } </script> <textarea onkeydown="killArrows(event)"></textarea> It works great in IE (I'm still even able to use the arrow keys in the textarea without triggering the external script's arrow functions - though I'm not sure why), but doesn't work in Firefox. Any idea why? Does FF not recognize the keyCode property? Thanks for any help. ~gyz I want to open a new tab "http://www.example.com/" when the user presses a key. How can this be done?
Hello all. I have fairly simple questions regarding modifying this script: http://papermashup.com/create-a-dynamic-form-preview/ to dynamically show different parts of a form on another part of the page. I am looking to use it on most parts of my form and would like a little clarification. First is the use of $(document).ready(function() or $(function(). It works using either, my question is which is preferred? As I understand it using $(document).ready(function() starts the DOM immediately on page load and is useful if you need something right away. I am also using this script: http://www.dynamicdrive.com/dynamici...formwizard.htm for the form. Since the preview script is being used with the form to wizard, I don't really need it until the rest of the form loads. Another question would be, is there a cleaner way to go about using the preview script on say 10 different form inputs independently? For example in a single function rather than 10 different function/updates? I have an example of what I am trying he http://jsfiddle.net/anhyG/1/ Thank you in advance for any help! Hi, On a registration form I have 4 fields that are all dropdown select fields. NAME, CLASS-1, CLASS-2, CODE 1) I would like to activate the CLASS-1, CLASS-2, CODE fields only if the NAME IS Selected from the dropdown. 2) Also would like to make the CLASS-1, CLASS-2 as required fields if the NAME is selected from the dropdown. How can I achieve this? Can I use some kind of a server event to activate / deactivate the fields on the form? Please advice Thanks Vinny Hi, I have requirement to move focus to previous button when onkeydown event occurs on tabout from current button. Below is snippet of code. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script language="Javascript"> function button3(event) { var keydown = event.keyCode; alert(keydown); if(keydown == 9){ document.all.b2.focus(); return false; } } </script> </head> <body> <FORM NAME="form1"> <INPUT id="b1" TYPE="BUTTON" name= "b1" VALUE="Button 1"> <INPUT id="b2" TYPE="BUTTON" name= "b2" VALUE="Button 2"> <INPUT id="b3" TYPE="BUTTON" name= "b3" VALUE="Button 3" onkeydown="button3(event)"> <INPUT id="b4" TYPE="BUTTON" name= "b4" VALUE="Button 4"> </FORM> </body> </html> when the focus is on b3 and if i give tabout then focus should go to b2. But its not working. Can you plz help Siva Hi, I am just a noob and this is my first go at javascript and html I am trying to figure out how to display info from an array in the <textarea>, I have tried a number of things nothings worked and I know it must be something simply but have tried a number of things I also have to clear the <textarea> after it displays the info mentioned above and I think I have that sorted but I also have to have the <textarea> display all signup info stored in the array when a user clicks on a button Here's the code Code: function show() { var myArray = new Array(); myArray[0] = document.getElementById('fullname').value; myArray[1] = document.getElementById('Address').value; myArray[2] = document.getElementById('Phone').value; document.writeln('Thank you for signingup,' + ' ' + myArray[0] + '. Your details will be confirmed by E-mail to ' + myArray[2] ); document.writeln("<br>") document.writeln('Details:') document.writeln("<br>") for (var i=0; i<myArray.length; i++) {document.write(myArray[i] + "<br />"); } } Thanks Hi All, I have a problem in which I try to execute a funcition via a document.write() and it throws an "object expected" error. Overall I am making an interface for MS ACCESS .mdb table via ADODB using JavaScript and I want to be able to click on a link and the id is used to delete that entry. Code: My function is: Code: function deleteRecord(del) { var adoConn = new ActiveXObject("ADODB.Connection"); var adoRS = new ActiveXObject("ADODB.Recordset"); adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = {path to }knowBA.mdb'"); adoRS.Open("Select * From know where ID="+ del, adoConn, 1, 3); adoRS.Delete; adoRS.Close(); adoConn.Close(); } The code using the funcition is - oh and the numric KEY is rs(0) : Code: if(!rs.bof) { document.write("<table width='700' border='1' align='center' cellpadding='2' cellspacing='0' bgcolor='#FFFFFF'>"); rs.MoveFirst() while(!rs.eof) { document.write("<tr><td><div align='center'><strong>"+rs(1)+"</strong></div>"); document.write("<strong>Keyword(s):</strong> "+rs(3)); document.write("<br><strong>Entry:</strong> " +rs(2)+" "); document.write("<A HREF='javascript:onClick=("+"eval(deleteRecord(" +rs(0)+"))"+")'>delete</A> "); document.write("</td></tr>"); cnt=cnt+1; rs.MoveNext() } document.write("</table></form>"); } if (cnt==0){ alert ("Sorry, there are no results on that search.");} rs.close() cn.Close(); } </script> Thanks for any hints on how to accomplish this! Hello codingforums! I'm new to javascript and have a problem regarding functions. I've been trying to create a slideshow, and while testing different syntax etc. I'm getting stuck at why this works: Code: document.images.portrait.src = img2.src; And not this: Code: function slideshow(){ document.images.portrait.src = img2.src; } Thanks for any help! Hello Pros. I am having a problem with getting id of the active element which calls function savePanelPosition(), as a result, I cannot get a new location of this element and pass it to my Page Method SaveCoords() All draggable panels are created dynamically in code-behind. Please, see the javascript code below. Any ideas/help are greatly appreciated function pageLoad() { var Max = "<%=qtyMax%>"; for (i = 0; i < Max; i++) { $find('DragP' + i).add_move(savePanelPosition); } } function savePanelPosition() { var elem = document.activeElement; var loc = $common.getLocation(elem); PageMethods.SaveCoords(elem, loc.x, loc.y); /* there is a call to PageMethods.SaveCoords(), but elem = objectHTMLBodyElement, loc.x=0, loc.y =0 */ } Hi Coders, I have a javascript function which lets a user to choose one of the 7 option buttons on a "mainsub.asp" page and the page will then be forwarded to one of the 7 process pages depending on what has been chosen. The problem is that firefox is angry with the first line ("if" statement) and tells the following in its error console: Error: document.forms[0].C1 is not a function Source File: [localhost...] Line: 117 Here is the code: function fSubmit(){ if (document.forms[0].C1(0).checked) document.forms[0].action="process.asp"; else if (document.forms[0].C1(1).checked) document.forms[0].action="process1.asp"; else if (document.forms[0].C1(2).checked) document.forms[0].action="process2.asp"; else if (document.forms[0].C1(3).checked) document.forms[0].action="process3.asp"; else if (document.forms[0].C1(4).checked) document.forms[0].action="process4.asp"; else if (document.forms[0].C1(5).checked) document.forms[0].action="process5.asp"; else if (document.forms[0].C1(6).checked) document.forms[0].action="process6.asp"; else document.forms[0].action="process.asp"; return; } Internet explorer does not complain about anything and does its job great. But I could not figure out how to change the code to be also compliant with Firefox? Thanks for all the comments. How to: pass local variable from <head> JS function to <body> textarea I have a JS function in the head that calculates a variable. the function is triggered by the vevent of a button click. when calculation is done, how is it sent back to the page and placed in a textarea or textbox....?? /Beginner issues :/ Hi, New to JS. Have ordered some new books, but need to get somethings going in the mean time. What I wanted to do is to link to a new page having a date range input in the form of 6 text boxes, 2 sets of mm-dd-yy, from and to, where the upon loading the page box 1 of the from would auto focus and then auto tab and then post where php could take over on the server side. Setting up the form and the lay out, no problem. Auto focusing went just like expected using the following code, included because on the next step everything fell apart. [/CODE] <script type="text/javascript" > window.onload=function() { document.getElementById("input1").focus(); } </script> [/CODE] So then the wheels came off and in response, began to simplify what was trying to be done to find where the issues were. As far as I can get working is: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" > window.onload=function() { document.getElementById("input1").focus(); } </script> <script type="text/javascript" > function myFunc() { alert("is this working"); } </script> </head> <body> <input id="input1" name="input1" type="text" onkeyup="myFunc()" maxlength="2" value="type a No." /> </body> </html> First issue with this: When I first get to the page everything is just as ordered. The focus is on the text box and the default value is "type a No." When I press a key onkeyup, I bring up the alert box with "is this working" in it. But when I refresh the page with the refresh button, after clicking the "ok" on the alert box, the character that was typed in is still displayed. If I use the link to the page, or the URL from the address bar, then the page reloads properly with the default value, "type a No". Question 1: How do you get the default textbox value using the refresh button as apposed to reloading the page using a link or from the address bar? Using Firefox 8.0 Second and more important at the moment: If I change the script to pass an argument to the function the script crashes. It does not pull up an alert box and freezes. My guess is that I'm doing something wrong on a concept level. NOTE: changed the default value of the text box to " ". Looked like to me there was an issue with the size specification and the default string length as you could only enter in a key stroke by highlighting the text and replacing it Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" > window.onload=function() { document.getElementById("input1").focus(); } </script> <script type="text/javascript" > function myFunc(awe) { alert(awe); } </script> </head> <body> <input id="input1" name="input1" type="text" onkeyup="myFunc("123")" maxlength="2" value="" /> </body> </html> Question 2: can someone straighten me out with this? like for example i have text areas named upload1 and upload2 when I click or add input on upload1 a drop down list below upload2 will not change, but when I add input on upload2 the dropdown will select "parts" ok so Code: document.write("Goodbye!"); works but I put ^ that inside a function Code: function SayHello () ( document.write("Goodbye!"); ) and it stops working? I know the function call works because when I place some code to display an image in SayHello function, it displays the image. Quote: <html> <head> <script type="text/javascript"> var a = january var b = febuary var c = march function test() { document.getElementById("test").innerHTML=a; <!-- needs to be A on first function click, b on second, c on third, etc..^^--> } </script> </head> <body> <p id="test"></p> <!-- the <p> should go to next month upon each function --> <input type="button" value="asdf" onclick="test()" /> </body> </html> I tried to explain it pretty well in the comment tags, thanks! My code is here and it works ... However, I would like my dynamic table to show on the same page as my body and not on a new blank page. I have created a DIV and try playing around with the document.getElementById('monTab').innerHTML but it's not working out for me ... What am i missing ? Regards, Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>new Script - Javascript Cours 11</TITLE> <META content="text/html"; charset="UTF-8" http-equiv="content-type"> <SCRIPT type="text/javascript"> function createTable(){ var Etudiant = new Array(Number(prompt("How many Students will you put in ?",""))); document.write("<table border=\"1\">"); for (var i=0; i<Etudiant.length; i++) { Etudiant[i] = window.prompt("S'il vous plait entrez le nom d'un etudiant " + (i+1) + ".","") alert("Nice to see you "+Etudiant[i]); document.write("<td>"+Etudiant[i]+"</td>"); j = parseInt(prompt("Combien de notes voulez vous calculez ?")); for (h=0;h<j;h++){ notes[h] = parseInt(prompt("S'il vous plait entrez la "+(h+1)+" note de "+Etudiant[i])); document.write("<td>"+notes[h]+"</td>"); } document.write("<tr>"); } document.write("</tr>"); document.write("</table>"); document.getElementById('monTab').innerHTML=Etudiant; } </script> <BODY> <H1>Combien de note voulez vous cumulez ?</H1> <br> <br> <input type="button" name="btnSubmit" value="TRY IT" onclick="createTable()"> <div id="monTab" size="10"> Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ...Content should come here ... </div> </BODY> </HTML> |