JavaScript - Highlight Row Color When Field Updated?
I have some table rows with an item, item description and a text field named "qty" for the quantity. If a user types a number above 0 in the "qty" field, I would like it to highlight the table row. If a user gos back and deletes the number already in the text field I would like the table row to return to it's default state. How can I do this?
Similar TutorialsI'm trying to highlight the row color when the input field is changed but get an error. Can someone please help. TRACY Code: <script type="text/javascript"> function toggle(trid){ var edited_row_bgcolor = '#FAEBD7'; var elm = document.getElementById(trid); document.elm.style.background = edited_row_bgcolor; } </script> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr id="Child1"> <td width="50%"> <input onchange="toggle('Child1');" type="text" name="T1" size="20"> </td> <td width="50%"></td> </tr> <tr> <td width="50%"><input type="text" name="T1" size="20"></td> <td width="50%"></td> </tr> <tr> <td width="50%"><input type="text" name="T1" size="20"></td> <td width="50%"></td> </tr> <tr> <td width="50%"><input type="text" name="T1" size="20"></td> <td width="50%"></td> </tr> <tr> <td width="50%"><input type="text" name="T1" size="20"></td> <td width="50%"></td> </tr> </table> Hi guys, Hopefully a really quick question. I'm a JS novice, and am looking for a way to output the coordinates of a Google maps marker into the value of two text fields, one for latitude and one for longitude. The code below is a simple location search which returns a result with a draggable marker. Currently, the coordinates in both text fields update when the location search is performed, but not when the marker is dragged to a new location afterwards. Does anyone know the code to simply update the coordinates each time the marker is dropped on a new location? Code: <html> <head> <style type="text/css"> #map_canvas { width:444px; height:444px; overflow:hidden; } </style> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAA-Kl-tQOj5PlnOlXQmp2N9hTg6Fn61x9hOlvMvn6kV4ENK8yRfBShRuj-nulocuk2Alx9JmFKKV4zwA" type="text/javascript"></script> <script type="text/javascript"> var map; var geocoder; function initialize() { map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(52.8068752, -1.6430344),6); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.enableScrollWheelZoom(); geocoder = new GClientGeocoder(); // Update current position info } // addAddressToMap() is called when the geocoder returns an // answer. It adds a marker to the map with an open info window // showing the nicely formatted version of the address and the country code. function addAddressToMap(response) { map.clearOverlays(); if (!response || response.Status.code != 200) { alert("Whoops, we couldn't find that address!"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); marker = new GMarker(point,{draggable:true}); map.addOverlay(marker); marker.openInfoWindowHtml(place.address + '<br /><span class="smallgrey">Zoom in and drag the marker to exactly where the point is</span>'); document.getElementById("latitude").value = point.lat(); document.getElementById("longitude").value = point.lng(); } } // showLocation() is called when you click on the Search button // in the form. It geocodes the address entered into the form // and adds a marker to the map at that location. function showLocation() { var address = document.forms[0].q.value; geocoder.getLocations(address, addAddressToMap); } // findLocation() is used to enter the sample addresses into the form. function findLocation(address) { document.forms[0].q.value = address; showLocation(); } </script> </head> <body onload="initialize()"> <form action="#" onsubmit="showLocation(); return false;"><input type="text" name="q" size="35" /> <input type="submit" name="find" value="Search"/></form> <div id="map_canvas">And pin the <strike>tail</strike> marker on the <strike>donkey</strike> map:<br /></div> Latitude: <input class="required" type="text" name="latitude" id="latitude" value="53.34870686020199" /> <br /> Longitude: <input class="required" type="text" name="longitude" id="longitude" value="-6.267356872558594" /> </body> </html> Many thanks in advance, I appreciate anyone who wants to help out! Hi, As you will see with the code below when the text ONE and TWO are clicked on it displays a background color. When ONE is activated TWO is off. When TWO is activated ONE is off. But when the page loads I want ONE to display the background color. When ONE displays the background color after the page has loaded, I want to click on TWO to display it's background color and ONE should turn off as it does now. I can't figure out how to activate the background color for ONE when the page loads. Then if it is activated when the page loads, how to turn off ONE and turn on TWO when clicked on and visa versa. Code: <!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>Untitled Document</title> <script language="javascript" type="text/javascript"> var btn = function () { var active = null, bcolor = '#84DFC1'; if (this.attachEvent) this.attachEvent('onunload', function () { active = null; }); return function (element) { if ((active != element) && element.style) { if (active) active.style.backgroundColor = ''; element.style.backgroundColor = bcolor; active = element; } }; }(); </script> </head> <body> <div onclick="btn(this);">ONE </div> <div onclick="btn(this);">TWO </div> </body> </html> I have created a journey planner from www.transportdirect.com (it automatically creates the code, so you just copy and paste it into your websites HTML code). But it doesn't automatically update the date parts of the form, to match the current date. This is the code for the date part of the form: <td> <p style="font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; text-align: left; margin: 5px 5px 5px 5px;"> <select id="dtd" name="dtd" style="border-right: lightgrey 1px solid; border-top: lightgrey 1px solid; font-size: 12px; border-left: lightgrey 1px solid; border-bottom: lightgrey 1px solid; font-family: verdana, arial, helvetica, sans-serif; background-color: white; height: 18px;"> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> <option value="05">05</option> <option value="06">06</option> <option value="07">07</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <!-- !IMPORTANT! Month/year dropdown values will need to be maintained over time. Only the current month and the following two months should be selectable because complete public transport data is only available for journeys up to three months in the future. Client-side script should be added to default the dropdown values to the current date and time. --> <select id="dtm" name="dtm" style="border-right: lightgrey 1px solid; border-top: lightgrey 1px solid; font-size: 12px; border-left: lightgrey 1px solid; border-bottom: lightgrey 1px solid; font-family: verdana, arial, helvetica, sans-serif; background-color: white; height: 18px;"> <option selected="selected" value="032012">Mar 2012</option><option value="042012">Apr 2012</option><option value="052012">May 2012</option> </select></p> </td> What I want to do is add a javascript code to automatically keep the dates updated? If you need any further details, please ask. Thank you for any help. Hi, I'm having a bit of trouble with this here... Before I submit the form with JS I update an input field with js like this: Code: Code: document.getElementById('IC_Checksum').value = data; imaginaryform.submit(); The problem is that the updated value is not sent along with the post data. Instead the old value is sent along. When i submit the form with a button afterwards though (not auto submit after the value is set), then the value is sent along fine. But that's not how I want it to work... Can anyone tell me how I can send the value that I'm setting with JS along with the post data like this? Ok, i have a javascript that creates a table then appends it to an empty div. This works fine in FF, however it fails to work in IE8. [edit] I have decided to post the entire code since I wasn't having any luck getting any suggestions. Maybe now someone can help me out. Code: function createTable() { var machine = document.Catalog.machine.value; var dSearch = document.Catalog.dSearch.value; var section = document.Catalog.section.value; var x = xmlDoc.getElementsByTagName('record'); var y = xmlDoc.getElementsByTagName('data'); var newEl = document.createElement('TABLE'); newEl.className = 'resultsTab'; var tmp = document.createElement('TBODY'); newEl.appendChild(tmp); var row = document.createElement('TR'); var n = 1; var headings = new Array("Col1", "Col2", "Col3", "Col4", "Col5"); var dcount = 0; //for (t=0;t<10;t++) { for (t=0;t<y[0].childNodes.length;t++) { if (y[0].childNodes[t].tagName == "record") { // it is required for FF to work properly dcount++; } } if (document.Catalog.thumbImg[0].checked) { var container = document.createElement('TH'); var theData = document.createTextNode("Pic"); container.className = "topline1"; container.appendChild(theData); row.appendChild(container); } for (h=0;h<headings.length;h++) { var container = document.createElement('TH'); var theData = document.createTextNode(headings[h]); container.className = 'topline' + n; container.appendChild(theData); row.appendChild(container); n++; } tmp.appendChild(row); switch (searchtype) { case 1: var objRegex = new RegExp(machine); break; case 2: var objRegex = new RegExp(section, "i"); break; case 3: var objRegex = new RegExp(dSearch, "i"); break; default: document.getElementById("replaceTxt").innerHTML = "<p>There was an error processing your request.</p>"; } var rowColor = 1; var noResult = "false"; for (i=0;i<dcount;i++) { var row = document.createElement('TR'); var searcharr = new Array(); for (j=0;j<x[i].childNodes.length;j++) { if (x[i].childNodes[j].nodeType != 1) continue; searcharr.push(x[i].childNodes[j].firstChild.nodeValue); } var searchstrg = searcharr.toString(); if (searchstrg.match(objRegex)) { var t; var m=1; if (document.Catalog.thumbImg[0].checked) { var pn = "images/"+searcharr[2]+".jpg"; var container = document.createElement('TD'); var refLink = document.createElement("A"); refLink.setAttribute('href', "javascript:viewImg(\""+pn+"\")"); var imgHolder = document.createElement("IMG"); imgHolder.setAttribute("src", pn); imgHolder.style.height = "75px"; refLink.appendChild(imgHolder); container.appendChild(refLink); container.className = "img"+rowColor; row.appendChild(container); } for (t=0; t<searcharr.length; t++) { container = document.createElement('TD'); var theData = document.createTextNode(searcharr[t]); container.appendChild(theData); container.className = 'line' + rowColor + '_' + m; row.appendChild(container); m++; } tmp.appendChild(row); rowColor == 1 ? rowColor++ : rowColor--; document.getElementById("replaceTxt").innerHTML = ""; document.getElementById("replaceTxt").appendChild(newEl); noResult = "true"; } } if (noResult=="false") { document.getElementById("replaceTxt").innerHTML = "<h3>Sorry, there was no match to your search. Please try again</h3>"; } } xmlDoc is the xml object from my import xml function. it is working correctly. IE does not give any JS errors, it just does nothing. If I put text in the Code: document.getElementById("replaceTxt").innerHTML field, IE displays the text in the correct spot so I know the code is working. I also verified the data is being written correctly to "newEl" via IE 8 debugger. IE just does not want to append the newEl child to the <div> tag. This is where I assume the problem is. Hi! New to JS... have been trying to rework this to call additional, independent sets of colors to cycle through (so it would loop thru a set of grays, a set of primary colors, etc). I would use perhaps a different function name in the HTML to call different sets of colors. If this is more complex than I think it is, I think 3 sets would be plenty. Would be hugely grateful for any help, thanks so much in advance. (demo link of script in current state at bottom) Code: <html><head><title></title> <script language=javascript> colors = ["#cacdca", "#b2b4b2", "#969896", "#7d7f7d", "#ffff00"]; cRGB = []; function toRGB(color){ var rgb = "rgb(" + parseInt(color.substring(1,3), 16) + ", " + parseInt(color.substring(3,5), 16) + ", " + parseInt(color.substring(5,7), 16) + ")"; return rgb; } for(var i=0; i<colors.length; i++){ cRGB[i] = toRGB(colors[i]); } function changeColor(target){ var swapper = navigator.appVersion.indexOf("MSIE")!=-1 ? toRGB(document.getElementById(target).style.backgroundColor) : document.getElementById(target).style.backgroundColor; var set = false; var xx; for(var i=0; i<cRGB.length; i++){ if(swapper == cRGB[i]){ if(((i+1)) >= cRGB.length){ xx = 0; }else{ xx = i+1; } document.getElementById(target).style.backgroundColor = colors[xx]; document.getElementById(target).style.backgroundImage.show; set = true; i=cRGB.length; } } set ? null : document.getElementById(target).style.backgroundColor = colors[1]; } </SCRIPT> </head> <body bgcolor="#333333"> <div> <div id="a1" onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background1.png); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: none"></div> <div id=a2 onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background2.gif); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: #666633"></div> <div id=a3 onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background3.png); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: #666633"></div></div> </body> </html> Demo: http://theclutch.com/rollover_color_..._bgndimage.htm Hi, I'm faced with a problem trying to set background color under IE7. I have the following Javascript: Code: function showLayer793BKColor(id) { var txtObj = document.all(id); if (txtObj.style.display == 'none') { txtObj.style.display = '' txtObj.style.backgroundColor = 'grey'; } } function hideLayer793BKColor(id) { var txtObj = document.all(id); if ( txtObj.style.backgroundColor == 'grey' ) txtObj.style.display = 'none'; } These functions are used to show or hide div blocks. These blocks are, for example, specified in the following way: Code: <div id="l_gct5tekst" style="display:none"> <b>GCT 5. Eerste verkenning problematiek</b> and, for example, Code: <div id="l_Keuze" style="display:none"> <br/> <b>GCT 5</b> <br/> </div> The whole configuration works smoothly when using IE8. However, when using IE7 I get an error msg like "Invalid value for property". When I use the Color propert iso the BackgroundColor property I get no error anymore but of course I don't have a background color anymore then. In what way can I specify the use of a background color under IE7 ? Or is just not possible in one way or the other. Furthermore, what more differences between JS under IE7 and IE8 do I have to take into account ? Do I also have to rewrite my div block in some way (using some attribs ?) to cope with IE7 ? Thanks in advance, Diederick van Elst Referring to following link, I get no idea on what the highlight code do, I would like to retrieve the web page using direct URL coding without using function. Does anyone have any suggestions? Thanks in advance for any suggestions http://www.dailyfx.com.hk/calendar/index.html function setFilter(field, value){ var params = {}; params["type"] = "calendar"; params["date"] = "2011-12-06" $('#calTable').load("/inc/process.php", params, function(data){ $(this).html(gbBig5(data)); }); } Hi I am doing validation on a form, but instead of throwing an alert on empty fields I want to highlight those fields indicating error. if all are empty, then i would like to show only 1 generalized error message "Pls. fill the highlighted textboxes.". how do i do this and thanks in advance. Hi, I have say 12 pics on a page, in 3 rows of 4. The rows of pics are there so that a choice can be made from each row and I'm using a function <script> var highlight_color = '#FF0033'; function toggle_highlight(id) { var images = document.getElementsByTagName('img'); for (var i = 0; i < images.length; i++) { var image = images[i]; image.style.borderColor = image.id == id ? highlight_color : 'white'; } } </script> to toggle a border colour change so that you can see what was chosen from each row. The function I have used is fine in that it works, but I can only choose one picture and have the border changed, then if I click on another row the first border that changed obviously changes back and the new selection is highlighted. I don't really know where to go from here. Any help will be much appreciated. Thank you. Hello, I have an image that contains two links; however, you cannot tell unless you happen to mouseover the right area and a message appears "Click here..." How do I highlight the area so that the user knows the links are there? This is the url: http://jaxpubliclibrary.org/progs/jpl/foote.html Thank you for your help, Elbee Hi, On my webpage I have an embedded link that jumps the users up to a text box for logging in. I'm trying to find a way so when they click that link, it will not only jump up to the text box but highlights it as well. I then want the highlight color to fade back to normal. I've been searching around but I can't find something that will work. Any ideas? I've Googled this without success. I have a webpage with an iframe which is on my same server. My parent page is a form which posts to the iframe page. The iframe page is a shell script that is used to telnet to routers and process commands and display the commands and responses. I need to have a highlight text option on the parent page for what is displayed in the iframe. Is this possible to do this with Javascript and if so, can you share that with me? Hi guys, I wonder if anyone can help me here, got this below code for a page im working on, what you'll notice is that when you hover over 'order' a sub menu appears, what I need help on is this, how do I make the 'order' remain highlight while Im hovering over the sub menus. hope im making sense. thanks in advance. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>test </title> <style type="text/css"> #menu {width:800px; height:36px; text-align:left; background:url(red.gif);} #menu li a {display:block; width:80px; margin-top:5px; height:24px; color:#000; text-decoration:none; padding:0 10px 0 10px; font: bold 12px/22px verdana;}/* This sets the default properties*/ #menu li a:hover{padding:0 9px; border:1px solid #000; background:#444; color:#fff; line-height:24px}/* This sets the hover properties*/ #menu ul {width: 100%;margin: 0 75px auto;} /* This centres the menu 100px from the left*/ #menu li { margin: 0; padding: 0; list-style: none; float: left;} #sddm div { position: absolute; visibility: hidden; margin: 0; background: #EAEBD8; border: 1px solid #5970B2} #sddm div a {position: relative; display: block; margin: 0; width: auto; white-space: nowrap; text-align: left; text-decoration: none; background: lightgrey; border-left:1px solid black; color: #2875DE;} #sddm div a:hover{ background: #49A3FF; color: #FFF} /* End navigation bar styling. */ /* This is just styling for this specific page. */ body { font: small/1.3 Arial, Helvetica, sans-serif; } div { text-align:center; } div#page { border:1px solid lightgrey; width:800px; margin:0 auto; padding:5px; text-align:left;} div#header { border:2px solid lightgrey; width:796px; height:100px;} div#content { border:2px solid lightgrey; width:796px; min-height:500px; _height:500px} div#footer { border:2px solid red; width:750px; height:30px;} </style> <script type="text/javascript"> <!-- var timeout = 1; var closetimer = 0; var ddmenuitem = 0; // open hidden layer function mopen(id) { // cancel close timer mcancelclosetime(); // close old layer if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; // get new layer and show it ddmenuitem = document.getElementById(id); ddmenuitem.style.visibility = 'visible'; } // close showed layer function mclose() { if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; } // go close timer function mclosetime() { closetimer = window.setTimeout(mclose, timeout); } // cancel close timer function mcancelclosetime() { if(closetimer) { window.clearTimeout(closetimer); closetimer = null; } } // close layer when click-out document.onclick = mclose; // --> </script> </head> <body> <div id="page"> <div id="header">Header</div> <div id="menu"> <ul id="sddm"> <li><a href="#" onmouseover="mopen('m3')" onmouseout="mclosetime()">Order</a> <div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="#">Visa Credit Card</a> <a href="#">Paypal</a> </div> </li> <li><a href="#">Home</a></li> <li><a href="#">Our Products</a></li> <li><a href="#">FAQs</a></li> <li><a href="#">Contact</a></li> <li><a href="#">Login</a></li> </ul> </div> <div id="content">Content</div> <div id="footer">Footer</div> </div> </body> </html> Hey guys, So, I am using the highlight.js library to highlight posted code. It is working fine, however in IE it centers everything within my <pre><code>...</code></pre> area. This is because my body has the attribute: text-align: center; This is specifically because IE doesn't respond to: margin: 0 auto. So, how could I go about fixing this? Here is the code. Code: <html> <head> <link rel="stylesheet" href="highlight/styles/sunburst.css"> <script src="highlight/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script> <style type="text/css"> pre { overflow: auto; } p hover { position: relative; width: 100%; height: 80%; z-index: 99; } body { margin: 0px; text-align: center; } .spacer1 { height: 7%; } .sub_title { text-align: center; font-size: 1.7em; font-family: monospace; font-weight: bold; } .sub_title2 { text-align: center; font-size: 1.4em; font-family: monospace; font-weight: bold; } .text_norm { font-size: 1.2em; font-family: monospace; text-align: left; } .code_cont { width: 90%; height: 40%; background-color: #CCCCCC; border: 1px solid #333333; margin: 0 auto; overflow: auto; text-align: left; } #container { background-color: #999999; width: 80%; height: auto; margin: 0 auto; overflow: hidden; padding-bottom: 5%; } #title_cont { background-color: #333333; width: 100%; height: 10%; display: table; text-align: center; } #title { color: #ffffff; font-size: 2.4em; font-family: monospace; font-weight: bold; display: table-cell; vertical-align: middle; } #summary_cont { width: 90%; margin: 0 auto; } #ex_cont { width: 90%; margin: 0 auto; } </style> </head> <body> <div id="container"> <div id="title_cont"> <span id="title">Dynamically Expanding Textarea Script</span> </div> <div id="summary_cont"> <div class="sub_title">SCRIPT SUMMARY</div> <br /> <div id="summary_body" class="text_norm">This script adds a feature on all textarea's in a page allowing them to dynamically change height according to their content. The script goes at the very bottom of the body. The script first makes an array of all the textareas on the page, and then modify's the onfocus, onblur</div> </div> <div class="spacer1"></div> <div class="sub_title2">Code(Goes at bottom of <body>)</div> <pre class="code_cont"> <code> <script type="text/javascript"> //////////////////////////////////// // Auto Expand Textarea Script // //////////////////////////////////// //This script gives every textarea// //the property of expanding and // //returning to original size // //relative to its conetnt. // //////////////////////////////////// // Insert at end of body tag // //////////////////////////////////// //Sniffer is the variable holding the recursive setTimeout function var sniffer; //textareas is the array of every textarea element found on the page var textareas = document.getElementsByTagName('textarea'); //If user is viewing through IE, set overflow to visible, everything //else is already taken care of. if (navigator.appName == 'Microsoft Internet Explorer') { for(var i=0; i %lt; textareas.length; i++) { textareas[i].style.overflow = "visible"; } } else { //This function dynamically changes the height of the textarea in focus function tAreaSniffer(tArea, prevVal) { //This makes sure the textarea doesn't change height if no changes //have been detected recently. var curVal = tArea.value; if(curVal != prevVal) { tArea.style.height = 1 + "px"; tArea.style.height = tArea.scrollHeight + "px"; } //This is a recursive call that will execute 50 milliseconds after here. sniffer = setTimeout(function(){tAreaSniffer(tArea, curVal)}, 50); } //This cycles through every textarea on the page and assigns different properties //and methods as can be seen below. Onfocus property means when a textarea has //focus, the script tAreaSniffer will run. When it loses focus the function will stop. //Overflow hidden ensures that no scrollbar will be present, and minHeight is to make //sure the textarea never gets smaller than its originally intentded height. for(var i=0; i < textareas.length; i++) { textareas[i].onfocus = function(){tAreaSniffer(this, this.value);}; textareas[i].onblur = function(){clearTimeout(sniffer);}; textareas[i].style.overflow = "hidden"; textareas[i].style.minHeight = textareas[i].offsetHeight + "px"; } } </script> </code> </pre> <div class="spacer1"></div> <div id="ex_cont"> <div class="sub_title2">Example</div> <div class="text_norm">Below are several textareas. This is meant to demonstrate the script's universal power, in the sense that it will modify each and every textarea object. To test the script, simply type, or copy and paste text into the textareas. They should change accordingly.</div> <div> <textarea cols="42" rows="6"></textarea> <textarea cols="42" rows="6"></textarea> <textarea cols="42" rows="6"></textarea> <textarea cols="42" rows="6"></textarea> </div> </div> </div> <script type="text/javascript"> //////////////////////////////////// // Auto Expand Textarea Script // //////////////////////////////////// //This script gives every textarea// //the property of expanding and // //returning to original size // //relative to its conetnt. // //////////////////////////////////// // Insert at end of body tag // //////////////////////////////////// //Sniffer is the variable holding the recursive setTimeout function var sniffer; //textareas is the array of every textarea element found on the page var textareas = document.getElementsByTagName('textarea'); //If user is viewing through IE, set overflow to visible, everything //else is already taken care of. if (navigator.appName == 'Microsoft Internet Explorer') { for(var i=0; i < textareas.length; i++) { textareas[i].style.overflow = "visible"; } } else { //This function dynamically changes the height of the textarea in focus function tAreaSniffer(tArea, prevVal) { //This makes sure the textarea doesn't change height if no changes //have been detected recently. var curVal = tArea.value; if(curVal != prevVal) { tArea.style.height = 1 + "px"; tArea.style.height = tArea.scrollHeight + "px"; } //This is a recursive call that will execute 50 milliseconds after here. sniffer = setTimeout(function(){tAreaSniffer(tArea, curVal)}, 50); } //This cycles through every textarea on the page and assigns different properties //and methods as can be seen below. Onfocus property means when a textarea has //focus, the script tAreaSniffer will run. When it loses focus the function will stop. //Overflow hidden ensures that no scrollbar will be present, and minHeight is to make //sure the textarea never gets smaller than its originally intentded height. for(var i=0; i<textareas.length; i++) { textareas[i].onfocus = function(){tAreaSniffer(this, this.value);}; textareas[i].onblur = function(){clearTimeout(sniffer);}; textareas[i].style.overflow = "hidden"; textareas[i].style.minHeight = textareas[i].offsetHeight + "px"; } } </script> </body> </html> hiiii, im new to javascripts . Can anyone help me to know that a javascript which is validating a phone number accepts only digits but if the text field is left empty it should accept the entry as an empty entry.... plz share knowledge u will be more knowledgeable Hi folks. Looking to see if anyone could tell me where I'm going wrong with this script... I'm trying to have a field automatically filled with the day of the week ("Monday", "Tuesday", "Wednesday" and so on), upon the user selecting a date from the datepicker jQuery. If this isn't clear, I'll clarify further down the page. Here is the script: Code: <script type="text/javascript"> jQuery(document).ready(function($){ $('input[name="item_meta[428]"]').change(function(){ var d = $('input[name="item_meta[428]"]').val(); var n = new Date(d).getDay(); if(n == 0) val v = 'Sunday'; else if(n == 1) val v = 'Monday'; else if(n == 2) val v = 'Tuesday'; else if(n == 3) val v = 'Wednesday'; else if(n == 4) val v = 'Thursday'; else if(n == 5) val v = 'Friday'; else if(n == 6) val v = 'Saturday'; $('input[name="item_meta[429]"]').val(v).change(); }); }); </script> I'm basically trying to say, if the user selected today (15/05/2012) in the field 428 it would fill the field 429 with "Tuesday". Again, if the user selected 18/05/2012 in the field 428 then it would automatically fill field 429 with "Friday". It's being done to work in conjunction with a wordpress plugin called Formidable Pro hence the item_meta[428] etc. Any assistance would be greatly appreciated. Sam. |