JavaScript - How To Determine If Someone Clicks Outside Of A Textbox
Hi,
I have a click event that changes an element from a span that acts like a text link, to a textbox that the user types in: Code: Event.add(area_el_rename, 'click', function(e) { if(!currently_renaming) { area_el.innerHTML = '<textarea name=\"renaming_area\" id=\"renaming_area\" style=\"width:100px;height:10px;background-color:#DCDCDC; resize:none;font-size:8px;\"></textarea><br>'; currently_renaming=true; } }); I am wondering if there is any way to determine if the user has clicked outside the textbox, and if so, perform an action (in my case revert back to the <span>. The solution probably doesn't need to be tied to anything. It probably just has to be something like: if(click_outside_id("renaming_area")) { //do my desired action } Similar TutorialsHi.. 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, See I have called a function in onchange event of a dropdownlist.What happens in the onchange function is that if the value for dropdown has already been entered once, then an alert message will be shown. The problem I have is, if the value has been already entered, when I try to change the value in dropdown, dropdownlist gets displayed (expands) and an alert message gets displayed. When I click "OK" of alertbox first the dropdown gets back to it original form and only on the next click alert box goes. What I need is everything should happen in a single click itself. is there js to prevent malicious clickers who try to ban my site from google ads by clicking so many times?
Is there anything wrong with the code below? - it doesnt seem to track the links, (which it suppose to do inside img.php) Code: // IMAGERY SYSTEM function Imagery(img) { ajax = ajaxFunction(); var url = base_url+"application/imagery/img.php?img="+img; ajax.open("GET",url,true); ajax.send(null); } Link Code: <a href="http://google.com" onClick="Imagery('545');"> Hi! Sorry for asking such noobish questions, I tried to search but couldnt find anything addressing my problem. It's probably pretty simple though. I have an image on a website. I want the image to change, after the user has clicked on it five times. In other words, on the first 4 clicks, nothing should happen. But the fifth click should change the source of the image. Here is my feeble attempt: Code: function image_changer(){ var i=0; for (i=0;i<=5;i++) { document.getElementById('changingimage001').src = 'images/smile6.jpg'; } } HTML: Code: <img id="changingimage001" src="images/base.jpg" onclick="image_changer();" alt="a changing image" />' I quess my main confusion is this: How do I make a new iteration in my for loop happen only when the mouse is clicked (instead of all the iterations running trough as fast as possible)? I have 16 links on a page, when each link is clicked, I need to change text that is on the page. This is Page 1 link 1 This Is Page 1 link 2 This is Page 2 ... link 16 This is Page 16 How can I do this? Excuse my ignorance, this is my first JS project Hello I want to add something to my web site. when the user clicks to download. i want to see a pop up screen which says your download has started. <script type="text/javascript"> function show_alert() { alert("Your Download Started!"); } </script> <input type="button" onclick="show_alert()" onclick="get value="Download" /> I dont get where should i put the download link I'm using "Coda-Slider 2.0" for a tab-based interface. I used external triggers to switch between tabs, and I'm having trouble adding my "selected" class when I click on one of the triggers. It works...BUT...it takes two clicks for it to respond correctly. The slider works just fine, but the "selected" class isn't added (i.e. the selected tab gets a different background image) until I click on one of the menu items twice. Here is the JavaScript I used: Code: $("a").click(function(){ $(".menu a.selected").removeClass("selected"); // remove previous class if there is any $(this).addClass("selected"); // add class to the clicked link return false; // prevents browser from following clicked link }); And here is the HTML. The "xtrig" class is required for it to be used as an external trigger for the slider. Code: <ul class="menu"> <li class="day1"><a class="selected xtrig" href="#1" rel="coda-slider-1">Day 1</a></li> <li class="day2"><a class="xtrig" href="#2" rel="coda-slider-1">Day 2</a></li> <li class="day3"><a class="xtrig" href="#3" rel="coda-slider-1">Day 3</a></li> <li class="day4"><a class="xtrig" href="#4" rel="coda-slider-1">Day 4</a></li> </ul> Any ideas why it would take two clicks for it to function? Thanks! Hello! I do my calendar (vertical) =) and I've done to date were down But how to do that day of the week displayed on the side of the date of Here is code: Code: <html><head><title>Calendar</title> <meta http-equiv="content-type" content="text/html; charset=windows-1251" /> </head> <body><center> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin monthnames = new Array("January","Febrary","March","April","May","June","July","August","September","October","November","December"); var linkcount=0; function addlink(month, day, href) { var entry = new Array(3); entry[0] = month; entry[1] = day; entry[2] = href; this[linkcount++] = entry; } Array.prototype.addlink = addlink; linkdays = new Array(); monthdays = new Array(12); monthdays[0]=31; monthdays[1]=28; monthdays[2]=31; monthdays[3]=30; monthdays[4]=31; monthdays[5]=30; monthdays[6]=31; monthdays[7]=31; monthdays[8]=30; monthdays[9]=31; monthdays[10]=30; monthdays[11]=31; todayDate=new Date(); thisday=todayDate.getDay(); thismonth=todayDate.getMonth(); thisdate=todayDate.getDate(); thisyear=todayDate.getYear(); thisyear = thisyear % 100; thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear)); if (((thisyear % 4 == 0) && !(thisyear % 100 == 0)) ||(thisyear % 400 == 0)) monthdays[1]++; startspaces=thisdate; while (startspaces > 7) startspaces-=7; startspaces = thisday - startspaces + 1; if (startspaces < 0) startspaces+=7; document.write for (s=0;s<startspaces;s++) { document.write(); } count=1; while (count <= monthdays[thismonth]) { for (b = startspaces;b<7;b++) { linktrue=false; /////displays the date document.write("<br width='30'>"); if (count <= 31) { document.write(monthnames[thismonth]); document.write(" "); } for (c=0;c<linkdays.length;c++) { if (linkdays[c] != null) { if ((linkdays[c][0]==thismonth + 1) && (linkdays[c][1]==count)) { document.write("<a href=\"" + linkdays[c][2] + "\">"); linktrue=true; } } } if (count==thisdate) { document.write("<font color='FF0000'><strong>"); } if (count <= monthdays[thismonth]) { document.write(count); } else { document.write(" "); } if (count==thisdate) { document.write("</strong></font>"); } if (linktrue) document.write("</a>"); document.write; count++; } document.write; document.write("<tr>"); startspaces=0; } document.write("</p>"); // End --> </SCRIPT> </center></body> </html> Referring to following link, I would like to determine the link for "In-Depth.xls", based on following coding, I find related information for Excel.png, does anyone have any suggestions on how to determine the URL for Excel file? Thanks in advance for any suggestions http://fx.aastocks.com/en/forex/mark...0&indicator=47 <img src="../../images/common/Excel.png" id="cp_imgExcel" class="btn" onclick="window.location.href='dbindepth.aspx?country=66970&startdate=2010/12/24&enddate=2011/12/24&indicator=47&excel=1'"/> THIS IS NOT HOMEWORK Hi all, See this image: The image represents an "entire" web page and the bright part the area currently scrolled into by the web browser. I can get the client's screen SIZE, but I don't know how to figure how many pixels down into a page the browser happens to be. To clarify, the distance shown as a question mark would be "zero" if the browser were scrolled all the way to the top of the page and some positive number as the browser scrolls down. Is there any way for me to get this number (in Javascript). What I need it for is to position a pop-up window centered left-to-right and 1/3-2/3 top to bottom on the screen REGARDLESS of where in the page the browser is scrolled. Thanks..... -- Roger HI all. How do I determine whether a variable exists in a form. I have a form called "theForm". I want to determine whether the variable "THIRD_PARTY" exists in the form and if it has been set. Tracy i'm working with a javascript on a drupal website, but the saving function seems to work only as soon as i click 2 times on the "save" button. the code that fires the function is: Code: var param ="&usuario="+usuario+"&nivel="+nivel+gano+porc_gano+gasto+porc_gasto+tengo+porc_tengo+debo+porc_debo+plazo_debo; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = direccion_servidor +"setMisDatos?callback=respuestaGuardarMisDatos¶m="+encodeURIComponent(param); h = document.getElementsByTagName("script")[0]; h.parentNode.insertBefore(s, h); i got the parentNode.insertBefore code from google (the same they use in google analitycs), but still i get error (specifically when he has to do the parentNode.insertBefore part (earlier it was only appendChild, but used to give me the same kind of error. Are the spaces a problem in this sense? Or there might be a better solution? because if i click the second time it enters the setMisDatos function and then works 100%. This is really driving me crazy, can anybody help me? Hi Everyone, I want to execute a script when the user clicks the button. Currently in my html doc. i have the button declared. <input type="button" id ="button" onclick='notEmpty() value="Play"/> When the button is clicked, i execute the notEmpty() function and I want to execute a script inside the notEmpty(). How can i do this? Thanks, Praveen I want to send a simple email with just email & subject only when the user clicks a link that opens a pdf. I'm thinking javascript is the best way to do this but I have no idea how. I have googled it a bunch but most information is about getting an email when someone clicks a link you send in an email. I don't want that. This is on a website. I'm not sure if php would be better to use. Any help would be most appreciated!
Okay, so I built up 2 codes, which do the same cause. but which one would be most efficient? or maybe which one would be best compatible for browsers? CODE 1 : - this code allows for me to use an #id Code: <a onclick="trackClick('1');" href="http://www.google.com" rel="nofollow" target="_new">(track 1)</a> function trackClick(trackid) { ajax = ajaxFunction(); var url = base_url+ "app_trackClicks.php"; url = url+ "?trackid=" +trackid; ajax.open("GET",url,true); ajax.send(null); } CODE 2 - using the REL Code: <a rel="randomclicks" href="http://www.google.com" rel="nofollow" target="_new">(track 2)</a> function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function'){ window.onload = func; } else { window.onload = function(){ oldonload(); func(); } } } addLoadEvent(randomclicks); function randomclicks() { if (!document.getElementsByTagName){ return; } var anchors = document.getElementsByTagName("a"); // loop through all anchor tags for (var i=0; i<anchors.length; i++){ var anchor = anchors[i]; if ((anchor.getAttribute("rel") == "randomclicks")){ anchor.onclick = function () { ajax = ajaxFunction(); var url = base_url+ "app_trackClicks.php"; url = url+ "?randomclicks"; ajax.open("GET",url,true); ajax.send(null); }; } } } Thanks Hi everyone, Is it possible to determine at the startup of the page if the visitor is using a computer or a phone to access the site? I would like to make the intro process much better than a simple "click here for HTML version or click here for Flash version". I would like for it to simply redirect to the page I set it to go to depending on whether or not they're using a regular browser or a mobile browser. How would I go about this? Thank you all very much in advance. I have an array of all links on a page (see var wa_links = document.links; below). How do I determine if the target of a link is set to "_blank"? I need to do this because currently with my code below, when a link has target="_blank" it ends up adding the Google Analytics code to the parent window and also opening a new window (so basically the new page opens in both the parent and target window instead of just the target window as expected). Code: /*Regex list of on-site domains, pipe and backslash delimited. */ var wa_onsiteDomains = /mydomain\.com|my2nddomain\.com|my3rddomain\.com|javascript/i; //Display-friendly domain and path name var wa_displayDomain = location.hostname.replace("www.","").toLowerCase(); var wa_displayPathname = location.pathname.toLowerCase(); /*Used to unobtrusivly add events to objects*/ function unobtrusiveAddEvent (element,event,fn) { var old = (element[event]) ? element[event] : function () {}; element[event] = function () {fn(); old();}; } function wa_crossDomainLink(i) { return function () { var thisLink = decodeURI(wa_links[i]); if (typeof(_gaq) == "object") _gaq.push(['_link', thisLink]); return false; }; } var wa_links = document.links; if ( wa_links ){ for(var i=0; i<wa_links.length; i++) { if( wa_links[i].href.match(wa_onsiteDomains) && !wa_links[i].href.match(location.hostname)){ unobtrusiveAddEvent( wa_links[i], 'onclick' , wa_crossDomainLink(i)); } } } With jquery I could just do something like... Code: if (jQuery(link).attr('target') == "_blank") ...but how do I do this in plain old JavaScript? Thanks! greetings, I'm unable to find solution for dreamweaver reporting syntax error with the following page: http://www.redskyjewelry.com/test_product_detail.html I am revamping my website so the css is not set up for this page but that's okay. I have put in the various javascripts based on the product so the page is similar to a template. The syntax error is for the second set of boxes, the bracelet length options, and specifically for line with: form.amount.value = 6.5 inches; from the following script-- <SCRIPT language=javascript> function BraceletLength(form) { if (form.os0.value == "6.5 inches") { form.amount.value = 6.5 inches; form.item_number.value = "6.5 inches"; } if (form.os0.value == "7 inches") { form.amount.value = 7 inches; form.item_number.value = "7 inches"; } if (form.os0.value == "7.5 inches") { form.amount.value = 7.5 inches; form.item_number.value = "7.5 inches"; } if (form.os0.value == "8 inches") { form.amount.value = 8 inches; form.item_number.value = "8 inches"; } } </SCRIPT> I hope I have included enough information and I thank any input into this glitch I am having. I'll check back tomorrow, and thank you. judith |