JavaScript - Get All 10 Digit Numbers In Page And Give An Onclick Event To It
Dear friends,
I was looking for some help on getting all the ten digits mobile numbers in the current webpage and assign an onclick event to it just by a click of a button. Likewise, Suppose there are mobile numbers Code: <p>9876543210 Blah....Blah...Any other content.9654321000</p> <input type="button" value="Get 10 digit mobile numbers" onclick="getnumbers();" /> in the current webpage. and the user clicks on a button. Then all the ten digit mobile numbers(in this case two numbers 9876543210 and 9654321000) gets the html as Code: <p><span onclick="openpopup('9876543210')">9876543210</span> Blah....Blah...Any other content.<span onclick="openpopup('9654321000')">9654321000</span></p> I am a PHP guy and probably suck at JS. Tried experimenting with the following code but didn't got it to work. Code: var html = document.getElementsByTagName('body')[0].innerHTML; and match = new RegExp("/\d{10}/"); replaceWith = "<span style='text-decoration:underline;' onclick=\"openpopup('--NUMBER--')\" >--NUMBER--</span>", replaced = html.replace(pattern,replaceWith); Please get me out of this glitch as it is getting harder for me to do it. Similar TutorialsHi, I am trying to modify this poetry generator script: Poem Generator .js-file: PHP Code: // Poem Generator JavaScript // Keith Enevoldsen, thinkzone.wlonk.com random_count=0; nsentences=0; nwords1=0; nwords2=0; nwords3=0; nwords4=0; nwords5=0; nwords6=0; nwords7=0; nwords8=0; nwords9=0; function init(form) { form.Samples.selectedIndex=1; generate_input(form, form.Samples.options[form.Samples.selectedIndex].text); make_poem(form); } function generate_input(form, sample_name) { form.title1.value = "Concrete Nouns"; form.title2.value = "Abstract Nouns"; form.title3.value = "Transitive Verbs"; form.title4.value = "Intransitive Verbs"; form.title5.value = "Adjectives"; form.title6.value = "Adverbs"; form.title7.value = ""; form.title8.value = ""; form.title9.value = "Interjections"; form.sentences.value = "The 5 1 6 3s the 1." +"\n5, 5 1s 6 3 a 5, 5 1." +"\n2 is a 5 1." +"\n9, 2!" +"\n1s 4!" +"\nThe 1 4s like a 5 1." +"\n1s 4 like 5 1s." +"\nWhy does the 1 4?" +"\n4 6 like a 5 1." +"\n2, 2, and 2." +"\nWhere is the 5 1?" +"\nAll 1s 3 5, 5 1s." +"\nNever 3 a 1." ; if (sample_name == "Sea") { form.list1.value = "sea\nship\nsail\nwind\nbreeze\nwave\ncloud\nmast\ncaptain\nsailor\nshark\nwhale\ntuna\nseashell\npirate\nlad\ngirl\ngull\nreef\nshore\nmainland\nmoon\nsun"; form.list2.value = "adventure\ncourage\nendurance\ndesolation\ndeath\nlife\nlove\nfaith"; form.list3.value = "command\nview\nlead\npull\nlove\ndesire\nfight"; form.list4.value = "travel\nsail\nwave\ngrow\nrise\nfall\nendure\ndie"; form.list5.value = "big\nsmall\nold\ncold\nwarm\nsunny\nrainy\nmisty\nclear\nstormy\nrough\nlively\ndead"; form.list6.value = "swiftly\ncalmly\nquietly\nroughly"; form.list7.value = ""; form.list8.value = ""; form.list9.value = "o\noh\nooh\nah\nlord\ngod\nwow\ngolly gosh"; } else if (sample_name == "City") { form.list1.value = "street\nsidewalk\ncorner\ndoor\nwindow\nhood\nslum\nskyscraper\ncar\ntruck\nguy\ngirl\njob\nflower\nlight\ncigarette\nrain\njackhammer\ndriver\nworker"; form.list2.value = "action\nwork\nnoise\ndesolation\ndeath\nlife\nlove\nfaith\nanger\nexhaustion"; form.list3.value = "get\ngrab\nshove\nlove\ndesire\nbuy\nsell\nfight\nhustle\ndrive"; form.list4.value = "talk\ngab\nwalk\nrun\nstop\neat\ngrow\nshrink\nshop\nwork"; form.list5.value = "big\nsmall\nold\nfast\ncold\nhot\ndark\ndusty\ngrimy\ndry\nrainy\nmisty\nnoisy\nfaceless\ndead"; form.list6.value = "quickly\nloudly\ncalmly\nquietly\nroughly"; form.list7.value = ""; form.list8.value = ""; form.list9.value = "o\noh\nooh\nah\nlord\ngod\ndamn"; } else { clear_all(form); } form.outtext.value = ""; count_all_lines(form); } function clear_all(form) { form.Samples.value = "-"; form.title1.value = ""; form.title2.value = ""; form.title3.value = ""; form.title4.value = ""; form.title5.value = ""; form.title6.value = ""; form.list1.value = ""; form.list2.value = ""; form.list3.value = ""; form.list4.value = ""; form.list5.value = ""; form.list6.value = ""; form.list7.value = ""; form.list8.value = ""; form.list9.value = ""; form.sentences.value = ""; form.outtext.value = ""; count_all_lines(form); } function count_all_lines(form) { nwords1 = count_lines(form.list1); nwords2 = count_lines(form.list2); nwords3 = count_lines(form.list3); nwords4 = count_lines(form.list4); nwords5 = count_lines(form.list5); nwords6 = count_lines(form.list6); nwords7 = count_lines(form.list7); nwords8 = count_lines(form.list8); nwords9 = count_lines(form.list9); nsentences = count_lines(form.sentences); } function random(maxnum) { r = Math.floor(Math.random() * maxnum) + 1; if (r > maxnum) r = maxnum; return r; } function count_lines(txt) { str = txt.value; len = str.length; nword = 1; for (i = 0; i < len; i++) { if (str.charAt(i) == "\n") { nword++; } } if (str.charAt(len-1) == "\n") nword--; return nword; } function get_line(str, lnum) { len = str.length; iline = 1; ichar = 0; jchar = -1; for (i = 0; i < len; i++) { if (str.charAt(i) == "\n") { iline++; if (iline == lnum) { ichar = i + 1; } else if (iline == (lnum + 1)) { jchar = i - 1; if (str.charAt(jchar) == "\r") { jchar--; } break; } } } if (jchar < 0) jchar = len - 1; // Note: Use loop because substr() doesn't work consistently on old browsers s = ""; for (i = ichar; i <= jchar; i++) { s = s + str.charAt(i); } return s; } function initial_cap(str) { // Note: Use loop because substr() doesn't work consistently on old browsers len = str.length; s = ""; for (i = 0; i <= len; i++) { if (i == 0) { s = s + str.charAt(i).toUpperCase(); } else { s = s + str.charAt(i); } } return s; } function make_poem(form) { form.outtext.value = ""; count_all_lines(form); nlines = random(4) + 1; for (ilin = 1; ilin <= nlines; ilin++) { make_poem_line(form) } } function make_poem_line(form) { pattern = get_line(form.sentences.value, random(nsentences)); lenpat = pattern.length; for (ichr = 0; ichr < lenpat; ichr++) { chr = pattern.charAt(ichr); // If the pattern contains a digit n, then pick a random word from list n if ((chr >= '1') && (chr <= '9')) { if (chr == '1') { wrd = get_line(form.list1.value, random(nwords1)); } else if (chr == '2') { wrd = get_line(form.list2.value, random(nwords2)); } else if (chr == '3') { wrd = get_line(form.list3.value, random(nwords3)); } else if (chr == '4') { wrd = get_line(form.list4.value, random(nwords4)); } else if (chr == '5') { wrd = get_line(form.list5.value, random(nwords5)); } else if (chr == '6') { wrd = get_line(form.list6.value, random(nwords6)); } else if (chr == '7') { wrd = get_line(form.list7.value, random(nwords7)); } else if (chr == '8') { wrd = get_line(form.list8.value, random(nwords8)); } else if (chr == '9') { wrd = get_line(form.list9.value, random(nwords9)); } else { wrd = ''; } // Capitalize first letter of sentence if (ichr == 0) { wrd = initial_cap(wrd); } form.outtext.value = form.outtext.value + wrd; } else { form.outtext.value = form.outtext.value + chr; } } form.outtext.value = form.outtext.value + "\n"; } And the .html: PHP 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=windows-1252"> <title>Poem Generator</title> <meta name="Description" content="Poem Generator"> <meta name="Keywords" content="Poem Generator"> <meta name="robots" content="all"> <link rel="icon" href="http://thinkzone.wlonk.com/thinkzone_icon.png"> <link rel="stylesheet" href="Poem%20Generator_files/style.css" type="text/css"> <script type="text/javascript" src="Poem%20Generator_files/PoemGen.js"></script> </head> <body onload="init(document.form)" style="background-color: #99CC99;"> <div class="bodydiv" style="background-color: #99CC99;"> <div align="center"> <a href="http://thinkzone.wlonk.com/index.htm"><img alt="thinkzone.wlonk.com" src="Poem%20Generator_files/thinkzone_wlonk_trans.png"></a> <h2>Poem Generator</h2> <p>This makes random poems. First, it randomly selects sentence patterns. Then, wherever the pattern has a number, it randomly selects a word from one of the numbered word lists. You can either choose one of the sample sets of words and sentence patterns, or you can enter your own words and sentence patterns.</p> <form name="form" id="form" action=""> <input value="Make Poem" onclick="make_poem(this.form)" type="button"><br> <textarea cols="70" rows="6" name="outtext">Grow swiftly like a clear wind. The reef falls like a rough sun. </textarea><br> <br> <b>Word Lists</b><br> Samples: <select name="Samples" onchange="generate_input(this.form, this.options[this.selectedIndex].text)"> <option>-</option> <option selected="selected">Sea</option> <option>City</option> </select> <input value="Clear Lists" onclick="clear_all(this.form)" type="button"><br> <table> <tbody> <tr> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> <th>6</th> <th>7</th> <th>8</th> <th>9</th> </tr> <tr> <td><textarea cols="12" rows="2" name="title1">Concrete Nouns</textarea></td> <td><textarea cols="12" rows="2" name="title2">Abstract Nouns</textarea></td> <td><textarea cols="12" rows="2" name="title3">Transitive Verbs</textarea></td> <td><textarea cols="12" rows="2" name="title4">Intransitive Verbs</textarea></td> <td><textarea cols="12" rows="2" name="title5">Adjectives</textarea></td> <td><textarea cols="12" rows="2" name="title6">Adverbs</textarea></td> <td><textarea cols="12" rows="2" name="title7"></textarea></td> <td><textarea cols="12" rows="2" name="title8"></textarea></td> <td><textarea cols="12" rows="2" name="title9">Interjections</textarea></td> </tr> <tr> <td><textarea cols="12" rows="10" name="list1">sea ship sail wind breeze wave cloud mast captain sailor shark whale tuna seashell pirate lad girl gull reef shore mainland moon sun</textarea></td> <td><textarea cols="12" rows="10" name="list2">adventure courage endurance desolation death life love faith</textarea></td> <td><textarea cols="12" rows="10" name="list3">command view lead pull love desire fight</textarea></td> <td><textarea cols="12" rows="10" name="list4">travel sail wave grow rise fall endure die</textarea></td> <td><textarea cols="12" rows="10" name="list5">big small old cold warm sunny rainy misty clear stormy rough lively dead</textarea></td> <td><textarea cols="12" rows="10" name="list6">swiftly calmly quietly roughly</textarea></td> <td><textarea cols="12" rows="10" name="list7"></textarea></td> <td><textarea cols="12" rows="10" name="list8"></textarea></td> <td><textarea cols="12" rows="10" name="list9">o oh ooh ah lord god wow golly gosh</textarea></td> </tr> </tbody> </table> <br> <b>Sentence Patterns</b><br> <textarea cols="40" rows="10" name="sentences">The 5 1 6 3s the 1. 5, 5 1s 6 3 a 5, 5 1. 2 is a 5 1. 9, 2! 1s 4! The 1 4s like a 5 1. 1s 4 like 5 1s. Why does the 1 4? 4 6 like a 5 1. 2, 2, and 2. Where is the 5 1? All 1s 3 5, 5 1s. Never 3 a 1.</textarea></form> <p>You can see the JavaScript source code in PoemGen.htm and PoemGen.js.</p> </div> <hr> <div align="center"> <a href="http://thinkzone.wlonk.com/index.htm">Keith Enevoldsen's Think Zone</a> </div> </div> </body></html> What I want to do is add more word lists. This of course is easy in principle - I can just continue the lists like: form.title9.value = ""; form.title10.value = ""; form.title11.value = ""; - and so on. The problem is that, in the "sentence patterns", I cannot use numbers with two digits to refer to the word lists. Then it thinks I mean 1+0 and 1+1 instead of 10 and 11. How can I allow this? I have heard about using regular expressions to "capture the number by its word boundary" - is this a good solution? If yes, can someone please explain to me how to do it? (I have tried special characters like @,#,$ and more as well as Russian and Greek letters. This makes the script unable to generate poems.) Thank you. Reply With Quote 12-28-2014, 08:31 PM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Convert the string values which are concatenated by + (e.g. "2" + "5" = 25) into numbers (e.g. 2+5 = 7) by using the Number() method, or another way is to multiply the value by 1. But you are using string values if (chr == '1') { quite unnecessarily. Remove the quote marks to make them into numbers. "1" is a string value. 1 is a number Obviously chr = pattern.charAt(ichr); only captures a single numeric chararcter. You can extract two-digit numbers from a string just by removing all non-digits var x = str.replace(/[^0-9]/g,""); // strip all characters but digits That of course assumes that there is only one number in the string. Haikus are easy But sometimes they don't make sense. Refrigerator. Can someone please help me generate a series of 13 digit numbers and output them to a text file. I'm really desperate here. Thanks guys. Alright, so I'm working on a script, and I'm simply using the following code: document.getElementById("element").onclick = alert("hello"); When I load the page, the alert fires instantaneously. I'm completely stumped. I've checked everything in my not too extensive Javascript file, and it looks fine. What common errors could cause this? I have a html page with a lot of thumbnails. The idea is that when the user clicks on an image the onClick event is to display another detailed form and deliver to that form the name of the image in a variable. In the detailed php-form there is a query to MySQL to retrieve a record. The record will be retrieved by a Query based on the name of the picture. Apparently the PHP cannot do the job. I had an idea to make the thumbnail page as a form and to use use a hidden field with the thummnail name which should be carried on with the $_POST array through the submit button but i do not want to have a submit button. The more elegant way is just by clicking the picture the detailed page is opened and the variable is transferred where my php code can make use of the variable for the query. I have never used java before so you have to excuse for the lack of knowledge. Can anyone gie me an idea how i should implemnt this Best regards MSP I have a html page with a lot of thumbnails. The idea is that when the user clicks on an image the onClick event is to display another detailed form and deliver to that form the name of the image in a variable. In the detailed php-form there is a query to MySQL to retrieve a record. The record will be retrieved by a Query based on the name of the picture. Apparently the PHP cannot do the job. I had an idea to make the thumbnail page as a form and to use use a hidden field with the thummnail name which should be carried on with the $_POST array through the submit button but i do not want to have a submit button. The more elegant way is just by clicking the picture the detailed page is opened and the variable is transferred where my php code can make use of the variable for the query. I have never used java before so you have to excuse for the lack of knowledge. Can anyone gie me an idea how i should implemnt this Best regards MSP Hi, I want to when I open a web page , my program detect all the "digit numbers" and display all of them for me. I don't know exactly what do I do? Thanks. Regards. 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 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? 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. 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> 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. 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> 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? 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; } } 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 very new to this thread so i will try to be as clear as possible i m try to create a website where i n have inserted a menu (this menu template i found online which is free.) Code: <div id="menu"> <ul class="menu"> <li><a href="#" class="parent"><span>Home</span></a> <li><a href="#"><span>Cities</span></a> <div><ul> <li><a href="#"><span>Pune</span></a></li> <li><a href="#"><span>Mumbai</span></a></li> <li><a href="#"><span>Delhi</span></a></li> <li><a href="#"><span>Madras</span></a></li> </ul></div> </li> <li><a href="#"><span>Login</span></a></li> <li><a href="#"><span>About Us</span></a></li> <li class="last"><a href="#"><span>Contact Us</span></a></li> </ul> </div> what i am trying to do here is when i click on city (one of the menu) it should read the values from database table (the table name is cityCode. this table contains two rows first cityName and second cityCode) n depending on which city is selected it should retrieve the code of that city. also where to save that retried value because i want to use that retried code to extract value from another table. I am using 2 ajax functions in the program. One for login and one for logout. The login one is showUser which is working correctly by using the form onsubmit method, however the logout button (IN BOLD) onclick method is not working. Pls help. Code: <form onsubmit="showUser(document.getElementById('uid').value,document.getElementById('pass').value);return false;" > <div id="txt"><b>Enter your username </b> <input type="text" name= "username" id="uid"> <br> <b>Enter your password</b> <input type="password" name="pass" id="pass"> <br></div> <div id="txt1" style="display : none">help</div> <input type="submit" value="Login" /> <input type="button" onclick="logout(document.getElementById('uid').value); return false; " name="logout" value="Logout" /> <input type="button" value="Register" class="register"/> </form> I'm trying to figure out a way to put this in all js code with the onclick event handlers and the parameters. I have 3 links that switch the style of my page. Right now I have them working with inline event handlers. Here are my code snippets below. HTML: Code: <head> <link rel="stylesheet" href="style1.css" type="text/css" title="style1"/> <link rel="alternate stylesheet" type="text/css" href="style2.css" title="style2" /> <link rel="alternate stylesheet" type="text/css" href="style3.css" title="style3" /> </head> <div class="styleLinks"> <a href="#" id="style1" onclick="setStyleSheets('style1'); return false;">Style 1</a> <a href="#" id="style2" onclick="setStyleSheets('style2'); return false;">Style 2</a> <a href="#" id="style3" onclick="setStyleSheets('style3'); return false;">Style 3</a> </div> JS: Code: function setStyleSheets(title) { //set styles and set cookie var i; var attribute; var today = new Date(); var expDate = new Date(today.getTime() + 7*24*60*60*1000); var styleSelected = ""; if (title=="style2"){ styleSelected = "style2"; } else if (title=="style3"){ styleSelected = "style3"; } for(i=0; (attribute = document.getElementsByTagName("link")[i]); i++) { if(attribute.getAttribute("rel").indexOf("style") != -1 && attribute.getAttribute("title")) { attribute.disabled = true; if(attribute.getAttribute("title") == title) attribute.disabled = false; SetCookie ('style', styleSelected, expDate, "/"); } } } I am try to make a form that appears to be multi page. I am trying to use a button to hide one div and display another at the same time my script is head Code: <script language=javascript type='text/javascript'> function hidediv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){//if they are 'see' divs if (document.getElementById) // DOM3 = IE5, NS6 divs[i].style.visibility="hidden";// show/hide else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'hidden'; else // IE 4 document.all.hideShow.divs[i].visibility = 'hidden'; } } } function showdiv(pass) { var divs = document.getElementsByTagName('div'); for(i=0;i<divs.length;i++){ if(divs[i].id.match(pass)){ if (document.getElementById) divs[i].style.visibility="visible"; else if (document.layers) // Netscape 4 document.layers[divs[i]].display = 'visible'; else // IE 4 document.all.hideShow.divs[i].visibility = 'visible'; } } } </script> body Code: <form name="PublicOrderPage" action="save_client_information.php" onsubmit="return validateForm()" method="post"> <div id="div1" style="width:600px; height: auto;background: yellow;"> <table width="600" border="0"> <tr> <legend><h3 style="padding-left:172.5px;">Required Client Information</h3></legend> </tr> <tr> <td style="padding-left:25px;"><b>Name:</b></td> <td><input type="text" name="client_name" id="client_name" value="<?php echo $_POST['client_name']; ?>" /></td> <td style="padding-left:25px;"><b>Home Phone:</b></td> <td><input type="text" name="client_home_phone" id="client_home_phone" value="<?php echo $_POST['client_home_phone']; ?>" /></td> </tr> </table> <br/> <table width="270" border="0"> <tr> <td style="padding-left: 180px;"><b>Email:</b></td> <td><input type="text" name="client_email" id="client_email" value="<?php echo $_POST['client_email']; ?>" /></td> </tr> </table> <br/> <table> <tr> <td style="padding-left:280px;"><input name="save_client_info" type="button" value="Next" onclick="hidediv('1');shwodiv('2');" > </td> </tr> </table> </div> <div id="div2" style="width:600px; height: auto;background: yellow; "> <table width="600" border="0"> <tr> <legend><h3 style="padding-left:172.5px;">Required Site Information</h3></legend> </tr> <tr> <td style="padding-left:25px;"><b>Site Street:</b></td> <td><input type="text" name="site_street" id="site_street" value="<?php echo $_POST['site_street']; ?>" /></td> <td style="padding-left:25px;"><b>Site City:</b></td> <td><input type="text" name="site_city" id="site_city" value="<?php echo $_POST['site_city']; ?>" /></td> </tr> </table> <br/> <legend><h3>Inspection Type</h3></legend> <table width="270" border="0"> <table width="602" border="0"> <tr> <td width="252"><input type="checkbox" name="cb_full_home" id="cb_full_home" <?php if ($_POST['cb_full_home']) echo 'checked="checked"'; ?> /> Full Home</td> <td width="150"><input type="checkbox" name="cb_4_point" id="cb_4_point" <?php if ($_POST['cb_4_point']) echo 'checked="checked"'; ?> /> 4 Point</td> </tr> <tr> <td ><input type="checkbox" name="cb_condominium" id="cb_condominium" <?php if ($_POST['cb_condominium']) echo 'checked="checked"'; ?> /> Condominium</td> <td ><input type="checkbox" name="cb_wind_mit" id="cb_wind_mit" <?php if ($_POST['cb_wind_mit']) echo 'checked="checked"'; ?> /> Wind Mit</td> </tr> <tr> <td ><input type="checkbox" name="cb_roof_cert" id="cb_roof_cert" <?php if ($_POST['cb_roof_cert']) echo 'checked="checked"'; ?> /> Roof Cert</td> <td ><input type="checkbox" name="cb_drywall" id="cb_drywall" <?php if ($_POST['cb_drywall']) echo 'checked="checked"'; ?> /> Drywall</td> </tr> <tr> <td><input type="checkbox" name="cb_reinspect" id="cb_reinspect" <?php if ($_POST['cb_reinspect']) echo 'checked="checked"'; ?> /> Re-Inspect</td> <td><input type="checkbox" name="cb_followup" id="cb_followup" <?php if ($_POST['cb_followup']) echo 'checked="checked"'; ?> /> Follow-Up</td> </table> <img src="CaptchaSecurityImages.php" /> Security Code: <input id="security_code" name="security_code" type="text" /> <br /> <input name="save_client_info" type="submit" value="Save" /> </div> </form> When the next button is used I would Like to Hide Div1 And Display Div2 so that it looks as if it is a new page. Any help would be greatly appreciated. |