JavaScript - Any Way To Populate Form Field With Onclick Image Event
I would like to set up an image gallery so that when customer clicks on their chosen image, the image caption populates into the associated field in the form below the gallery, on the same page.
Any way you know of to do this? I am not really a coder, I only know this and that, so examples or detailed instructions will be most helpful. Thanks very much. Similar TutorialsOk so Im going to break down what Im trying to do and hopefully someone can point me to a possible solution without getting all technical. I have 2 div tags. the first is a content container more or less. the second is a container for a php built calender (using html tables). Basically when the page loads the php builds the calenders html table code. each td element has an onclick event handler. The goal is to have the javascript handler execute when any non empty cell is clicked (non empty being that it has a date associated with it and is not a blank space filler). This is the easy part. The hard part is that each calendar day potentially has certain information associated with it stored in a mysql database. Im wanting input fields within the first container div to autopopulate with the information from the database (if any) for whatever day is clicked. Ive search around and heard things like javascript cant do mysql queries directly, and heard mention of ajax. So im stumped as to how to accomplish this. whether i need an external php script for the queries (perhaps inside a php function that can return data to the javascript that calls it?), but if that is plausable would it cause page loads or the like to the user? i really dont want to have to learn ajax for this one page, just seems excessive, but i do need a way to make the content in the first div populate with the respective database data for the selected day on the calendar. any thoughts, comments, or solutions that dont involve yet another web language would be greatly appreciated. thanks
Hi all I have relatively easy task I need to accomplish but as per usual I have very little idea of how to do it. I have done a google search to no avail. Basically I need to: 1. Pull a value from inside a div Code: <div id="number">(invoice #1017)</span> 2. Populate a form input field with that value. Does this make sense? If not let me know if you need any more info. Thanks Hi all, I can't seem to add an onclick event to an image. I'm sure I am doing something wrong as I am very new to Javascript. This is a part of my javascript code that is in the head and body of my HTML file: Code: <head> <script language="JavaScript"> ..... ..... var redLocation0 = redArray[0]+".jpg"; .... .... function redClick( buttonLocation ) { window.location = "http://www.yahoo.com/" } .... .... </script> </head> <body> <table> <tr> <td> <script language="javascript">document.write('<IMG SRC="'+ redLocation0 +'">'); onclick="redClick('0')";</script> </td> </tr> </table> </body> The image that is displayed is not clickable, and therefore the function redClick cannot be called. Can someone please help me and tell me where I am going wrong here. I am kinda new to JavaScript. Thanks! I'm very inexperienced with Javascript, but want to use the onclick event to change an image to text. I'm working on a directory type website and want users to have to click on the image of a telephone in order to reveal the telephone number they are looking for. how do i do this? Also is there a way of tracking how many clicks each person gets? I'd really appreciate any help you guys can give me on this Hi I am trying to stop a preloaded images used in a rollover. The images are linked to a tab navigation system, that open on the same page. if(document.images){ var image_array = new Array(); // path to the directory with images var path = './images/food-drink/food/'; // enumeration of the "active" images image_array[0] = path + "starters_r.png"; image_array[1] = path + "mains_r.png"; image_array[2] = path + "desserts_r.png"; image_array[3] = path + "childrens_r.png"; image_array[4] = path + "sandwiches_r.png"; image_array[5] = path + "meal_r.png"; var preload_image = new Array (); for(var i=0; i<image_array.length; i++){ preload_image[i]= new Image(); preload_image[i].src = image_array[i]; } } function rollover(name, filename){ var fullpath = './images/food-drink/food/' + filename; document.images[name].src = fullpath; } I am trying to change the image with another one, which will change back when a different image is clicked. The problem seems to be that the tab navigation code is disagreeing with other code I have tried. The tab code looks like this and works fine until I add another code with document.getElementById() to the onClick event. function swichtabs(wert) { if (wert=='1'){ /*menu starters tab*/ document.getElementById('tabStarters').className='tab1 tabactive'; document.getElementById('tabMains').className='tab2'; document.getElementById('tabDesserts').className='tab3'; document.getElementById('tabChildrens').className='tab4'; document.getElementById('tabSandwiches').className='tab5'; document.getElementById('tabMeals').className='tab6'; }else if (wert=='2'){ etc... The html code for the image is: <a href="#starters" onmouseout="rollover('btnStarters','starters.png')" onmouseover="rollover('btnStarters','starters_r.png')" onClick="this.onMouseOver=null;this.onMouseOut=null; blendon('starters'); blendoff('mains');etc...; swichtabs('1');" onclick="return false;" title="Starters" id="tabStarters"> <img src="./images/food-drink/food/starters.png" name="btnStarters" width="129" height="30" border="0" /> </a> I would be grateful if you could point me in the right direction. Hi there, I have a html form, and I need it so that when a user clicks a button, it adds a field into the form. I also need it to write <td></td> around the new field, and I need it to write this in a specific part row of a table. How would I go about doing this? I've tried searching for the past two hours, but no luck. Many thanks, I appreciate it, Jason I need when I click to type into a form field, I need an onclick event to show another form field. I would assume this would be a hiddin div or an on click event to post another form field. So in theory just because I actually clicked into one form field...another form field shows up underneath it...can anyone help... 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? I have a web form that requests a user full name and email address. What I would like to do is when the user fills in the full name in one input box, I would like to take the full name and populate the email address field as such. "first.last@allstate.com". So pretty much split the full name and popluate email address field "first.last@allstate.com". Tracy Hello forum, My name is juan and recently started html programming. I have a web page with a drop box with the name of states. Code: <option value="">Alabama</option> <option value="">Alaska</option> I can add a onclick="code here" to the tag so that when the drop box alabama is selected it triggers the onclick event. Im using Ibox in order to have a image of the state open. Code: <a href="images/large/image_1b.jpg" rel="ibox" title="alabama at 1024x450!"><img src="images/small/image_1.jpg" alt=""/></a> the above is a <a> link tag correct? How do I go bout adding the above code into the onclick event? Hi, New to javascript. Doing web page with ASP/VB.NET. Have text boxes for UI on page. Two command buttons - Submit (for db update) and Cancel. I need the Cancel button to prompt the user to verify cancellation. Need OK/Cancel buttons on alert. If user selects Cancel-no action. If user selects OK then I want the text boxes cleared of user text input and focus returned to first text box. I think this may be the code but do not know how to apply it. function Clear() { var res=window.confirm("Please confirm cancellation-text boxes will be cleared"); if(res==true) { document.getElementById("StrtDte").value=""; document.getElementById("EndDte").value=""; document.getElementById("txtProjRegHrsAl").value=""; document.getElementById("txtProjOTHrsAl").value=""; document.getElementById("ddlRAS").focus(); } } Is this code valid or invalid for the events I need? How do I set it to fire when user clicks the ASP Cancel button? Thanks, John hi, i need to be able to take the values from two text boxes and change the location of a sprite on my canvas, i've searched the internet and it doesnt really explain how to do it for me. here is my code: x: <input type="text" name="x" id="x"/><br /> y: <input type="text" name:"y" id="y"/><br /> <input type="submit" value="Submit" onClick="ChangeCo()" /><br /> function ChangeCo() { } and i need the function to take the x and y values from the text boxes and change the values of my variables: var block_x; var block_y; block_x = 290; block_y = 70; Thankyou in advance I'm having an issue where a programmatic click event is not behaving the same way the cursor click event is. A cursor click returns the correct object from GetObject(). The programmatic click triggered by a USB device is returning undefined from GetObject(). How can this be resolved? Edit: It appears that it does not recognize eval(document.getElementById(gButtonList[gButtonId])).onclick(); as an event. Why is this? How can I get it to recognize it? Edit2: Resolved it myself. See green text below. TestPage.htm: Code: <script language="JavaScript" src="../bin/USBHelperFile.js"></script> <script language="JavaScript" type="text/JavaScript"> function BuildButtons() { for (var i = 0; i < testArray.length; i++) { // Create Div [Buttons created programmatically] var divNode = document.createElement('div'); divNode.id = 'div' + i; divNode.onclick= ClickFunction; etc... } } function ClickFuntion(nodeButtonNum) { alert(GetObject()); Returns the index for a cursor click. Returns undefined for the programmatic click triggered by the USB device } function GetObject() { var node = event.srcElement; return node; } </script> USBHelperFile.js: Code: This JS file works with a USB hardware device that can navigate through divs and click them when they have focus. function HelperFunction(keyCommand) { switch (keyCommand) { case: "click": // eval(document.getElementById(gButtonList[gButtonId])).onclick(); var target = eval(document.getElementById(gButtonList[gButtonId])); target.fireEvent("onclick"); break; } } I've got a checkbox that, when clicked, displays new text inputs. However, when I "uncheck" the box, the fields don't disappear unless I reload the entire page. What code can I add to reset the box to null when it is unchecked? Here's the function code I have: Code: <script> function showUserReg() { document.getElementById("userReg").style.display = "inline"; } </script> And here's the inline code: Code: <input type="checkbox" name="additional" value="userRegister" onclick="showUserReg()"/> Yes! Register me now!<br/> <span id = "userReg" style="display:none"> <table class="nobord" align="center"> <tr> <td>Choose a username:</td> <td><input type="text" name="username" size="35"/></td> </tr> <tr> <td>Choose a password:</td> <td><input type="password" name="password" size="35" maxlength="20"/></td> </tr> <tr> <td>Confirm password:<font color="red">*</font></td> <td><input type="password" name="password" size="35" maxlength="20"/></td> </tr> </table> </span> Thanks for any help. here the deal ,,I've solved all but this problem in my script i have my page setup with 1 iframe and the main html the code below is exactly how the page will show up in the iframe, you can copy and paste the whole thing and save it as a htm file to view if needed.. I need a way to catch the clicks that happen within the iframe but from the main section of the page..heres why! this is inserted at the top of the page if(top.location==self.location){top.location="RefESI_search.asp";} just above top.document.reset.RefCat.value= I can get the page to load even with this in the iframes ..but for the purposes of this i left it out so the page would load ok for anyone thats gonna try and help . theres only 2 links in the code.. hopefully whatever will hopefully solve this problem will be able to tell which links were clicked,and i can can point them to the apropriate links. I've looked thru alot of the threads so i know there are some extremely brite ppl in here that can knock this problem out of the ball park very easily.. you can grab the styles sheet from here https://www.docs.sony.com/reflib/Style_esi.css Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Ref_Lib_Results</title> <link rel="stylesheet" type="text/css" href="home.css"/> <script language="javascript"> top.document.reset.RefCat.value="Home Receiver"; top.document.reset.NarrowRef.value="Good"; top.document.reset.criteria.value="stra"; top.document.reset.searchscope.value="model"; top.document.reset.companyscope.value="SONY"; top.document.reset.company.value="SONY"; if(""==""){top.reset();} function popUp(URL,Name) { var day = new Date(); var id = "page" + Name; window.open(URL, id, "toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=600,height=600"); } function launchjsmanuals(flag, x, y, z, id) { //var myTypeLib = new ActiveXObject("Scriptlet.Typelib"); //var GUID = new String(myTypeLib.guid).substr(1,8); //var endguid = new String(myTypeLib.GUID).substr(25,10); if((x.indexOf("CHM")!=-1) || (x.indexOf("chm")!=-1)){ alert("You will be prompted to download a file\n\nClick Open - Do NOT click Save"); } var whnd = "page" + id; //+ GUID + endguid; var URL = '_manualusage.asp?flag='+flag+'&manual=' + x + '&user=' + y + z + '&manualid=' + id; if(flag!=""){ whnd = window.open(URL,whnd, "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=560,height=600"); }else{ whnd = window.open(URL,"Loader", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=560,height=600"); } } function emailit(id, url,name,type,filesize,model,email,custname,cs3event,user){ var namestring = name; var re = new RegExp('&','gi'); namestring = namestring.replace(re,'and'); name = namestring; var xurl = "/srvs/common/email.asp?id="+id+"&emailurl="+url+"&title=" + name + "&type="+type+"&model=" + model + "&filesize=" + filesize + "&email=" + email + "&custname=" + custname + "&convid=" +cs3event + "&user=" + user; popUp(xurl,id); } function NarrowSearch(what,value,cat){ switch(what){ case "Category": parent.document.SearchForm.RefCat.value=value; parent.document.SearchForm.NarrowRef.value="Good"; parent.document.SearchForm.submit() break; case "Model": if("Home Receiver"!=""){ parent.document.SearchForm.RefCat.value="Home Receiver"; } parent.document.SearchForm.criteria.value=value; parent.document.SearchForm.searchscope.value="model"; parent.document.SearchForm.NarrowRef.value="Good"; parent.document.SearchForm.submit() break; case "ONLY": parent.document.SearchForm.criteria.value=value; parent.document.SearchForm.searchscope.value="model"; parent.document.SearchForm.RefCat.value=cat; parent.document.SearchForm.NarrowRef.value="Only"; parent.document.SearchForm.submit() break; case "ALL": parent.document.SearchForm.criteria.value=value; parent.document.SearchForm.RefCat.value=cat; parent.document.SearchForm.NarrowRef.value="ALL"; parent.document.SearchForm.submit() break; } } </script> </head> <body> <div id="results"> <div style="height: 400px;border-bottom:1px solid black;" class="modelblock"> <div style="margin-left:20px; margin-right:15px; margin-top:10px; font-size:10pt"> <span style="float:Right;margin-top:10px;text-align:right"> <table border=0 cellpadding=0 cellspacing=0><tr><td> <div style="background:silver;color:black;font-size:10px;padding:2px;border:1px solid gray;cursor:pointer" onclick="javascript:NarrowSearch('ALL','stra','Home Receiver')">Display All Models</div> </td><td> </td><td><div style="width:40px;background:silver;color:black;font-size:10px;padding:2px;border:1px solid gray;cursor:pointer;text-align:center" onclick="javascript:history.go(-1)">Back</div></td></tr></table></span><b>Your search of "<font color=green>stra</font>" matches 66 Models in the Home Receiver category.</b><br><br>Please select the specific model to continue:<table border=0 cellpadding=0 cellspacing=2><tr><td><a class="modellink" onMouseOver="this.className='modellinkhover'" onMouseOut="this.className='modellink'" onclick="javascript:NarrowSearch('ONLY','STRAV1000','Home Receiver')"><b>STRA</b>V1000</a></td><td width=15px></td><td><a class="modellink" onMouseOver="this.className='modellinkhover'" onMouseOut="this.className='modellink'" onclick="javascript:NarrowSearch('ONLY','STRAV1010','Home Receiver')"><b>STRA</b>V1010</a></td><td width=15px></td></tr></table</div></div></div> <iframe name="Loader" id="Loader" src="blank.htm" style="display:none;height:150px;width:100%;border:1px solid silver"></iframe> <a onclick="document.getElementById('Loader').style.display='';">*</a> <script language="javascript"> //alert(parent.IQ.location.href); </script> </body> </html> Hi I would like to use javascript to control what tooltip displays when a tab is rolled over depending on which tab was clicked. Code: <li id='1tab_1a' class='selected'><a id='1link_1a' title="Customer Info Screen"><span >Customer Info</span></a></li> <li id='1tab_1b' ><a id='1link_1b' title="Order Detail" ><span>Order</span></a></li> <li id='1tab_1c' ><a id='1link_1c' title="Phone Detail" ><span>Phone: 7093521232</span></a></li> For example when the Customer Info tab is selected I would like the tooltips to be like above but when Order is the tab selected I would like the tooltip to say Customer Info Detail, Order Detail Screen, and Phone Detail. How could I use an onclick event to control what tooltip is being displayed depending on which tab is selected? I have about 20 sets of customer info and sometimes not everyone contains all of the tabs and I would also like to be able to add more customers. Hi, I am trying to get my onclick event to handle both of the function below. I want the event to return false (stop executing) if any of the two functions return false. Here is my code: Code: function isNumeric(elem, helperMsg){ var numericExpression = /[0-9]+/; if(!elem.value.match(numericExpression)){ SaveRecord(); return true; }else{ alert("You cannot enter numbers in the Comments field."); return false; } } function lengthRestriction(elem, min, max){ var x = elem.value; if(x.length >= min && x.length <= max){ SaveRecord(); }else{ alert("Please enter between " +min+ " and " +max+ " characters in the Issue Number field"); } } Please help me. Thank you. I was trying to help someone on another forum and seem to have run into a brick wall. The main problem that has got me stumped at the moment is that clicking on the images in the 1st tab work fine. However the subsequent tab selections and clicks do not change the "bigImage" correctly (not at all). Perhaps some other more experienced forum members can identify what I doing wrong at this time. I believe it is in my set-up of the onclick events in the "onload=" section, but I not the best at this event stuff yet! Code: var sel, tmp, elem; var j=0; for (var i=0; i<imgGroupArray.length; ++i) { sel = document.getElementById('imgGroup'+i).getElementsByTagName('img'); while (elem=sel[j++]) { elem.onclick = function() { setBigImage(this.src); } } } Here is the full code that 'almost' works: Code: <!DOCTYPE HTML> <html> <head> <title> Tab Gallery </title> <style type="text/css"> li { display:inline; list-style-type:none; border:1px solid blue; margin:3px; } .imgBlock { display:none; } </style> <script type="text/javascript"> // From: http://www.webdeveloper.com/forum/showthread.php?t=250787 var baseURL = 'http://www.nova.edu/hpd/otm/pics/4fun/'; var imgGroupArray = [ ['11.jpg','12.jpg','13.jpg','14.jpg','15.jpg'], ['21.jpg','22.jpg','23.jpg','24.jpg','25.jpg'], ['31.jpg','32.jpg','33.jpg','34.jpg','35.jpg'], ['41.jpg','42.jpg','43.jpg','44.jpg','45.jpg'], ['51.jpg','52.jpg','53.jpg','54.jpg','55.jpg'], ['61.jpg','62.jpg','63.jpg','64.jpg','65.jpg'] // NOTE: No comma after last entry ]; function tabGroup(which) { var sel = document.getElementById('imgGroup').getElementsByTagName('div'); for (var i=0; i<sel.length; ++i) { sel[i].style.display = 'none'; } var tmp = 'imgGroup'+which; // alert(tmp); document.getElementById(tmp).style.display = 'block'; } function setBigImage(info) { // alert(info); document.getElementById('bigImage').src = info; } window.onload = function() { var img; for (var i=0; i<imgGroupArray.length; ++i) { for (var j=0; j<imgGroupArray[i].length; ++j) { img = document.createElement('img'); img.setAttribute('src', baseURL+imgGroupArray[i][j]); img.setAttribute('height','100px'); img.setAttribute('width','75px'); document.getElementById('imgGroup'+i).appendChild(img); } } // Following modified from: // http://www.codingforums.com/showthread.php?t=102896&highlight=addevent+onclick var sel, tmp, elem; var j=0; for (var i=0; i<imgGroupArray.length; ++i) { sel = document.getElementById('imgGroup'+i).getElementsByTagName('img'); while (elem=sel[j++]) { elem.onclick = function() { setBigImage(this.src); } } } tabGroup(0); } </script> </head> <body> <div id="tabMenu"> <div style="float:left"> <li onclick="tabGroup(0)">Tab 1</li> <li onclick="tabGroup(1)">Tab 2</li> <li onclick="tabGroup(2)">Tab 3</li> <li onclick="tabGroup(3)">Tab 4</li> <li onclick="tabGroup(4)">Tab 5</li> <li onclick="tabGroup(5)">Tab 6</li> </div><br> <div id="imgGroup" style="width:300px; height:300px; border:1px solid red; float:left"> <div id="imgGroup0" class="imgBlock"></div> <div id="imgGroup1" class="imgBlock"></div> <div id="imgGroup2" class="imgBlock"></div> <div id="imgGroup3" class="imgBlock"></div> <div id="imgGroup4" class="imgBlock"></div> <div id="imgGroup5" class="imgBlock"></div> </div> <div id="bigImageDiv" style="width:250px; height:300px; border:1px solid red; float:left;"> <img id="bigImage" src="" alt="bigImage here!"> </div> <br style="clear:both"> </div> </body> </html> I assum the following html code: <div id="id1" onclick="click()">A<div> <div id="id2" onclick="click()">B<div> Do you know how to get ID = id2 when I onclick on A? The following coding works in Konqueror 3.5.10 on Ubuntu 8.04.3 LTS but not on Firefox 3.0.10 Linux/3.5.7 XP, Opera 10.10 Linux or IE8 XP. I can't see why but it may be to do with the recursion (showtable calls onclick calls addit which calls showtable ...). Somehow it is not seeing the addit routine the second time round. It is meant just to add a line. Eventually it needs to be a complex table but this is for illustration. There are other ways to solve this but this would be the simplest - if it worked! What happens is that one line is added OK but then it chokes. This is what makes me think it is the recursion but I can't see otherwise how to make it write the updated text. I realise I should have a document.close() in it as well and I have tried adding <![CDATA[ ... ]]> as well. Other than in Konqueror, it gives an error message saying object not found (in IE8) or more explicitly: Code: function onclick(event){ addit(4); } with 'addit is not defined' in Firebug. In Konqueror it works sweetly. 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' xml:lang='en' lang='en'> <head> <script language='Javascript' type='text/javascript'> if(typeof(sections) == 'undefined'){ var sections=['Text 0','Text 1','Text 2']; } function addit(ilocal){ sections.splice(sections.length,0,'Text '+ilocal); showtable(); } function showtable(){ var i,j,ip1; for(i=0;i<sections.length;i++){ ip1=i+1; document.write('Section ',i,': ',sections[i],'<br>'); } document.write("<input type='button' value='Add' onClick='addit(",ip1,")' /><br>"); for(j=0;j<sections.length;j++){document.write(sections[j]," ");} } </script> </head><body> <script language='Javascript' type='text/javascript'> showtable(); </script> </body> </html> Clues would be very much appreciated - my baldness coefficient is increasing daily! |