JavaScript - Tampermonkey Script Problem
Hi,
I'm writing my first tampermonkey script, which is also my first javascript program, and I have run into a bit of a problem - can someone help? First, I'll tell say what I am trying to do and what I have done: I regularly visit a web page that has a table of text and numbers on it. I wanted to do some calculations on the numbers in each row and add a column to the table with the result of the calculation. So far so good - that works. However, the page in question has a javascript component on it that is used for sorting the table by column if the table heading is clicked on and I want the new column to behave in the same way. That bit does not work and I cannot see how to change it. The javascript in the source page looks a like this: <code> <script type='text/javascript' src='http://thesite.com/_javascript/sortable.js?2' language='javascript'></script> <script type="text/javascript"> var st = new SortableTable(document.getElementById("mytable"), ["String", "String", "Number", "None", "Number", "String", "Number", "Number"]); </script> <script type='text/javascript' src='http://thesite.com/_javascript/sortable_plus.js?2' language='javascript'></script> <script type="text/javascript"> paintTable(); </script> </code> So, I thought I might be able to edit the parameter to SortableTable() with something like this is my tampermonkey script: <code> document.body.innerHTML = document.body.innerHTML.replace('"Number", "Number"', '"Number", "Number", "Number"') </code> But that doesn't work. In fact after running that it seems that none of the table is sortable. In fact I just tested that and even if I change the text of a column heading the substitution works, but the sort routine fails, so most likely this is not the best approach. So, can anyone tell me how can I use replace the existing javascript routine or modify it so that it sorts the extra column? Thanks in advance for any assistance, Harrold Reply With Quote 01-14-2015, 10:43 PM #2 harrold View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 3 Thanks 0 Thanked 0 Times in 0 Posts Actually, I can see I mucked up the example replace() - but it really doesn't work even if the parameters are correct! Harrold Reply With Quote 01-16-2015, 08:10 AM #3 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts run the code in the script tag after you inject the new content. you might need need to add another item to the end of the column type list, looks like "Number" from here. Similar TutorialsHiya all, I'm new here and fairly new to JavaScript and coding - one of my teachers said it would be a fun language to learn to help me out when our GCSE's come up so I thought I would give it a go. I am currently trying to make a roulette style of game - the first phase though is fairly basic. I want the user to click a number and then to be told if it is right or wrong and update their chips. Currently I am using a fixed number whilst building up the script for testing purposes - I will change that to a random number later on. So far I have broke the code down and the parts that work are where the user function is not there(The buttons) so i assume the function for changing a variable to what the user picks is broke. Although when printing that function it says that it has changed. Like I said I'm new here so if this is not where to post for help just let me know and point me in the wrong direction any help would be much appreciated The code is : Code: <html> <body> <script language='JavaScript'> var numbers = new Array(39); numbers[0] = "BLANK IF THIS COMES UP PANIC AND RUN"; numbers[1] = "1"; numbers[2] = "2"; numbers[3] = "3"; numbers[4] = "4"; numbers[5] = "5"; numbers[6] = "6"; numbers[7] = "7"; numbers[8] = "8"; numbers[9] = "9"; numbers[10] = "10"; numbers[11] = "11"; numbers[12] = "12"; numbers[13] = "13"; numbers[14] = "14"; numbers[15] = "15"; numbers[16] = "16"; numbers[17] = "17"; numbers[18] = "18"; numbers[19] = "19"; numbers[20] = "20"; numbers[21] = "21"; numbers[22] = "22"; numbers[23] = "23"; numbers[24] = "24"; numbers[25] = "25"; numbers[26] = "26"; numbers[27] = "27"; numbers[28] = "28"; numbers[29] = "29"; numbers[30] = "30"; numbers[31] = "31"; numbers[32] = "32"; numbers[33] = "33"; numbers[34] = "34"; numbers[35] = "35"; numbers[36] = "36"; numbers[37] = "0"; numbers[38] = "00"; var goldennum = numbers[20]; //roullete number document.write(goldennum +"</br>"); var userpot = 500; // The amount of credits or chips the user has //var userpot = userpot*38; //document.write(userpot); user pot working calc var usernum = 200; //user betting number function button00(){ var usernum = 00; } function button0(){ var usernum = 0; } function button3(){ var usernum = 3; } function button6(){ var usernum = 6; } function button9(){ var usernum = 9; } function button12(){ var usernum = 12; } function button15(){ var usernum = 15; } function button18(){ var usernum = 18; } function button21(){ var usernum = 21; } function button24(){ var usernum = 24; } function button27(){ var usernum = 27; } function button30(){ var usernum = 30; } function button33(){ var usernum = 33; } function button36(){ var usernum = 36; } function button2(){ var usernum = 2; } function button5(){ var usernum = 5; } function button8(){ var usernum = 8; } function button11(){ var usernum = 11; } function button14(){ var usernum = 14; } function button17(){ var usernum = 17; } function button20(){ var usernum = 20; //document.write("</br></br></br>" + usernum + "</br></br></br>"); } function button23(){ var usernum = 23; } function button26(){ var usernum = 26; } function button29(){ var usernum = 29; } function button32(){ var usernum = 32; } function button35(){ var usernum = 35; } function button1(){ var usernum = 1; } function button4(){ var usernum = 4; } function button7(){ var usernum = 7; } function button10(){ var usernum = 10; } function button13(){ var usernum = 13; } function button16(){ var usernum = 16; } function button19(){ var usernum = 19; } function button22(){ var usernum = 22; } function button25(){ var usernum = 25; } function button28(){ var usernum = 28; } function button31(){ var usernum = 31; } function button34(){ var usernum = 34; } function runnums(){ //function to run the if the users bet is equal to the roulette number if(usernum == goldennum){ var userpot=500; userpot = userpot * 38; document.write(userpot); document.write( " YOU ARE A WINNER "); } else{ var userpot = 500; userpot= userpot - userpot; document.write ("You have " + userpot + " credits left "); document.write ( " YOU ARE A LOOOOOSER "); } } </script> <br> <br> <br> <br> <br> <br> <br> <input type="button" name="Button" value="00" onclick="button00()"> <input type="button" name="Button3" value="3" onclick= "button3()"> <input type="button" name="Button6" value="6" onclick= "button6()"> <input type="button" name="Button9" value="9" onclick= "button9()"> <input type="button" name="Button12" value="12" onclick="button12()"> <input type="button" name="Button15" value="15" onclick="button15()"> <input type="button" name="Button18" value="18" onclick="button18()"> <input type="button" name="Button21" value="21" onclick="button21()"> <input type="button" name="Button24" value="24" onclick="button24()"> <input type="button" name="Button27" value="27" onclick="button27()"> <input type="button" name="Button30" value="30" onclick="button30()"> <input type="button" name="Button33" value="33" onclick="button33()"> <input type="button" name="Button36" value="36" onclick="button36()"> <p> <input type="button" name="Button0" value="0" onclick="button0()"> <input type="button" name="Button2" value="2" onclick="button2()"> <input type="button" name="Button5" value="5" onclick="button5()"> <input type="button" name="Button8" value="8" onclick="button8()"> <input type="button" name="Button11" value="11" onclick="button11()"> <input type="button" name="Button14" value="14" onclick="button14()"> <input type="button" name="Button17" value="17" onclick="button17()"> <input type="button" name="Button20" value="20" onclick="button20()"> <input type="button" name="Button23" value="23" onclick="button23()"> <input type="button" name="Button26" value="26" onclick="button26()"> <input type="button" name="Button29" value="29" onclick="button29()"> <input type="button" name="Button32" value="32" onclick="button32()"> <input type="button" name="Button35" value="35" onclick="button35()"> <p> <input type="button" name="Button1" value="1" onclick="button1()"> <input type="button" name="Button4" value="4" onclick="button4()"> <input type="button" name="Button7" value="7" onclick="button7()"> <input type="button" name="Button10" value="10" onclick="button10()"> <input type="button" name="Button13" value="13" onclick="button13()"> <input type="button" name="Button16" value="16" onclick="button16()"> <input type="button" name="Button19" value="19" onclick="button19()"> <input type="button" name="Button22" value="22" onclick="button22()"> <input type="button" name="Button25" value="25" onclick="button25()"> <input type="button" name="Button28" value="28" onclick="button28()"> <input type="button" name="Button31" value="31" onclick="button31()"> <input type="button" name="Button34" value="34" onclick="button34()"> <input type="button" name="Place Bets" value="Place Bets" onclick="runnums()"> </body> </html> Dear friends I am trying to code this piece of wonderful fun there is some glitch with it though - the 'female occupation' always gets stuck on lady of leisure'. I cannot figure what the problem is - can anyone spot it? Thank yoo!! Beth xx //define sex var sex=Math.random(); if (sex>0.5) {document.write(". You were male. ");} else {document.write(". You were female. ");} //define occupation number var occu_num=Math.random()*10; occu_num=Math.round(occu_num); //define male occupation var occupation; if (sex>0.5){ if (occu_num==0) {occupation="jeweler or watch-maker.";} else if (occu_num==1) {occupation="jeweler or watch-maker.";} else if (occu_num==2) {occupation="priest.";} else {occupation="man of the law, probably a judge.";} document.write("<br>You were a respected and accomplished " + occupation);} //define female occupation else { if (occu_num==0) {occupation="jeweler or watch-maker.";} else if (occu_num==1) {occupation="jeweler or watch-maker.";} else if (occu_num==2) {occupation="nun or priestess.";} else (occu_num==10) {occupation="lady of leisure.";} document.write("<br>You were a respected and accomplished " + occupation);} Helo, I'm really hoping one of you JavaScript gurus can help me. I find this a bit difficult, but I'm sure you will find it easy. I wrote a script to detect the version of Windows that a visitor is using. It then loads a remote script based on the OS. You can see it in action by visiting my website http://www.xp-smoker.com and clicking on any link that takes you to another page. This script shows you an offer based on whether you are using XP, Vista or Windows 7. It works great in IE 8. No errors. It does not work at all in Firefox. But once again absolutely no errors. I'm using "onload" in the body tag of my pages like this: Code: <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="loadjs();"> The function is contained in a file that is called locally. Here is the function: Code: function loadjs() { //Create a 'script' element var scrptE = document.createElement("script"); //Set 'type' and 'language' attribs scrptE.setAttribute("type", "text/javascript"); scrptE.setAttribute("language", "JavaScript"); if (navigator.appVersion.indexOf("Windows NT 5.1")!=-1){ scrptE.setAttribute("src", "http://www.trialpay.com/js/pop_under/?c=62020ec"); }else if (navigator.appVersion.indexOf("Windows NT 6.0")!=-1){ scrptE.setAttribute("src", "http://www.trialpay.com/js/pop_under/?c=7ace1f3"); }else if (navigator.appVersion.indexOf("Windows NT 6.1")!=-1){ scrptE.setAttribute("src", "http://www.trialpay.com/js/pop_under/?c=85cfeba"); } // create an object of the head element of current page var hdEl = document.getElementsByTagName("head")[0]; //check for previously appended child //(it ensures that each time the button is pressed it // removes the previously loaded script element) if (hdEl.childNodes.length > 1) { hdEl.removeChild(hdEl.lastChild); } // Now add this new element to the head tag hdEl.appendChild(scrptE); } I don't know if it is the function causing it or if the onload event in the body tag is the problem. I tried removing the onload event from the body tag and using this after the body tag: Code: <script>if(document.all)window.attachEvent("onload",loadjs());else window.addEventListener("load",loadjs(),false);</script> But that didn't work in Firefox either. That gave me an error. Your help would be greatly appreciated. I hope I provided you with enough info. I am working on a new site wherein i have list of links in colomn. what i want is when i click on a link. that color of the text should change to indicate that the link is selected. I am not talking about roll over effect. even after the mouse is rolls out the color should still remain as it is to show that the link is still selected. how can i do this. How can javascript detect which link is selected. and save it may be in a variable. which changes each time i select a link. what script or logic should i use for this? Hi there, Im very new to all this and have only been working with scripts for a few days, so simple pointers would be greatly appriciated. My problem; I play an online strategy game where i can use scripts to help my game play. There is a quick bar at the top of the game screen which i can add scripts to. When editing the bar there are 3 options. 1. Name, 2. Image URL, 3. Target URL. The script i have written is entered into the Target URL. It works fine but i have to be on a certain page in the game to run the script because of how it gets the required info. At the minute i have two scripts doing what i would like one to do. The first script (that i wrote) and a second which just redirects me to the right page (which i have to click first). Can i get both tasks on to one script. What i would like the script to do is, upon clicking redirect me to the appropriate page the script needs to be run from, and then run the javascript function. My Script; ( which isnt finished but works fine for now) Code: JavaScript: var n = prompt("1.Plunder / Looting 2. OD 3.Archer 4.Axe ", "1");n = parseInt(n); if(n == 1) {var stringOne = (document.getElementsByTagName("img")[12].title);var stringTwo = (document.getElementsByTagName("img")[10].title);var stringThree = (document.getElementsByTagName("img")[25].title);var stringFour = (document.getElementsByTagName("img")[24].title);var stringFive = stringOne + " \n" + stringTwo + " \nToday " + stringThree + " \nToday " + stringFour + "";alert (stringFive );}; if(n == 2) {var stringSix = (document.getElementsByTagName("img")[15].title);var stringSeven = (document.getElementsByTagName("img")[22].title);var stringEight = (document.getElementsByTagName("img")[23].title);var stringNine = stringSix + " \nToday as attacker " + stringSeven + " \nToday as defender " + stringEight + "";alert (stringNine );}; To sum up. Basicly i want to be able to click the link to this script and have it redirect me to the right page and then run. So where would i put the page address and how do i make the script rum when the page is loaded. Hey guys, so I am a designer (not a developer) doing a site for someone. I am playing with some simple free javascripts. I have lightbox and toggler. Both work great individually. They are conflicting and everywhere online says to set the both to onLoad in the body tag. Sounds easy enough. But I can't seem to figure out the call for this script: Code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="../js/expand.js"></script> <script type="text/javascript"> $(function() { $("h2.expand").toggler({method: "fadeToggle"}); }); //--><!]]> </script> <body onload="toggler();initLightbox()"> is what is seems like it should be for me. But that isn't working at all. Please help! I feel like I have tried every possible name with the toggler()... If you need more, I can point you to the site itself and you can see all of the (messy) code. I finished this code, the full code is not here, but when I ran it as a diagnostic the action did not occur when i clicked on the "process item" button. I believe it may have something to do with the script, but i am new to javascript and cannot seem to figure it out, it is supposed to multiply the price by the number to give the value of sale (sale). Any help would be much appreciated!!! Code: <html> <script language="javascript"> function test() { var Items,Price,Number,sale; Items = parselfloat(document.victoria.secondnumber.value); Price = parselfloat(document.victoria.price.value); Number = parselfloat(document.victoria.num.value); sale = Price*Number; document.victoria.val.value=sale; } </script> <body><form name ="victoria"> <center> <table border=40 bordercolor="yellow"> <tr><td>Customer Number <input name ="firstnumber" type="text" size="6" value="1" ></td> <td>Home Delivery <input name="customer_name" type="checkbox"Checked></td><tr> <tr><td>Items Purchased</td><td><center><input name="secondnumber" type="text" size="12"></center></td></tr> <tr><td>Item Number</td><td><center><input name="itemnum" type="text" size="12" value="1"></center></td></tr> <tr><td>Price</td><td><center><input name="price" type="text" size="12"></center></td></tr> <tr><td>Number Purchased</td><td><center><input name="num" type="text" size="12"></center></td></tr> <tr><td>Value of Sale</td><td><center><input name="val" type="text" size="12" value="0"></center></td></tr> <tr><td>Customer Total</td><td><center><input name="total" type="text" size="12" value="0"></center></td></tr> <tr><td></td><td><input type="button" value="Process Item" onclick="test()"></td></tr> </table> </center></form> </body></html> I have a problem I just can't seem to solve. Seems to be an interference of two scripts. But have checked no duplicate function names or variables. Tried altering script order too. The one that breaks, breaks on this line: $('*[@title^="ajax:"]').each(function(index){ ... which I don't fully understand. The expression is a jQuery loop thing I believe. index seems to be null. I can't see where index is defined. What the code at this point aims to do is check for the phrase ajax: in all links on the page and do some manipulation so that the contents of the link are shown in a a tooltip. The problem is not about ajax. The full script is he http://www.javascriptkit.com/script/...xtooltip.shtml The problem occurs when the page includes the editor script, such as he http://www.tji-java-ide.com/beijing/...blogs&Itemid=1 The links on the top of the page work fine when there is no editor present, such as he http://www.tji-java-ide.com/beijing/...tpage&Itemid=1 I have an age script running in the attachment below. It works fine for numbers such as 1 22 1980. Code: if ((input.search(/\b([1-9]|[12][0-9]|3[01])\b/)!= -1) && (input.search(/\b([1-9]|1[0-2])\b/)!=-1) && (input.search(/\b(19[0-9]{2}|200[0-9]|201[01])\b/)!= -1)) { function getBirth() { var now = new Date(); var myMatchy = input.match(/\b(19[0-9]{2}|200[0-9]|201[01])\b/); var myMatchm = input.match(/\b([1-9]|1[0-2])\b/) var myMatchd = input.match(/\b([1-9]|[12][0-9]|3[01])\b/); var year = myMatchy[0]; var month = myMatchm[0]; var day = myMatchd[0]; var today = { "year" : now.getFullYear(), "month": now.getMonth()+1, "day" : now.getDate() } var age = today["year"] - year; if (month > today["month"]) age--; else if (month == today["month"]) if (day > today["day"]) age-- return age; } document.result.result.value = "Your age is "+getBirth()+"."; return true;} However, if someone writes out the month it doesn't. Such as January 22 1980. I did a work-around by inserting the month value. Highlighted below. But that means I would have to duplicate this lengthy code 12 times for each month of the year. Anybody know a better way to handle this? You can test it in the small attachment below. Any help would be appreciated. Code: if ((input.search(/\b([1-9]|[12][0-9]|3[01])\b/)!= -1) && (input.search(/(january)/)!= -1) && (input.search(/\b(19[0-9]{2}|200[0-9]|201[01])\b/)!= -1)) { function getJan() { var now = new Date(); var myMatchy = input.match(/\b(19[0-9]{2}|200[0-9]|201[01])\b/); var myMatchd = input.match(/\b([1-9]|[12][0-9]|3[01])\b/); var month = 0; var year = myMatchy[0]; var day = myMatchd[0]; var today = { "year" : now.getFullYear(), "month": now.getMonth()+1, "day" : now.getDate() } var age = today["year"] - year; if (month > today["month"]) age--; else if (month == today["month"]) if (day > today["day"]) age-- return age; } document.result.result.value = "Your age is "+getJan()+"."; return true;} Thread duplicated see one above!
confused:hope its the right place to post a newbie here . but i have a problem with a firefox accepting a script that i wrote it works on exploer but not on firefox onclick="javascript:if (this.parentNode.parentNode.nextSibling.style.display !='block') this.parentNode.parentNode.nextSibling.style.display ='block'; else this.parentNode.parentNode.nextSibling.style.display ='none';" hope u can help me thx Hello all. This script is working fine in IE7 but FF is complaining about undeclared variables. Can anybody assist to get this working in FF or do I need a new script? Any and all advice is welcome. 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=utf-8" /> <title>Test ZOOM</title> <script type="text/javascript"> //Image zoom in/out script- by javascriptkit.com //Visit JavaScript Kit (http://www.javascriptkit.com) for script //Credit must stay intact for use var zoomfactor=0.05 //Enter factor (0.05=5%) function zoomhelper(){ if (parseInt(whatcache.style.width)>10&&parseInt(whatcache.style.height)>10){ whatcache.style.width=parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix whatcache.style.height=parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix } } function zoom(originalW, originalH, what, state){ if (!document.all&&!document.getElementById) return whatcache=eval("document.images."+what) prefix=(state=="in")? 1 : -1 if (whatcache.style.width==""||state=="restore"){ whatcache.style.width=originalW+"px" whatcache.style.height=originalH+"px" if (state=="restore") return } else{ zoomhelper() } beginzoom=setInterval("zoomhelper()",100) } function clearzoom(){ if (window.beginzoom) clearInterval(beginzoom) } </script> </head> <body> <!-- CHANGE 99 to your image width, 100 to image height, and "office_map" to your image's name--> <a href="#" onmouseover="zoom(100,63,'office_map_6','in')" onmouseout="clearzoom()">Zoom In</a> | <a href="#" onmouseover="zoom(100,63,'office_map_6','restore')">Normal</a> | <a href="#" onmouseover="zoom(120,60,'office_map_6','out')" onmouseout="clearzoom()">Zoom Out</a> <div style="position:relative;width:420;height:300"> <div style="position:absolute"><img name="office_map_6" src="images/office_map_6.gif" width="100" height="63"> </div> </div> </body> </html> low tech Hey everyone, I'm trying to make a sound by using the mouseover event on JS. The script works fine on my husband's computer (IE8, windows xp), but does not work on mine (IE8, Vista). Click on the link below to give you an idea. Just mouseover the images and you should hear an elephant and duck sound. Mouseover the word "elephant" and it "should" make an elephant sound. http://www.mypreciousarrival.com/Ani...oundtest4.html I just need to find a script that will work with different operating systems (or at least windows xp and vista) and browsers (or at least IE) Any suggestions are greatly appreciated. I would like to not resort to any macromedia or schockwave scripting. Thank you! Hello everybody I am new here and my English is not very good, sorry. I hope this post is in the correct forum.Thank you in advance for helping me out. I am from the netherlands and we are having a problem with a script. I will explain a few things so everything is clear for you. We are a member from a website: www.onderdelenzoeker.nl Through this website customers can ask for used carparts. If we have these parts in stock we can send the customers an email trough this website. (we are loggin in at leden.onderdelenzoeker.nl) We don't have a regular stock and price so every email we send is unique. That is why we are using this script. When we are sending a customer an email, this script will put the parts in our webshop with the prices. The customer will get an email with a unique link and can order the parts and pay trough the internet. But now the problem , this script won't work the first time. If we fill in a form and send it the first time the script won't work (the customer is getting an email but without the link and the parts are not in the webshop). If we fill in the same form a second time and send it the script is working and the customer is getting an email with a link and the parts are in the shop. Now the script is working in IE and we are using Trixie (is the same like greasemonkey is for FF) I hope I have written down all the information you need. And I hope there is somebody who can help me out. Thank you for your time and effort. Nicole This is the script: PHP Code: // ==UserScript== // @name onderdelenzoeker.nl Extractor for ie // @namespace http://www.autodemontage-wlubbers.nl // @description Adds products to the autodemontage-wlubbers.nl webshop width the information form the onderdelenzoeker.nl website when a users request a product. // @date 09.05.2011 // @version 1.0.2 // @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js // @include http://leden.onderdelenzoeker.nl/* // ==/UserScript== var merk; var model; var bouwjaar; var base_url = 'http://www.autodemontage-wlubbers.nl/shop/admin/services.php?action='; $(document).ready(function(){ setTimeout('replace_button()',500); }); replace_button = function(){ if($('.info').find('td:eq(7)').length!=0){ merk = $('.info').find('td:eq(7)').html().split(' ')[0]; model = $('.info').find('td:eq(10)').html(); bouwjaar = $('.info').find('td:eq(13)').html().replace(/[^A-Za-z0-9 .]/,''); $('.info:eq(4)').find('button').after('<input type="button" class="button" onclick="addProjectToShop();" style="width:100%" value="Verstuur gegevens naar aanvrager" />'); $('.info:eq(4)').find('button:eq(0)').remove(); $('body').after('<iframe style="display:none;" id="sendFrame" />'); $('#sendFrame').attr('src',base_url+'login&pass=q6pk4mcn5kzy5hppg0bcq'); } setTimeout('replace_button()',1000); } addProjectToShop = function (){ $('body').after('<div style="position:fixed;top:'+(window.innerHeight/2-100)+';left:'+(window.innerWidth/2-200)+';width:400px;height:200px;border:1px solid black;background:white;" id="loadingFrame" ><h1>Sending...</h1></div>'); var length = 10; var sPassword = ""; for (i=0; i < length; i++) { numI = getRandomNum(); while (checkPunc(numI)) { numI = getRandomNum(); } sPassword = sPassword + String.fromCharCode(numI); } var int_ = 200; $('.info:eq(4)').find('label').each(function(){ var parent = $(this).parent().parent().parent(); if(parent.find('input:eq(0)').attr('checked')) { setTimeout('$(\'#sendFrame\').attr(\'src\',\''+base_url+'addProduct&pass=q6pk4mcn5kzy5hppg0bcq&code='+sPassword+'&merk='+merk+'&model='+model+'&bouwjaar='+bouwjaar+'&item='+$(this).html()+'&prijs='+parent.find('input:eq(1)').val()+'&statiegeld='+parent.find('input:eq(2)').val()+'&verzendkosten='+$('#verzendkosten').val()+'&garantie='+parent.find('select option:selected').text()+'\');',int_); int_ = int_ + 200; } }); setTimeout('$(\'#sendFrame\').attr(\'src\',\''+base_url+'logout\');',int_); $('textarea').val($('textarea').val()+"\nU kunt de producten via onze webshop bestellen.\nKlik of kopieer de onderstaande link in uw browser.\nhttp://www.autodemontage-wlubbers.nl/shop/index.php?route=product/product/refcode&refcode="+sPassword); setTimeout('$(\'#loadingFrame\').remove();$(\'#sendFrame\').remove();validate_and_submit();',4000); return false; } getRandomNum = function () { var rndNum = Math.random() rndNum = parseInt(rndNum * 1000); rndNum = (rndNum % 94) + 33; return rndNum; } checkPunc = function (num) { if ((num >=33) && (num <=47)) { return true; } if ((num >=58) && (num <=64)) { return true; } if ((num >=91) && (num <=96)) { return true; } if ((num >=123) && (num <=126)) { return true; } return false; } Hi! everyone. I've run into a problem with a piece of script and being code illiterate I could use some help. I'm making a page with a few thumbnails that I want to use as links to open a larger image in a pop-up window. I found this piece of code ( call it a senior moment ~ but I didn't make a note of where it was ) that works fine in Firefox and Safari, but IE8 is telling me that there is an error in the highlighted line: Code: <script language="JavaScript"> function openW(mypage,myname,w,h,features) { if(screen.width){ var winl = (screen.width-w)/2; var wint = (screen.height-h)/2; }else{winl = 0;wint =0;} if (winl < 0) winl = 0; if (wint < 0) wint = 0; var settings = 'height=' + h + ','; settings += 'width=' + w + ','; settings += 'top=' + wint + ','; settings += 'left=' + winl + ','; settings += features; win = window.open(mypage,myname,settings); win.window.focus(); } </script> Code: <a href="JavaScript:openW('URL','TITLE',WIDTH,HEIGHT,'')">LINK</a> Anyone got an idea if it can be tweaked to make IE recognize it? Or a simple alternative script that works cross browser? Any help would be greatly appreciated. Thanks hi i have 4 check boxes chk1 , chk2,chk3,chk4 also textbox1 , textbox2 textbox3 textbox4 when selecting one chk box (chk1) textbox1=45 textbox44=45 when chk1 checked if textbox2=56 textbox45=56 when chk2 checked plz give me code sample for me plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz give me a answer Hi Guys, I am trying to create a way for my users to download some code dynamically from my web page via a file download. Below is the code that i have written so far. It seems to be dying on the iframe but i'm not sure why. Here is my jquery trigger which is inside my onreadystate function. Code: $('#export_txt').click(function(e){ alert(LPAjax.ajaxurl + "/download.php"); $.generateFile({ action : "download_txt", filename : "exportme.txt", content : $("#ticket_window").html(), script : LPAjax.ajaxurl + "/download.php" }); e.preventDefault(); }); and here is the code i am using to process the post. Code: (function($){ // Creating a jQuery plugin: $.generateFile = function(options){ options = options || {}; if(!options.script || !options.filename || !options.content){ throw new Error("Please enter all the required config options!"); } alert("Inside Function"); // Creating a 1 by 1 px invisible iframe: var iframe = $('<iframe>',{ width:1, height:1, frameborder:0, css:{ display:'none' } }).appendTo('body'); var formHTML = '<form action="" method="post">'+ '<input type="hidden" name="filename" />'+ '<input type="hidden" name="content" />'+ '</form>'; // Giving IE a chance to build the DOM in // the iframe with a short timeout: setTimeout(function(){ // The body element of the iframe document: var body = (iframe.prop('contentDocument') !== undefined) ? iframe.prop('contentDocument').body : iframe.prop('document').body; // IE alert(" We are almost there"); body = $(body); // Adding the form to the body: body.html(formHTML); alert("added form to page"); var form = body.find('form'); form.attr('action',options.script); form.find('input[name=filename]').val(options.filename); form.find('input[name=content]').val(options.content); alert("submitting form"); // Submitting the form to download.php. This will // cause the file download dialog box to appear. form.submit(); },50); }; })(jQuery); it seems to be dying on this line. Code: var body = (iframe.prop('contentDocument') !== undefined) Any suggestions? Thanks in advance. I have two seperate js files. One that houses the functions mylibrary.js and another that call the validated functions myform.js. I can not get the form to validate any data. The data just sits there and will not report errors. Any help would be greatly appreciated. Code: function valForm() { if(!isAlpha(document.myform.firstname.value)) { myform.firstname.focus(); return false; } if(!validEmail(document.myform.email.value)) { myform.email.focus(); return false; } if(!isRequired1(document.myform.options.value)) { myform.options.focus(); return false; } return true; } // JavaScript Document seperate js file mylibrary.js function isNumber(num) { return !(/\D/.test(num)); } function isAlpha(text){ return text.match(/\w+/) } function validEmail(email){ return email.match(/^([a-zA-Z0-9]{3,})(((\.|\-|\_)[a-zA-Z0-9]{2,})+)?@([a-z]{3,})(\-[a-z0-9]{3,})?(\.[a-z]{2,})+$/i ) } function isRequired1(){ if(myform.food.selectedIndex ==0) { alert("Please select from the drop-down list."); } } |