JavaScript - Linking To A Function Script In Another Page.
I've searched everywhere for help on how to do this...
I have a website for tanning salon services. Salon A's page has links for 4 possible equipment choices -[I] (diamond, platinum, gold, bronze levels) on the Sunbeds page. Sunbeds page has 2 iFrames, top and bottom, that are changed by 4 functions - changediamond(), changebronze(), etc. based on the selection. I need to be able to click a link on the Salon page that will take me to the corresponding function on the Sunbeds page... Here's what I have so far: Salon A page Code: <a href="sunbeds.htm?javascript:changediamond()"><img src="images/nr_diam_sm2.jpg" alt="Diamond Level Sunbeds" /></a> (thru) <a href="sunbeds.htm?javascript:changebronze()"><img src="images/nr_brnz_sm2.jpg" alt="Bronze Level Sunbeds" /></a> Sunbeds page Code: <SCRIPT language="JavaScript"> function changediamond() { parent.FRAME1.location="sb_top_ct1.htm"; parent.FRAME2.location="sb_bot_ct1.htm"; } (thru) function changebronze() { parent.FRAME1.location="sb_top_ct4.htm"; parent.FRAME2.location="sb_bot_ct4.htm"; } </script> . .. ... .. . <a href="javascript:changediamond()"><img src="images/diamond_sm2.jpg" alt="Diamond Level Sunbeds" /></a> (thru) <a href="javascript:changebronze()"><img src="images/bronze_sm2.jpg" alt="Bronze Level Sunbeds" /></a> The links take me to the correct page but not the function. Once I'm there I can select the functions and the iFrame change works great. I'm just at a loss for passing along the data string ie sunbeds.htm?javascript"changediamond() I would certainly appreciate any help and advice you could share. I'm sure it's pretty simple but for a JS newbie, it's frustrating! Similar TutorialsHello and thanks for letting me on this forum! Im pretty new to JScript and I am still getting used to it all. I am trying to make a Website that allows values to be selected from one form, transferred to the next form as a summary and then completed. The values are sent to the page fine but my Validation is broken. Here is my LINK code In the Form Code: <form id="Tickets" onsubmit="return ValidateForm()" action="Details.html"> And in the Submit Button Code: <input type="submit" id="OrderTickets" value="Order Tickets" onclick="return ValidateForm()" > My validation is as follows Code: <script type = "text/javascript"> function ValidateForm() { if( document.getElementById('DepartingStation').selectedIndex == " ") { alert( "Please provide a Departing Station!" ); document.getElementById('DepartingStation').focus() ; return false; } if( document.getElementById('ArrivingStation').selectedIndex == " ") { alert( "Please provide an Arriving Station!" ); document.getElementById('ArrivingStation').focus() ; return false; } var Depart = document.getElementById('DepartingStation').value; var Arriv = document.getElementById('ArrivingStation').value; if( Depart==Arriv){ alert( "Train cannot depart and arrive at the same station!" ); return false; } if ( document.getElementById('ReturnTravel').checked=true; { var valueDate = document.getElementById('OutwardDate').value; if ( valueDate== null || valueDate== '') { alert('Please provide an Outward Travel Date!'); return false; } } var valueRetDate = document.getElementById('ReturnDate').value; if ( document.getElementById('ReturnTravelType').checked==true && (valueRetDate== null || valueRetDate== '' )) { alert('Please provide a Return Travel Date!'); return false; } } Id appreciate any help anyone can share on this! Thanks. Hi, I have a javascript app that works fine to parse my bb_feed.xml page pasted below this message. The problem is I need to link to the script instead of including it within the web page. When I try to create the page as a .js file and link to this script from another webpage, it doesn't work. Here's the code that I used to link the .js file that I have named bb_footer.js <script language="javascript" src="bb_footer.js" type="text/javascript"></script> Is there some other way this has to be done? Thanks for any and all possible help... <html> <body> <script type="text/javascript"> if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","bb_feed.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; var x=xmlDoc.getElementsByTagName("item"); for (i=0;i<x.length;i++) { document.write("<ul><li><a href=\""); document.write(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue); document.write("\">"); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write("</a></li></ul>"); } </script> </body> </html> I have a simple script that will get the NWS forecast for any zip code and it opens it in a new tab. I would like it to open in an iframe on another page with in my website. I have come close, but not quite all the way yet. This will enter the forecast in an iframe on the same page as the input form. http://www.cavecountryweather.com/wxsearch.php How can it load onto this page from the form on the menubar? This menu is common on all the sites pages. I have seen solutions posted around the internet using javascript for similar issues, but I haven't been able to get any to work in my situation. My javascript skills are - none. Any help would be appreciated. i have been looking all over the web and i can't get to where i need to be to finish my page. basically i have two pages and if someone clicks a specific link from the first page i want it go to the other page but load a specific page in the iframe on the second page. i know how to use javascript to make a specific page load into an iframe but not how to make the page load into the iframe on another page. all i need to know is how to do it for one page then i think i can build the decision structure around it to make it work for more than one link (hopefully). any help will be greatly appreciated. thanks. Hey, I have 3 bits of code, 2 of which I'm pretty sure are right [i know the php works, and the ajax looks fine], but one i'm having trouble with. Basically what I'm trying to do is use a link to call php function [calls a piece of text from a database]. Which worked fine. But then I tried to incorporate AJAX into the script to make change dynamically on the page, and I'm a little confused with it all. I've got the AJAX and PHP, [and an attempted page with a link on to try and call the function with AJAX] but so far it's not doing as it should. Wondered if anyone could show me where I'm going wrong with the whole 'linking together' thing? So far everything I've tried hasn't worked. [hope this doesn't violate the forums 'don't dump your code' rule. But it's kind of all necessary] The AJAX [AJAX.js]: Code: function loadurl(generate.php) { var ajax = false; // Create the object: // Choose the objecttype, depending on what is supported: if (window.XMLHttpRequest) { // IE 7, Mozilla, Safari, Firefox, Opera, most browsers: ajax = new XMLHttpRequest(); } else if (window.ActiveXObject) { // Old IE-browsers // Make the type Msxml2.XMLHTTP, if possible: try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e1) { // Else use the other type: try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { } } } // Retrieving the data from the page if (ajax) { alert("url:generate.php" + url); ajax.open('GET', url); // Sends request ajax.send(null); // Function that handles response ajax.onreadystatechange=function(){ // If everything is OK: if ( (ajax.readyState == 4) && (ajax.status == 200) ) { // Returns the value to the document alert(ajax.responseText); } } } else { // AJAX is not useable alert('It is not possible to connect, please update your browser.'); } } The PHP [generate.php] Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <?php if($_GET['act'] == "generate_quotes") { $db = mysql_connect("*", "*", "*") or die ("Unable to connect to database."); mysql_select_db("quote") or die ("Unable to select database."); $result = mysql_query( " SELECT * FROM `quote` ORDER BY RAND() LIMIT 0,1 " ); $fetch = mysql_fetch_array($result); echo "<blockquote>".$fetch['q_quote']."</blockquote>"; mysql_close($db); } else { echo "<img src=\"1.png\">"; } ?> </body> </html> The page where I'm trying to bring them together [PULL.php] Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <script src="ajax.js" type="text/javascript"></script> </head> <body> <a onClick="loadurl('generate.php'); return false;">Click Here</a> </body> </html> I've included the file names with extensions just in case it's something to do with those, but thanks in advance for any help. Greatly appreciated. hello i've followed this javascript and i'd like to link the text to one of my page.How do i place the ahref tag in the script.Appreciate your help http://www.javascriptkit.com/script/script2/neontext.shtml . . . .Within my website (so I control all pages) I often make anchor-links from one page (call it currentpage.htm) to an anchor-link in another page (newpage.htm). Imagine that newpage.htm has two anchor-locations, one near the page-beginning (#high) and one near the page-end (#low). . . . .There is a problem when linking to newpage.htm#low (or an inside-the-page link to #low) because the page-end goes to the bottom of the browser window, and the location (#low) appears somewhere in the vertical middle of the browser window, so it's difficult for a user to know where they should begin reading, and they get confused. . . . .A low-tech solution is to "make the page longer" by adding space to the page-bottom with a series of <p> </p>, or with a tall blank spacer-gif. But this implies something false, it tricks a user into thinking the page is longer than it is, so they may think "this page is too long, I don't want to read that much" and they go away, or they "skim" when they could read more slowly. . . . .Is there a solution using javascript? . . . .If yes, I assume the javascript must be located within newpage.htm, because a command within currentpage.htm can't "tell another page" what to do. Is this correct? I'm not confident because I'm a novice with using javascript. . . . .So is there a way to say, within newpage.htm, "make the page longer by adding a blank spacer-gif to the page-end when an incoming link goes to newpage.htm#low" but to have this be temporary, so when newpage.htm is opened the next time normally (with a link to newpage.htm or to newpage.htm#high) the spacer-gif is gone? CraigR -edit - nevermind. mods plz delete.
I just wrote an essay to discover it had logged me out and I lost everything. Grrrrrrr. Here goes again, simplified this time. I've got a sticky footer at the bottom of the page and a spry collapsible panel which expands to reveal content on mouse over. The problem I'm facing is that the page doesn't scroll down with it, only the scroll bar gets larger to accommodate for a manual scroll down. This is kind of useless because the user might not even realise that there's extra content there in the first place if it's not automatic. My question is, what's the best javascript code to use to automatically scroll the page down when the spry tab is opened and where would I insert it? I've tried all morning with no success so far! Thanks, Nick, I'm copy pasting this post this time round, I don't trust this website now Hi guys I'm new here and I'm new with javascript, althought I'm flash expert that doesn't help me to much with Javascripts ! So I need help with function! What I want is a function when I call it with desire value (for example: myfunction(300);" to change var value (for example: dest_x = 300). Is that possible? Please help me! For some reason in IE this script Code: <script type="text/javascript"> //<![CDATA[ function SelectDisplayDiv(pointer){var divs = document.getElementsByClassName('hiddenDiv');for(var i =0; i < divs.length; ++i){divs[i].style.display = "none";} document.getElementById(pointer).style.display = 'block';}//]]> </script> is saying "Object doesn't support this method or property" But this script Code: function SelectDisplayDiv(pointer){var divs = document.getElementsByClassName('hiddenDiv');for(var i =0; i < divs.length; ++i){divs[i].style.display = "none";} document.getElementById(pointer).style.display = 'block';} *almost the exact same thing, just not written to the canvas by code, hard coded rather- does not. What does that error mean? Is this an IE thing? hi every body, when iam usig java script function to textbox,For text length minimum 4 chars, alert is raising enter minimum 4 chars, but cursor is not focus on text box, when i click on alert "OK". Here the code written. function min() { var len=document.getElementById("tx1").value; if(len!="") { if(len.length==4) { alert("Chars 4 Letters Entered"); } else { alert("Enter 4 chars") document.getElementById("tx1").select(); document.getElementById("tx1").focus(); } } } Yours Narasimha Rao k I'll probably be laughed at for this attempt of coding, but all I am trying to do is read an input field, remove the "$" and write the new value in a different input field. Code: function convert_action (form){ var input1=form.input_field1.value; var clean=input1.replace(/$/, ''); form.input_field2.value = clean; } Looks simple, and thought this would work, it kindof does, it just does not strip out the dollar sign... Help would be appreciated...greatly... I'm trying to reduce the space between the page content and the footer..this is the code i'm using to resize and the method call is implemneted in master page pageload() Code: function resize() { var windowHeight; if (document.getElementById("leftnav") && document.getElementById("content")) { // document.getElementById('leftnav').style.height = document.getElementById('content').offsetHeight - 20 + 'px'; if (document.getElementById("content").offsetHeight >= 698) { document.getElementById("leftnav").style.height = document.body.clientHeight + "px"; document.getElementById("content").style.height = document.body.clientHeight + "px"; } } This method resizes based on the content but it gives more extra space between the content and the footer which is not our site standards. Any suggestions please? thanks Hi! I'm trying to run this script on Firefox. I'm copying and pasting the whole thing in here just to be safe, but I'm mostly concerned with getting the findLegendary function to call catchPok(). The script executes fine, goes into the battle, but then...does nothing. It runs the catchPok function if I manually click and deselect the "Find Legendary" window option, so alternately, if somebody knows how to make the program automatically click the element at that point to stop repeating the function (maybe?) and it works, I'd be just as happy with that. My best guess is that the autoContinue function might be interfering somehow, since it runs that portion of the code with the manual findLegendary shutoff, but to be honest I'm pretty clueless. What I want it to do is run the catch function through, catch the game pixel, and then go back to repeating. I don't care how this is accomplished as long as it can feasibly loop. The game rules allow botting, so this isn't against any site rules, either. Any and all help/advice is much appreciated! Code: // ==UserScript== // @name Pokemon Vortex Tool // @namespace vortexrising.tk // @include http://*pokemonvortex.org/* // @exclude http://*pokemonvortex.org/adv.php* // ==/UserScript== var legends = [ // Custom // Grass 'Shaymin (Sky)', 'Celebi', 'Latios', 'Latias', 'Rayquaza', 'Shaymin', 'Mew', 'Cresselia', 'Azelf', 'Uxie', 'Mesprit', 'Virizion', 'Genesect', // Grass (water) 'Manaphy', 'Phione', 'Suicune', 'Keldeo', // Ice 'Articuno', 'Suicune', 'Lugia', 'Regice', 'Kyurem', // Cave (land) 'Groudon', 'Arceus', 'Regigigas', 'Palkia', 'Dialga', 'Deoxys', 'Jirachi', 'Registeel', 'Regirock', 'Mewtwo', 'Cobalion', 'Terrakion', 'Virizion', 'Reshiram', 'Zekrom', 'Kyurem', 'Genesect', 'Tornadus', 'Landorus', // Cave (water) 'Kyogre', 'Lugia', 'Keldeo', // Ghost 'Mew', 'Giratina', 'Rotom', 'Mesprit', 'Azelf', 'Uxie', 'Celebi', 'Darkrown', 'Darkrai', // Electric 'Zapdos', 'Raikou', 'Jirachi', 'Darkrai', 'Darkrown', 'Thundurus', 'Zekrom', 'Genesect', // Fire 'Heatran', 'Ho-oh', 'Moltres', 'Entei', 'Reshiram', 'Victini' ]; var settings = { 'keys': ['autoBattle', 'findRare', 'findLegendary','catchPok','findNewpoke'], 'data': {}, 'save': function() { for (var i = 0; i < this.keys.length; i++) { GM_setValue(this.keys[i], this.data[this.keys[i]]); } }, 'load': function() { for (var i = 0; i < this.keys.length; i++) { this.data[this.keys[i]] = GM_getValue(this.keys[i], false); } } }; var movPos = 0; function moveAround() { movPos += 10; if (movPos > 360) { movPos = 0; } var xpos = parseInt(Math.sin(movPos * (Math.PI / 180))*10); var ypos = parseInt(Math.cos(movPos * (Math.PI / 180))*10); unsafeWindow.PlayRequest(xpos + 14, ypos + 14, parseInt(Math.random()*8)+1); /* var btnArrow = unsafeWindow.document.querySelector('#arrows img[onclick]') if (btnArrow) { btnArrow.click(); } else { unsafeWindow.console.info('No buttons?'); }*/ } function catchPok() { try { var btnPo = unsafeWindow.document.querySelector('#battleForm input[type="submit"][value="Continue"]'); if (btnPo) { btnPo.click(); } var radMaster = unsafeWindow.document.querySelector('#itemForm input[type="radio"][value="Master Ball"]'); if (radMaster) { radMaster.click(); } var btnItem = unsafeWindow.document.querySelector('#itemForm input[type="submit"][value="Use Item"]'); if (btnItem) { btnItem.click(); } var btnCont2 = unsafeWindow.document.querySelector('#battleForm input[type="submit"][value="Continue!"]'); if (btnCont2) { btnCont2.click(); } var linkReturnToMap = unsafeWindow.document.querySelector('.optionsList a'); if (linkReturnToMap && linkReturnToMap.textContent.trim() == 'Return to the Map') { settings.data.nextBattle = new Date().getTime() + 10000; unsafeWindow.location.href = linkReturnToMap.href; } }catch (e) { unsafeWindow.console.warn('Exception: ', e); } } function findNewpoke() { var aPoke = unsafeWindow.document.querySelector('#appear p'); var oldPoke = unsafeWindow.document.querySelector('#appear strong'); var searchPoke = unsafeWindow.document.querySelector('#alert p') if (!aPoke) { moveAround(); return; } else if (oldPoke) { moveAround(); return; } else if (searchPoke) { moveAround(); return; } else { var btnDo = unsafeWindow.document.querySelector('input[type="submit"][value="Battle!"]'); if (btnDo) { btnDo.click(); } catchPok(); return; } } function findLegendary() { var wildText = unsafeWindow.document.querySelector('#appear p'); if (!wildText) { moveAround(); return; } wildText = wildText.textContent.trim(); for (var i = 0; i < legends.length; i++) { if (wildText.match(legends[i])) { var btnDo = unsafeWindow.document.querySelector('input[type="submit"][value="Battle!"]'); if (btnDo) { btnDo.click(); } catchPok(); return; } } moveAround(); } function findRare() { var wildText = unsafeWindow.document.querySelector('#appear p'); if (!wildText) { moveAround(); return; } wildText = wildText.textContent.trim(); if (!wildText.match(/Wild (Shiny|Shaymin (Sky)|Celebi|Latios|Latias|Rayquaza|Shaymin|Mew|Cresselia|Azelf|Uxie|Mesprit|Virizion|Genesect|Manaphy|Phione|Suicune|Keldeo|Articuno|Lugia|Regice|Kyurem|Groudon|Arceus|Regigigas|Palkia|Dialga|Deoxys|Jirachi|Registeel|Regirock|Mewtwo|Cobalion|Terrakion|Reshiram|Zekrom|Tornadus|Landorus|Kyogre|Giratina|Rotom|Zapdos|Raikou|Darkrai|Darkrown|Thundurus|Heatran|Ho-oh|Moltres|Entei|Victini)/)) { moveAround(); return; } unsafeWindow.console.info('Rare found ', wildText); } function autoBattle() { try { var btnContinue = unsafeWindow.document.querySelector('#battleForm input[type="submit"][value="Continue"]'); if (btnContinue) { btnContinue.click(); } var btnContinue2 = unsafeWindow.document.querySelector('#battleForm input[type="submit"][value="Continue!"]'); if (btnContinue2) { btnContinue2.click(); } var btnAttack = unsafeWindow.document.querySelector('#battleForm input[type="submit"][value="Attack!"]'); if (btnAttack) { btnAttack.click(); } var linkReturnToMap = unsafeWindow.document.querySelector('.optionsList a'); if (linkReturnToMap && linkReturnToMap.textContent.trim() == 'Return to the Map') { settings.data.nextBattle = new Date().getTime() + 10000; unsafeWindow.location.href = linkReturnToMap.href; } // check for battle button var btnBattle = unsafeWindow.document.querySelector('#appear form input[type="submit"][value="Battle!"]'); var linkRebattle = unsafeWindow.document.querySelector('.optionsList a'); if (btnBattle) { // wait until 10 seconds since last battle //var delay = GM_getValue('lastBattle'); window.setTimeout(function() { btnBattle.click(); }, 10000); } else if (linkRebattle && linkRebattle.textContent.trim() == 'Rebattle Opponent') { window.setTimeout(function() { unsafeWindow.location.href = linkRebattle.href; }, 10000); } else { // if not found, click a direction var btnArrow = unsafeWindow.document.querySelector('#arrows img[onclick]') console.info('arrow', btnArrow); if (btnArrow) { btnArrow.click(); } } } catch (e) { unsafeWindow.console.warn('Exception: ', e); } } function autoContinue() { if (settings.data.findRare) { findRare(); } if (settings.data.autoBattle) { autoBattle(); } if (settings.data.findLegendary) { findLegendary(); } if (settings.data.catchPok) { catchPok(); } if (settings.data.findNewpoke) { findNewpoke(); } } unsafeWindow.AjaxRequest = function () { if (!this.xmlhttp) { try { // Try to create object for Firefox, Safari, IE7, etc. this.xmlhttp = new XMLHttpRequest(); } catch (e) { try { // Try to create object for later versions of IE. this.xmlhttp = new ActiveXObject('MSXML2.XMLHTTP'); } catch (e) { try { // Try to create object for early versions of IE. this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { // Could not create an XMLHttpRequest object. return false; } } } } this.method = 'post'; this.async = true; this.url; this.query = ''; this.data = ''; this.reponseText; this.reponseXML; this.responseHandler; this.abortHandler; this.showLoading = false; this.send = function () { if (this.method && this.url) { var self = this; this.xmlhttp.onreadystatechange = function () { if (self.xmlhttp.readyState == 4) { if (self.xmlhttp.status && (self.xmlhttp.status == 200 || self.xmlhttp.status == 304)) { //unsafeWindow.console.info('success', self); self.responseText = self.xmlhttp.responseText; if (self.xmlhttp.responseXML) { self.responseXML = self.xmlhttp.responseXML; } else { self.responseXML = null; } if (self.responseHandler) { self.responseHandler(); var evt = document.createEvent('Event'); evt.initEvent('gm:ajaxhook', false, true); document.dispatchEvent(evt); //autoContinue(); } } else { showAlert('<p>An error occured while requesting the data.</p><p>Status Msg: ' + self.xmlhttp.statusText + '</p><p><input type="button" name="ok" value="OK" onclick="removeAlert();" id="alertFocus"></p>'); } if (self.showLoading && self.loading) { self.loading.style.visibility = 'hidden'; } } } if (this.showLoading) { this.displayLoading(); } this.xmlhttp.open(this.method, this.url + '?' + encodeURI(this.query), this.async); if (this.method == 'post') { this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } this.xmlhttp.send(encodeURI(this.data)); } else { showAlert("<p>An error occured while requesting the data.</p><p>No method, URL, and/or query string provided.</p><p><input type=\"button\" name=\"ok\" value=\"OK\" onclick=\"removeAlert();\" id=\"alertFocus\"></p>"); } } this.abort = function () { this.xmlhttp.onreadystatechange = function () {}; this.xmlhttp.abort(); if (this.abortHandler) { this.abortHandler(); } } this.getFormValues = function (form) { for (i = 0; i < form.elements.length; i++) { switch (form.elements[i].type) { case 'text': case 'hidden': case 'password': case 'textarea': this.data += form.elements[i].name + "=" + form.elements[i].value + "&"; break; case 'checkbox': case 'radio': if (form.elements[i].checked) this.data += form.elements[i].name + "=" + form.elements[i].value + "&"; break; case 'select-one': this.data += form.elements[i].name + "=" + form.elements[i].options[form.elements[i].selectedIndex].value + "&"; break; } } this.data = this.data.substr(0, (this.data.length - 1)); } this.appendHTML = function (object, flag) { if (this.xmlhttp.responseText) { if (flag) { object.innerHTML = this.responseText; } else { object.innerHTML += this.responseText; } } else {} } this.displayLoading = function () { if (this.showLoading == 'sidebar') { this.loading = document.getElementById('sidebarLoading'); this.loading.style.height = document.getElementById('sidebar').offsetHeight - 2 + 'px'; this.loading.style.width = document.getElementById('sidebarContent').offsetWidth + 'px'; this.loading.innerHTML = '<p style="text-align: center; margin-top: 150px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>'; } else if (this.showLoading == 'message') // message { this.loading = document.getElementById('messageContent'); this.loading.style.height = document.getElementById('message').offsetHeight + 'px'; this.loading.style.width = document.getElementById('message').offsetWidth + 'px'; this.loading.innerHTML = '<p style="text-align: center; margin-top: 75px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>'; } else if (this.showLoading == 'messageList') // message list { this.loading = document.getElementById('messageList'); this.loading.style.height = document.getElementById('messageList').offsetHeight + 'px'; this.loading.style.width = document.getElementById('messageList').offsetWidth + 'px'; this.loading.innerHTML = '<p style="text-align: center; margin-top: 50px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>'; } else if (this.showLoading == 'map') // map { this.loading = document.getElementById('mapLoading') this.loading.innerHTML = '<p style="text-align: center; margin-top: 150px;"><img src="http://static.pokemonvortex.org/images/loading_white.gif" width="100" height="100" alt="Loading..." /></p>'; } else if (this.showLoading == 'live') { this.loading = document.getElementById('loading'); this.loading.style.height = document.getElementById('scroll').offsetHeight + 'px'; if (document.getElementById('scrollContent')) { this.loading.style.width = document.getElementById('scrollContent').offsetWidth + 'px'; } else { this.loading.style.width = document.getElementById('scroll').offsetWidth + 'px'; } this.loading.innerHTML = '<p class="large" style="margin-top: 75px; text-align: center;"><strong>Waiting for the other user to respond...</strong></p><p style="text-align: center;">You have been waiting <span id="waitTime">0 seconds</span>.</p>'; waitTime(0); } else // main { this.loading = document.getElementById('loading'); this.loading.style.height = document.getElementById('scroll').offsetHeight + 'px'; if (document.getElementById('scrollContent')) { this.loading.style.width = document.getElementById('scrollContent').offsetWidth + 'px'; } else { this.loading.style.width = document.getElementById('scroll').offsetWidth + 'px'; } this.loading.innerHTML = '<p style="text-align: center; margin-top: 150px;"><img src="http://static.pokemonvortex.org/images/loading.gif" width="100" height="100" alt="Loading..." /></p>'; } this.loading.style.visibility = 'visible'; } } function createToggler(container, title, varname) { var toggleEnable = unsafeWindow.document.createElement('p'); container.appendChild(toggleEnable); toggleEnable.innerHTML = title + ' <b>' + (settings.data[varname] ? 'Enabled' : 'Disabled') + '</b>'; toggleEnable.addEventListener('click', function() { settings.data[varname] = !settings.data[varname]; toggleEnable.innerHTML = title + ' <b>' + (settings.data[varname] ? 'Enabled' : 'Disabled') + '</b>'; settings.save(); autoContinue(); }, false); } function init() { var iframes = unsafeWindow.document.getElementsByTagName('iframe'); for (var i = 0; i < iframes.length; i++) { iframes[i].parentNode.removeChild(iframes[i]); } var sty = unsafeWindow.document.createElement('style'); unsafeWindow.document.querySelector('head').appendChild(sty); sty.textContent = '#fscctrl { background: green; border: 1px solid yellow; cursor:pointer; margin: auto; padding: 10px; width: 1010px; } #fscctrl p { margin: 0; } #alert{position:absolute; z-index: 1; background:#ffc; padding: 0 10px; right: 0; width: 100px;} #alert p { margin: 0; } #loading {z-index: 0; top: 0; height: 200px;} #loading p {margin-top:0 !important;} #header{ height: 70px; }'; unsafeWindow.disableSubmitButton = function(form) { for (i = 0; i < form.elements.length; i++) { if (form.elements[i].type == 'submit') { form.elements[i].value = 'Please Wait... or click again - by rockingdo'; } } return true; } settings.load(); document.addEventListener('gm:ajaxhook', function() { autoContinue(); }, false); var container = unsafeWindow.document.createElement('div'); unsafeWindow.document.body.insertBefore(container, unsafeWindow.document.body.firstChild); container.setAttribute('id', 'fscctrl'); createToggler(container, 'Auto-battle', 'autoBattle'); createToggler(container, 'Find Rare', 'findRare'); createToggler(container, 'Find Legendary', 'findLegendary'); createToggler(container, 'Catch Pokemon', 'catchPok'); createToggler(container, 'Find New Pokemon', 'findNewpoke'); autoContinue(); } init(); I am trying to implement a credit card check function in the validation script. But whenever i enable the function it bypasses all previous validation checks and just inputs the data, where am i going wrong with this function? Code: function CheckCreditCard(cardtype, cardnumber) { var frm = document.forms["OrderForm"]; if (cardtype == "Visa") { var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/; } else if (cardtype == "Master Card") { var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/; } else if (cardtype == "American Express") { var re = /^3[4,7]\d{13}$/; } if (!re.test(cardnumber)) return false; cardnumber = cardnumber.split("-").join(""); var checksum = 0; for (var i=(2-(cardnumber.length % 2)); i<=cardnumber.length; i+=2) { checksum += parseInt(cardnumber.charAt(i-1)); } for (var i=(cardnumber.length % 2) + 1; i<cardnumber.length; i+=2) { var digit = parseInt(cardnumber.charAt(i-1)) * 2; if (digit < 10) { checksum += digit; } else { checksum += (digit-9); } } if ((checksum % 10) == 0) return true; else sfm_show_error_msg('error message goes here'); return false; } HTML Code is: Code: <script language="JavaScript" type="text/javascript"> var frmvalidator = new Validator("OrderForm"); frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.EnableFocusOnError(false); // other attributes went here but were removed frmvalidator.setAddnlValidationFunction("CheckCreditCard"); </script> FULL Javascript: Attached at a txt file, was too large to post here. I have a function where in I call another function that assigns a value to a var. e.g. Code: function setVar{ var thisVar = 'hello'; return thisVar; } function callFuncSetVar { var newVar = setVar(); alert(newVar); } For some reason my code below is returning 'undefined'. But when I place an alert(); before the 'return' it shows the correct value. However when I place an alert(); to show the var that is set to what the function returns it says 'undefined'. Firebug throws no errors. I am using a little bit of jQuery. For the sample code: Code: <form name=form> <ul> <li><input type="text" onkeyUp="calc1();" name=x ></li> <li><input type="text" onkeyUp="calc2();" name=y ></li> </ul> </form> <script> function calc1() { document.form.y.value = (10 * document.form.x.value).toPrecision(5); } function calc2() { document.form.x.value = (0.1 * document.form.y.value).toPrecision(5); } </script> How can I use a checkbox to : (1) Upon check, change the current values to toExponential(5) format (2) Use a different script and/or function that would then calculate with toExponential(5) [as opposed to the hard coded toPrecision(5) in the current functions. (3) Upon unchecking, the result should should go back to Precision and change the function and/or script back to the original. Hi, Can anyone tell me How to send values from application resources.properties file to a java script function in a jsp Thanks in Advance, John Ven Hi guys, i have a code where if you press on a word some words disappear and new ones appear and then when you press on the word again everything goes back to normal. I am trying to get it so that after the first click if i press back it should go back to normal instead of having to press the word again but all i am getting at the moment when i press back is the the page with the changed text. |