JavaScript - Resizing Text Field With Onfocus
I am trying to get a text field to increase in size (one time to a predetermined size) when user clicks in the text field. Here is the code that for some reason isn't working for me.
Code: <script type='text/javascript'> function resizeIt() { document.getElementById('comment').style.height = 50px; }; </script> <input type='text' id='comment' class='urlTextArea' name='url' value='' size='75' onfocus='resizeIt()'> Similar TutorialsHi all, Thanks for reading. I'm having an issue trying to accomplish the following - I have a text field (field1) already displayed on the HTML page. However, there's a link where you can add additional text fields to the page as well. When the link is clicked, the second text field is added successfully (field2), and when the link is clicked again, the third text field (field3) is added successfully. However, the third field does not add itself to the page, and the text for anything greater than a third field also isn't displayed after. This obviously means that my "fields" variable is not working right, so I'm wondering, would anyone be able to assist me to help me get that variable processing correctly? Code: <script language="javascript"> fields = 1; function addMore() { if (fields = 1) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field2' size='25' /> <span>Field 2.</span>"; fields = 2; } else if (fields = 2) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field3' size='25' /> <span>Field 3.</span>"; fields = 3; } else { document.getElementById('addedMore').innerHTML = "Only 3 fields are allowed."; document.form.add.disabled=true; } } </script> Here is the code in my HTML - Code: <input type="text" name="field1" size="25" /> <span>Field 1.</span> <div id="addedMore"></div> <p class="addMore"><form name="add"><a onclick="addMore()">Add another field.</a></form></p> Thank you very much. Hey guys, First shot at JS so please be gentle! I'm trying to get this script to clear the default value of my input elements on focus. It works well the first time, however, if a user inputs some fresh text, selects something else, then selects the same input element again, it will clear the text they entered. Make sense? Here's the script (thanks in advance!!): Code: <script language="JavaScript"> function clickFocus(input){ input.className = 'focus'; if (input.value = input.defaultValue){ input.value = ''; } } function unFocus(input){ input.className = 'entered'; if (input.value == ''){ input.value = input.defaultValue; input.className = 'normal' } } </script> <form action="confirmation.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return checkForm(this)"> <input type="text" name="name" value="Name" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <input type="text" name="email" value="Email" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <input type="text" name="subject" value="Subject" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <textarea type="text" name="message" onfocus="clickFocus(this)" onblur="unFocus(this)" rows="5">Message</textarea> <input class="submit" name="submit"type="submit" value="Send Message" /> </form> I have a text field, call it income, that when the input is > 0 I need to dynamically show the next text box, and if it is blank hide the next text box. I would like to use onBlur but can't seem to get it to work. Can I do this? Help Hi, I'm hoping this will be an easy one for you experts out there. I am working on a convention registration form. What I'm trying to do is have the text "50.00" pop into the COST field when any text (even if it's only one character) is entered into the NAME field. If the text in the NAME field is deleted, the "50.00" should also be deleted. Does anyone have a script that does this? Thanks! Hi all, I have a REALLY strange problem - maybe a new set of eyes can help me. Look at these pieces of code: This generates the code Code: <!-- BEGIN code_open --> <dl class="codebox"> <dt>{L_CODE}: <a href="#" onclick="autoSelect(this.parentNode.nextSibling); return false;">{L_SELECT_ALL_CODE}</a> </dt> <dd> <pre onfocus="doTest(this)"> <!-- END code_open --> <!-- BEGIN code_close --> </pre> </dd> </dl> <!-- END code_close --> Test JS just for now Code: var doTest = function(a) { alert(a); } The HTML as seen by Firebug Code: <dt>Code: <a href="#" onclick="autoSelect(this.parentNode.nextSibling); return false;">Select all</a></dt><dd> <pre onfocus="doTest(this)"> Test Test Test </code></pre></dd> One little problem... it doesn't work!!! And yes the function being called is accessible. For that matter, simply putting "alert('hello')" into the "onfocus" also fails. I even checked at W3CSchools to verify that: (1) The <pre> element supports "onfocus" (it does). (2) I ran their "Try it" and "onfocus" is working in my browser (Firefox 3.6.17, WinXP 32). What the heck??????????? Any ideas? Thanks! -- Roger Hello The onFocus events I have come across seem to deal with changing the background colour of the field on a Web form, so that the active field is a different colour to the background field of the other form elements. But how would I use onFocus simply to have the cursor moving in the active field (on a Web form it might be the 'name' field for example)? The code I have at the moment looks like this: Code: <!DOCTYPE etc <head> <title>Janko</title> <style type="text/css"> body { font-family: Arial, Sans-Serif; font-size: 13px; } #inputArea { font-family: Arial, Sans-Serif; font-size: 13px; background-color: #d6e5f4; padding: 10px; width:310px; } #inputArea input, #inputArea textarea { font-family: Arial, Sans-Serif; font-size: 13px; margin-bottom: 5px; display: block; padding: 4px; width: 300px; } .activeField { background-image: none; background-color: #ffffff; border: solid 1px #33677F; } .idle { border: solid 1px #85b1de; background-image: url( 'blue_bg.png' ); background-repeat: repeat-x; background-position: top; } </style> <script src="jquery-1.2.6.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $("input, textarea").addClass("idle"); $("input, textarea").focus(function(){ $(this).addClass("activeField").removeClass("idle"); }).blur(function(){ $(this).removeClass("activeField").addClass("idle"); }); }); </script> </head> <body> <h2><a href="www.jankoatwarpspeed.com">Janko At Warp Speed</a></h2> <p>This example is from the article <a href="http://www.jankoatwarpspeed.com/post/2008/05/22/CSS-Message-Boxes-for-different-message-types.aspx">Enhance your input fields with simple CSS tricks</a></p> <div id="inputArea"> <label for="txtName"> Name</label> <input id="Text16" type="text" /> <label for="txtEmail"> Email</label> <input id="Text17" type="text" /> <label for="txtWebsite"> Subject</label> <input id="Text18" type="text" /> <label for="txtComment"> Message</label> <textarea id="Textarea6" rows="4" cols="30"></textarea></div> </body> </html> Many thanks Steve greetings, i have a function that sets the onfocus and onblur event for every item in a table which then tells it to the change the class name. for some reason this doesn't seem to be working with the <select> inputs. i have heard it has something to do with how the option list re-loads itself??? Code: function setTableActivation(){ tableDiv = document.getElementById("tables"); tables = tableDiv.getElementsByTagName("table"); count = tables.length; for(var h=0;h<count;h++){ var table = tables[h]; table.accessKey = h; table.onfocus = function(){tables[this.accessKey].className = "activeTable";}; table.onblur = function(){tables[this.accessKey].className = "searchreal";}; for(var i=0;i<table.rows.length;i++){ row = table.rows[i]; row.accessKey = h; row.onfocus = function(){tables[this.accessKey].className = "activeTable";}; row.onblur = function(){tables[this.accessKey].className = "searchreal";}; for(var j=0;j<table.rows[i].cells.length;j++){ cell = table.rows[i].cells[j]; cell.accessKey = h; cell.onfocus = function(){tables[this.accessKey].className = "activeTable";}; cell.onblur = function(){tables[this.accessKey].className = "searchreal";}; for (var k = 0; k < cell.childNodes.length; k++) { if (cell.childNodes[k].nodeType == document.ELEMENT_NODE) { cell.childNodes[k].accessKey = h; cell.childNodes[k].onfocus = function(){tables[this.accessKey].className = "activeTable";}; cell.childNodes[k].onblur = function(){tables[this.accessKey].className = "searchreal";}; if(cell.childNodes[k].tagName == "SELECT"){ } } } } } } } Hi, can someone show me why I cant get the onfocus and onblur to loop thru the function showTextContent() when entering the words one, two, three or four. I have tried for days, googled and lost a lot of hair trying to figure it out. http://www.data-affiliates.com/DL234...5/attempt.html Code: <html> <!-- Created on: 08.08.2009 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title></title> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content="sdfgdfg"> <meta name="generator" content="AceHTML 6 Pro"> <link rel="stylesheet" href="vid61.css" type="text/css" media="screen" /> <script type="text/javascript"> function toggle(id, status){ document.getElementById(id).style.visibility = status; } function myFocus(element) { if (element.value == element.defaultValue) { element.value = ''; } } function myBlur(element) { if (element.value == '') { element.value = element.defaultValue; } } function populateSearchField(){ var specialChars = "\\.+*?[^]$(){}=!<>|:,-=/"; var ignoreList = ["a", "the"]; var i, j, searchFld, keywords; if (!(searchFld = document.getElementsByName('formcontent')[0])) return; if (!(keywords = document.referrer.match(/[pq]=(.*?)&/))) return; var preg_quote = function(str){return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, "\\$1");} keywords = decodeURIComponent(keywords[1]).replace(new RegExp('[' + preg_quote(specialChars) + ']', 'g'), ' ').split(/[\+ ]/); for (i = 0; i < keywords.length; i++){ for (j = 0; j < ignoreList.length; j++) if (!keywords[i] || (keywords[i] == ignoreList[j])) { keywords.splice(i--, 1); break; } } searchFld.value = keywords.join(' '); } function keywordMatch(keywords, text) { var result = 0; for (var i in keywords) { if (text.match(new RegExp("(^| )" + keywords[i] + "( |$)", "i"))) { result++; }; } return result; } function showTextContent() { var i, matches = []; var div, divcontent, divs = document.getElementById("ts-1").getElementsByTagName('div'); var keywords = document.getElementsByName('formcontent')[0].value.split(' '); for (i = 0; i < divs.length; i++) { div = divs[i]; divcontent = div.lastChild.nodeValue; if (keywordMatch(keywords, divcontent)) { matches.push(div); } } if (matches[0]) { document.getElementById('take1000').innerHTML = matches.length + " matches / Treffer"; for (i = 0; i < matches.length; i++) { matches[i].onmouseover(toggle('take1000', 'visible')); matches[i].onmouseout = null; } } else { document.getElementById("ts-1").innerHTML = "" ; matches[i].onmouseover(toggle('notake1000', 'visible')); } } window.onload = function(){ populateSearchField(); showTextContent(); } </script> </head> <body> <div id="container"> <div id="notake1000">Keine Ergebnisse / No Matches</div> <div id="take1000"></div> <div id="ulent">Search this site / Diese Seite durchsuchen :</div><form><input type="text" name="formcontent" value="one" onmouseover="toggle('notake1000', 'hidden');toggle('take1000', 'hidden');" onfocus="myFocus(this); showTextContent();" onblur="myBlur(this); showTextContent();" style="font-family:Arial;color:#ffff40;text-align:center;font-size:12px;font-weight:bold;float:right;margin-left : auto;margin-right : 2px;border: 2px double #AFAFAF;background-color: #5F5F5F;padding:1px;height:18px;width:293px;" /></form> <div id="ts-1" style="visibility:hidden;"> <div onmouseover="toggle('fo-test1', 'visible');" onmouseout="this.className='ts-1-1';toggle('fo-test1', 'hidden');" onmouseup="this.className='ts-1-3A';" class="ts-1-1"><object id="fo-test1" style="visibility:hidden;" type="application/x-shockwave-flash" data="peelawayok.swf" width="356" height="286"><param name="movie" value="peelawayok.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /></object>www.Ihre-domain.de<br />one</div> <div onmouseover="toggle('fo-test2', 'visible');" onmouseout="this.className='ts-1-2';toggle('fo-test2', 'hidden');" onmouseup="this.className='ts-1-3A';" class="ts-1-2"><object id="fo-test2" style="visibility:hidden" type="application/x-shockwave-flash" data="peelawayok.swf" width="356" height="286"><param name="movie" value="peelawayok.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /></object>www.Ihre-domain.de<br />two</div> <div onmouseover="toggle('fo-test3', 'visible');" onmouseout="this.className='ts-1-3';toggle('fo-test3', 'hidden');" onmouseup="this.className='ts-1-3A';" class="ts-1-3"><object id="fo-test3" style="visibility:hidden" type="application/x-shockwave-flash" data="peelawayok.swf" width="356" height="286"><param name="movie" value="peelawayok.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /></object><br />www.Ihre-domain.de<br />three</div> <div onmouseover="toggle('fo-test4', 'visible');" onmouseout="this.className='ts-1-4';toggle('fo-test4', 'hidden');" onmouseup="this.className='ts-1-3A';" class="ts-1-4"><object id="fo-test4" style="visibility:hidden" type="application/x-shockwave-flash" data="peelawayok.swf" width="356" height="286"><param name="movie" value="peelawayok.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="false" /></object><br />www.Ihre-domain.de<br />four</div> </div> </div> </body> </html> Ok, here is my issue. I want to have an input text on the top of the page that when I type in a series of numbers and hit submit, it populates the rest of the form. Does anyone have any idea what I need to perform this action?
Hi all, I am working on a site which is in a frameset. There is content area, a footer and a workqueue on the right. Now what I do is poll the workqueue every 30 seconds, check if there are any changes to any queues and if so, I make them go bold and red and play a beep. That's no problem, that works fine. The trouble is I am trying to make the title flash "New Item" if the window is out of focus (Minimised would be better but dont think that is possible to detect). The flashing bit is no problem, it's the triggering when the windows out of focus that is a problem. Applying events to the window object doesn't work. The closest I have come to making it work is this, but it doesn't work in firefox... Code: var debugwin = window.open("", "newwin", "width=300, height=300, scrollbars=1"); debugwin.document.open(); debugwin.document.write("<HTML><TITLE>Debug Window</TITLE><BODY>"); debugwin.document.write("</BODY></HTML>"); debugwin.document.close(); function addDebug(msg) { debugwin.document.body.innerHTML = msg + "<BR/>" + debugwin.document.body.innerHTML; } <!--<frameset onblur="workitemAlerts.setItemAlerts(false);" onfocus="workitemAlerts.setItemAlerts(true);" id="titleframeset" rows="<%= HEADER_FRAME_RESTORED %>,*,<%= FOOTER_FRAME_HEIGHT %>" framespacing="0" border="0" frameborder="0">--> <frameset onblur="addDebug('Blur 1st frameset');" onfocus="addDebug('Focus 1st frameset');" id="titleframeset" rows="<%= HEADER_FRAME_RESTORED %>,*,<%= FOOTER_FRAME_HEIGHT %>" framespacing="0" border="0" frameborder="0"> <frame onblur="addDebug('Blur frame 1');" onfocus="addDebug('Focus frame 1');" noresize scrolling="no" framespacing="0" border="0" frameborder="0" id="titlebar" name="titlebar" src="<wfmt:headerpage />"> <frameset onblur="addDebug('Blur 2nd frameset');" onfocus="addDebug('Focus 2nd frameset');" id="mainframeset" cols="10,*,<%= MAIN_FRAME_RESTORED %>" framespacing="0" border="0" frameborder="0"> <frame onblur="addDebug('Blur frame 2');" onfocus="addDebug('Focus frame 2');" noresize framespacing="0" border="0" frameborder="0" name="leftpad" src="mainColourFill.jsp" scrolling="no"> <frame onblur="addDebug('Blur frame 3');" onfocus="addDebug('Focus frame 3');" noresize name="windmain" src="<wfmt:postloginpage />" scrolling="auto"> <frame onblur="addDebug('Blur frame 4');" onfocus="addDebug('Focus frame 4');" noresize framespacing="0" border="0" frameborder="0" name="queues" src="workqueues.jsp" scrolling="no" style="BORDER-RIGHT: gray 1pt solid;"> </frameset> <frame noresize scrolling="no" framespacing="0" border="0" frameborder="0" name="footerbar" src="footer.jsp"> </frameset> I have popped up a little window to help me view debug away from the window so I can focus and blur and still see the output to see what events are triggering. IE seems to trigger the events on the <frame> tags fine, which means I can achieve what I need to in IE, however FF isn't playing ball. Anybody know what I can do to detect if the window is out of focus. TIA, Dale Realizing that form input placeholders aren't universally recognized among browsers, I began changing all of mine using onblur and onfocus handlers instead. As an example, I used the following code, which works in most cases: Code: <input type="text" name="example" maxlength="5" value="Example" onblur="if(this.value=='') this.value='Example';" onfocus="if(this.value=='Example') this.value='';"/> At first, I coded all of the inputs without a value attribute. But, when the page initially loaded, the fields would load empty, and the value/placeholder wouldn't appear until the field had been "focused" and then "blurred" again. Adding the value attribute seemed to correct that problem, again, for the most part. I have some text fields that appear only after I select a particular radio button or select option. Problem is, when the radio is clicked, the field appears, but even with the value attribute in place, the field appears void. I'm not sure what is different, or what I'm doing wrong. Here's the javascript code with the radio button (note:everything works except that the "placeholder" doesn't show when the field first appears): Code: function showfield() { document.forms[0].otherRelation.value = ""; document.getElementById("newBox").style.display = "none"; var r = document.forms[0].relation; var len = r.length; for (var i =0; i<len; i++) { if (r[i].checked && r[i].value == "Otherrelation" ) { document.getElementById("newBox").style.display = "inline"; } } } <input type="radio" name="relation" value="Otherrelation" onclick="showfield()"/>Other <span id = "newBox" style="display:none">: <input type = "text" name="otherRelation" size="35" value="Your Relationship" onblur="if(this.value=='') this.value='Your Relationship';" onfocus="if(this.value=='Your Relationship') this.value='';"/> </span> Thanks for any help. Sorry so long. Hey all, I'm trying to write what I thought to begin with would be a simple script. All it will do is go out and find every textarea, then change the onblur/onfocus functions to something that I created. Here's my problem, when I am going through each textarea object, I can't seem to find a way to reference the object from within the function. See down in that for loop? When I say tAreaSniffer(i), the i ends up being overwritten each time. This makes the value of i in each object to be 3(since there are 3 textareas). I have used javascript in the past, however now I am getting back into it and having trouble. Thanks guys, Here's my code: Code: <html> <head> </head> <body> <form> <textarea name="t1" rows="4" cols="20"></textarea> <textarea name="t2" rows="4" cols="20"></textarea> <textarea name="t3" rows="4" cols="20"></textarea> </form> <script type="text/javascript"> var sniffer; var textareas = document.getElementsByTagName('textarea'); var counter = 0; function tAreaSniffer(tArea)//, oldCont) { alert(tArea); //var curCont; = tArea.value; counter++; sniffer = setTimeout(function(){tAreaSniffer(tArea)}, 1000); } for(var i=0; i<textareas.length; i++) { textareas[i].onfocus = function(){tAreaSniffer(i);};//, textareas[i].value);}; textareas[i].onblur = function(){clearTimeout(sniffer);}; } alert("HEYO"); </script> </body> </html> Hi, I'm working on a website and am having difficulty figuring out how to have a function triggered when the window becomes active. I am having limited success with: <body onFocus=myFunction();> This works fine with Firefox and Safari, but not Internet Explorer. Is there a way to achieve this in all 3 browsers? Thanks. I have a page with 6 dependant drop down boxes. I also have a text field with a copy to clipboard button. What I need it to do is send the drop down selections to the text field to be copied along with some static text. The resulting text field would look something like this after the selections are made. "Per Wizard: Choice 0: Selection 2, Choice 1: Selection 2, Choice 2: Selection 4 ..." Can this be done on each line as a second onChange event? Code: <html> <head> <HEAD> <script type="text/javascript"> <!-- var arrItems1 = new Array(); var arrItemsGrp1 = new Array(); arrItems1[1] = "Selection 1"; arrItemsGrp1[1] = 1; arrItems1[2] = "Selection 2"; arrItemsGrp1[2] = 1; arrItems1[3] = "Selection 3"; arrItemsGrp1[3] = 1; var arrItems2 = new Array(); var arrItemsGrp2 = new Array(); arrItems2[12] = "Selection 1"; arrItemsGrp2[12] = 1 arrItems2[13] = "Selection 2"; arrItemsGrp2[13] = 1 arrItems2[14] = "Selection 3"; arrItemsGrp2[14] = 1 arrItems2[15] = "Selection 4"; arrItemsGrp2[15] = 1 arrItems2[16] = "Selection 5"; arrItemsGrp2[16] = 1 arrItems2[17] = "Selection 6"; arrItemsGrp2[17] = 1 var arrItems3 = new Array(); var arrItemsGrp3 = new Array(); arrItems3[42] = "Selection 1"; arrItemsGrp3[42] = 12 arrItems3[43] = "Selection 2"; arrItemsGrp3[43] = 12 arrItems3[44] = "Selection 3"; arrItemsGrp3[44] = 12 var arrItems4 = new Array(); var arrItemsGrp4 = new Array(); arrItems4[133] = "Selection 1"; arrItemsGrp4[133] = 42 var arrItems5 = new Array(); var arrItemsGrp5 = new Array(); arrItems5[244] = "Selection 1"; arrItemsGrp5[244] = 133 arrItems5[245] = "Selection 2"; arrItemsGrp5[245] = 133 function selectChange(control,nu){ var frm=control.form; var sel=frm['Choice'+nu]; var iary=window['arrItems'+nu]; var gary=window['arrItemsGrp'+nu]; var cnt=1; while (frm['Choice'+cnt]){ if (cnt>=nu){ while (frm['Choice'+cnt].firstChild){ frm['Choice'+cnt].removeChild(frm['Choice'+cnt].firstChild); } } cnt++; } var myEle=document.createElement("option"); myEle.appendChild(document.createTextNode("[SELECT ONE]")); myEle.setAttribute("value","0"); sel.appendChild(myEle); for (var x = 0 ; x < iary.length ; x++ ) { if ( gary[x]==control.value ) { myEle = document.createElement("option"); myEle.setAttribute("value",x); myEle.appendChild(document.createTextNode(iary[x])); sel.appendChild(myEle); } } } // --> </script> <script language='Javascript'> function doact(d) { var doc = eval("document.form."+d); cp = doc.createTextRange(); doc.focus(); doc.select(); cp.execCommand("Copy"); } function FP_popUpMsg(msg) {//v1.0 alert(msg); } </script> </HEAD> <BODY> <form name=form> <div align="center"> <table border="2" width="790" id="table1" bordercolor="#64367C"> <tr> <td width="778" align="left" colspan="2"> </td> <tr> <td width="305" align="left"> <font size="2" face="MS Sans Serif"> Choice 1:<font size="2" face="MS Sans Serif"> <select id="Choice0" name="Choice0" onchange="selectChange(this, 1);"> <option value="0" selected>[SELECT]</option> <option value="1">Selection 1</option> <option value="2">Selection 2</option> <option value="3">Selection 3</option> </select></font></font></td> <td width="225" align="center" onclick="FP_popUpMsg('More Info')"> <font face="MS Sans Serif" size="2" color="#FF0000">*</font><font face="MS Sans Serif" size="2" color="#0000FF"> <u> Tell me more</u></font></td> <tr> <td width="547" align="left"> <font size="2" face="MS Sans Serif"> Code 2: <select id="secondChoice" name="Choice1" onchange="selectChange(this, 2); "></select></font></td> <td width="225" align="center" rowspan="4"> <TEXTAREA name="text1" cols="25" rows="5"> Selections will populate here. </TEXTAREA><input onclick="doact('text1')" type="button" value="Copy"> </td> </tr> <tr> <td width="547" align="left"> <font size="2" face="MS Sans Serif"> Code 3: <select id="thirdChoice" name="Choice2" onchange="selectChange(this, 3);"></select></font></td> </tr> <tr> <td width="547" align="left"> <font size="2" face="MS Sans Serif"> Code 4: <select id="fourthChoice" name="Choice3" onchange="selectChange(this, 4);"></select></font></td> </tr> <tr> <td width="547" align="left"> <font face="MS Sans Serif" size="2"> Code 5: </font> <font size="3" face="Courier"> <select id="fifthChoice" name="Choice4" onchange="selectChange(this, 5);" size="1"></select></font></td> </tr> <tr> <td width="547" align="left"> <p><font face="MS Sans Serif" size="2"> Answer: </font> <font size="3" face="Courier"> <select id="sixthChoice" name="Choice5" onChange="alert('Reminder')" size="1"></select> </font></p></td> <td width="225" align="center"> <font size="2" face="MS Sans Serif"> <a target="_blank" href="reference.htm">Show the Full Spreadsheet</a></a></font></td> </tr> <tr> <td width="778" align="left" colspan="2"> </td> </tr> </table> </div> </form> </body> </html> Hello, I am needing the coding to do the follow: When a user makes a selection from a dropdown, the value is placed in a text input. SELECT >>> INPUT Thank you so much for your help! Hi guys, I have this drag and drop script: 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> <title>JavaScript Drag and Drop Tutorial</title> </head> <body> <div style="position:absolute; left:0%; top:0%; "> <style type="text/css"> .drag { position: absolute; } </style> <div style=" position:absolute; width:100%; height = 100%; left:0%; top: 0%" > <input id="1" class="drag" style="width:100px; height:100px; top: 0px" type="submit" value="Drag 'n' throw me"> <pre id="debug"> </pre> </div> <script language="JavaScript" type="text/javascript"> <!-- function $(id){ return document.getElementById(id); } var _startX = 0; // mouse starting positions var _startY = 0; var _offsetX = 0; // current element offset var _offsetY = 0; var _dragElement; // needs to be passed from OnMouseDown to OnMouseMove var _oldZIndex = 0; // we temporarily increase the z-index during drag var _debug = $('debug'); // makes life easier InitDragDrop(); function InitDragDrop() { document.onmousedown = OnMouseDown; document.onmouseup = OnMouseUp; } function OnMouseDown(e){ if (e == null) e = window.event; var target = e.target != null ? e.target : e.srcElement; if ((e.button == 1 && window.event != null || e.button == 0) && target.className == 'drag') { _startX = e.clientX; _startY = e.clientY; _offsetX = ExtractNumber(target.style.left); _offsetY = ExtractNumber(target.style.top); _oldZIndex = target.style.zIndex; target.style.zIndex = 10000; _dragElement = target; document.onmousemove = OnMouseMove; document.body.focus(); document.onselectstart = function () { return false; }; target.ondragstart = function() { return false; }; return false; } } function ExtractNumber(value) { var n = parseInt(value); return n == null || isNaN(n) ? 0 : n; } function OnMouseMove(e) { if (e == null) var e = window.event; // this is the actual "drag code" _dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px'; _dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px'; } function OnMouseUp(e) { if (_dragElement != null) { _dragElement.style.zIndex = _oldZIndex; // we're done with these events until the next OnMouseDown document.onmousemove = null; document.onselectstart = null; _dragElement.ondragstart = null; // this is how we know we're not dragging _dragElement = null; } } </script> </div> </body> </html> Is there a way to drag and drop text field? 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> I have a table where when the cursor passes/hovers over a cell, the current cell, as well as the top cell in its column and the first cell in its row change backgroundColor. I have text fields outside the table which I want to populate with the contents of the cells affected by the mouseover event. So as the mouse moves over different cells, the contents of the text fields changes accordingly. I've got the backgroundColor to change, but when I try to assign the contents of the cells to the text fields, nothing happens. The change of backgroundColor even stops working. This is the code I'm usign to populate the fields. Code: document.getElementById("tableID").textfieldID.value = Col1Cell[0].innerHTML; document.getElementById("tableID").textfieldID.value = HeaderCell[n].innerHTML; document.getElementById("tableID").textfieldID.value = this.innerHTML; I'm traversing through the <th> and <td> tags to find the header cell HeaderCell[n] and first column cell Col1Cell[0] associated with the current cell. If I leave out these lines the backgroundColor changes, if I use them, nothing happens at all. Can't figure out why. Any suggestions? Hi guys,I was thinking about the code to : write something inside the text box and if the word entered is equal "hero" for example the box next to it will turn green means correct, otherwise it will turn red means wrong,and if nothing entered it stays white. I really like to know how we code that in javascript using functions, without any CSS or anything else. That means we have 2 objects a text box and a rectangle for feedback color. Remark: there is no button at all, the validation will be each time you are typing. A Bonus question : if someday we decide to change the color with pictures , is it possible to do that? Thank you very much for your help, much appreciate it. |