JavaScript - Troubles With Javascript, Please Help
Hello everyone, I'm in a bit of a pickle. Here are all the details and I hope someone will be able to help me out...
I have a CD; the way this CD installs is...when inserted, the CD runs a file Login.html...on this page there are 3 fields, login, password, and language (depending on which language you click on, that's the language that it automatically changes the Login and Password text to. The username and password need to be an account that is on a server that the login.html connects to. Once you log in, the system automatically bring you to the next page which is also located on the CD which is Install.html...now on this page, there are 4 fields. Destination of where I want to install, Language drop down, but here's the tricky part...the two other fields are Currency and Sales Origination. These two fields get auto populated depending on the language we selected on the first page, Login.html. but the trick is that if I bypass the Login.html file and point my browser directly to the Install.html file, the Currency and Sales Origination fields will be blank and I will not be able to install the application. Keep in mind, this is not an exe or MSI installation, it's a batch file that's on the CD and it performs several tasks such as moving files, extracting files, placing things in scheduled tasks, and a few other things. So what I need to do is figure out a way, hopefully with your guys help, is how to bypass the Login.html altogether so that I can run Install.html without needing anything from the Login.html. So I need to, I'm guessing, edit the Install.html file so that it already has Currency and Sales Origination pre-populated. Because if I go to Install.html directly and leave those two fields blank, the batch file that runs to install everything, it says there is no Currency file that is selected. Because the way it's created is it selects a certain .zip file from the CD and extracts it depending/according to the Currency and Sales Originations...which that depends all on the Language that was selected on the Login.html page. Currency: ZPF Sales Origination: 02CA these are the values that it's supposed to have. Hopefully this gives you guys an idea, because unfortunately I don't know much about JavaScript, so looking for some help from the pros Similar TutorialsHey guys, Here is my question: Is it possible to extract a cookie inside a textarea? For example, I am building a very basic shopping cart in Javascript, with "Add to Cart" buttons listed for each item. As the "Add to Cart" button is pressed, a cookie is created. There is a link in which you can click with "Review Order", which consists of a textarea that displays the items that you have 'purchased'. I am trying to get the value of the cookie to be extracted into this textarea, however I am not sure if this is possible. Thanks I wasnt sure where to put this one, since its mainly javascript I thought I would put it here. I am trying to pull a value being stored in a php function (it works fine) which is echoed into an html element, and use it in a javascript function. my HTML: Code: <img id="menu_image" src="<?php echo get_php_value(); ?>" width="356" /> my javascript: Code: function get_large_image(){ var image = document.getElementById('menu_image').src; alert(image); } right now the alert is giving me flie path to the current page, I need a file path to the image. When I had javascript pull a value from an input tag using the id to reference and stored the php function in the value attribute, I got this: "object HtmlElement" The final purpose of all this is to modify dynamically and HTML <a>'s href and class attribute based on a certain condition being true. apprecaite the help First problem: I have a script that allows ONLY numbers to be typed into a text field. I have tried to modify this script to allow Decimals (periods) to be typed as well, but haven't succeeded. The code in Red are the changes I added to this script, but it isn't working out. Code: function numbersOnly(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 110 || charCode > 110) ) return false; return true; } Second Problem: I need to set a Minimum number users may type in the text field. Normally this would be a simple task, but the minimum number they may type is a decimal (0.10). The default value in the field is .50. I tried replacing the .50 with .09, and I can't get the field to run the script and set its new value to .10 (<- this is the minimum). Here is the code I am working with. Code: <?php $memberType = "free"; $creditsBalance = .5; $bannerBalance = 1000; $textBalance = 1000; ?> <html> <head> <title>Convert Credits</title> <style type="text/css"> #convert{ height: 10px; } </style> <script type="text/javascript" language="javascript"> function numbersOnly(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 110 || charCode > 110)) return false; return true; } function convert(){ creditsBanner = Number(document.convertform.creditsbanner.value); creditsText = Number(document.convertform.creditstext.value); bannerText = Number(document.convertform.bannertext.value); textBanner = Number(document.convertform.textbanner.value); memberType = "<?php echo $memberType;?>"; creditsBalance = "<?php echo $creditsBalance;?>"; bannerBalance = "<?php echo $bannerBalance;?>"; textBalance = "<?php echo $textBalance;?>"; if(memberType=="free"){ // If Free // check credit balance if(creditsBanner>creditsBalance){ document.convertform.creditsbanner.value = creditsBalance; creditsBanner = creditsBalance; if(creditsBanner<.1){ document.convertform.creditsbanner.value = 0.1; creditsBanner = 0.1; } } if(creditsText>creditsBalance){ document.convertform.creditstext.value = creditsBalance; creditsText = creditsBalance; if(creditsText<.05){ document.convertform.creditstext.value = 0.05; creditsText = 0.05; } } // check banner balance if(bannerText>bannerBalance){ document.convertform.bannertext.value = bannerBalance; bannerText = bannerBalance; if(bannerText<.5){ document.convertform.bannertext.value = .5; bannerText = .5; } } // check text balance if(textBanner>textBalance){ document.convertform.textbanner.value = textBalance; textBanner = textBalance; if(textBanner<2){ document.convertform.textbanner.value = 2; textBanner = 2; } } crBanner = Number(creditsBanner * 10); crText = Number(creditsText * 20); bnText = Number(bannerText * 2); txBanner = Number(textBanner / 2); document.getElementById("creditstobanner").innerHTML="<b>"+crBanner+"</b>"; document.getElementById("creditstotext").innerHTML="<b>"+crText+"</b>"; document.getElementById("bannertotext").innerHTML="<b>"+bnText+"</b>"; document.getElementById("texttobanner").innerHTML="<b>"+txBanner+"</b>"; } else{ // If Upgraded } } // function updateValues(val) { // document.getElementById('bannerimp').value = val * 10; // document.getElementById('field2').value = val * 20; // document.getElementById('field3').value = val / 2; // document.getElementById('field4').value = val * 2; // } //document.getElementById('creditstobanner').innerHTML </script> </head> <body> <h1>Convert Credits</h1><br /> Credits: <?php echo $creditsBalance; ?><br /> Banner Impressions: <?php echo $bannerBalance; ?><br /> Text Ad Impressions: <?php echo $textBalance; ?><br /> <form action="convert.php" method="POST" name="convertform"> <h2>Convert Your Credits to Banner or Text Ad Impressions</h2> <div id="convert">Convert <input type="text" name="creditsbanner" size="5" onKeyUp="convert();" onKeyPress="return numbersOnly(event);"> Credits to <span id="creditstobanner"><b>0</b></span> Banner Impressions!</div> <br /> <div id="convert">Convert <input type="text" name="creditstext" size="5" onKeyUp="convert();" onKeyPress="return numbersOnly(event);"> Credits to <span id="creditstotext"><b>0</b></span> Text Ad Impressions!</div><br /> <h2>Convert Your Impressions</h2> <div id="convert">Convert <input type="text" name="bannertext" size="5" onKeyUp="convert();" onKeyPress="return numbersOnly(event);"> Banner Impressions to <span id="bannertotext"><b>0</b></span> Text Ad Impressions!</div><br /> <div id="convert">Convert <input type="text" name="textbanner" size="5" onKeyUp="convert();" onKeyPress="return numbersOnly(event);"> Text Ad Impressions to <span id="texttobanner"><b>0</b></span> Banner Impressions!</div><br /> </form> </body> </html> Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? So i have this: Code: #wrap { background-color:#FFFFFF;filter:alpha(opacity=80);opacity:.6; } And with javascript I want to basically, make turn the opacity up, so i tried this: Code: function mouseOver() { document.getElementById('wrap').style.background-color = "#FFFFFF;filter:alpha(opacity=80);opacity:.9;" } Though it's not working, can anyone help me? I am pretty sure this requires javascript, but right now my coding skills are next to none, but I am trying to teach myself, but for now I still have no idea what I am doing. So here is my problem. I have a site with fairly large images because I am working with a fluid layout, and the background is such that it cannot repeat well, so I placed a loader on the first page so that it can load all the images. I am also using html5 to animate a curtain up the screen, but because of the load time when a user first visits the site, the won't see that animation. Is there anyway that I can pass the amount of time it took to load the site into the delay section of html code. Here is the site: www.franklyon.info Thanks so much! I am running a flash detection script which I will include below... It is called by... Code: <script type="text/javascript"> //<![CDATA[ var requiredFlashVersion = 8; var hasFlashURL = 'http://www.*****.org.uk/'; var upgradeFlashURL = document.location.href + "?flash=ug"; var noFlashURL = 'http://www.*****.org.uk/text_version/**********.html'; var dontKnowFlashVersionURL = document.location.href + "?flash=dk"; //]]> </script> <script type="text/javascript" src="flash_detect.js"> //<![CDATA[ function getFlashVersion() { return null; }; //]]> </script> <script type="text/javascript" src="flash_redirect.js"> //<![CDATA[ location.href = dontKnowFlashVersionURL; //]]> </script> as you can see it determines whether the user has flash and refreshes the page with the according url paramater or sends them on their way. The problem I have is that because it refreshes the page the script runs again and again and just readds the url paramater every time... so it keeps refreshing until the url looks like this: index.html?flash=dk?flash=dk?flash=dk?flash=dk?flash=dk. I want a way to make it realise it has done its job and not run after its first service. Everything I have tried such as using an incremental variable has lead to it loading index.html/undefined (I probably executed this wrong). Here is the external js files for the redirection: flash_detect.js Code: // Flash Version Detector v1.2.1 // documentation: http://www.dithered.com/javascript/flash_detect/index.html // license: http://creativecommons.org/licenses/by/1.0/ // code by Chris Nott (chris[at]dithered[dot]com) // with VBScript code from Alastair Hamilton (now somewhat modified) function isDefined(property) { return (typeof property != 'undefined'); } var flashVersion = 0; var count = 0; function getFlashVersion() { var latestFlashVersion = 8; var agent = navigator.userAgent.toLowerCase(); // NS3 needs flashVersion to be a local variable if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) { flashVersion = 0; } if (agent.indexOf("firefox") != -1 && agent.indexOf("msie") == -1) { flashVersion = -2; } // NS3+, Opera3+, IE5+ Mac (support plugin array): check for Flash plugin in plugin array if (navigator.plugins != null && navigator.plugins.length > 0) { var flashPlugin = navigator.plugins['Shockwave Flash']; if (typeof flashPlugin == 'object') { for (var i = latestFlashVersion; i >= 3; i--) { if (flashPlugin.description.indexOf(i + '.') != -1) { flashVersion = i; break; } } } } // IE4+ Win32: attempt to create an ActiveX object using VBScript else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) { var doc = '<scr' + 'ipt language="VBScript"\> \n'; doc += 'On Error Resume Next \n'; doc += 'Dim obFlash \n'; doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n'; doc += ' Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n'; doc += ' If IsObject(obFlash) Then \n'; doc += ' flashVersion = i \n'; doc += ' Exit For \n'; doc += ' End If \n'; doc += 'Next \n'; doc += '</scr' + 'ipt\> \n'; document.write(doc); } // WebTV 2.5 supports flash 3 else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3; // older WebTV supports flash 2 else if (agent.indexOf("webtv") != -1) flashVersion = 2; // Can't detect in all other cases else { flashVersion = flashVersion_DONTKNOW; } return flashVersion; } flashVersion_DONTKNOW = -1; flash_redirect.js Code: // Flash Detection / Redirect v1.1.1 // documentation: http://www.dithered.com/javascript/flash_redirect/index.html // license: http://creativecommons.org/licenses/by/1.0/ // code by Chris Nott (chris[at]dithered[dot]com) // requires: flash_detect.js (http://www.dithered.com/javascript/flash_detect/index.html) // use flash_detect.js to return the Flash version var flashVersion = getFlashVersion(); // Redirect to appropriate page if (flashVersion >= requiredFlashVersion) location.replace(hasFlashURL); else if (flashVersion > 0) location.replace(upgradeFlashURL); else if (flashVersion == -2) location.replace(dontKnowFlashVersionURL); else if (flashVersion == 0) location.replace(noFlashURL); else if (flashVersion == flashVersion_DONTKNOW || flashVersion == null) location.replace(dontKnowFlashVersionURL); Your help is appreciated but please go into detail as I have a minor understanding of Javascript. Edit: Resolved. Instead of using paramaters I changed the anchor and used jquery to search for the string. I run a small nonprofit org, and am looking to upgrade our site to something cleaner like UNBOUNDARY'S website he http://www.unboundary.com/ Don't laugh, but I build our website with Microsoft Publisher, so I don't know any Code or Javascript. Is there any way I can have this "middle scrolling frame" like they do without having to know code. Perhaps an easy cut & paste code I can embed to give me that middle frame. Any assistance you can give is appreciated. Thanks, DOC I've got a call from an HTML form to a getBoardsSold() function Code: <input value="Show Me the Money" type="button" onClick="getBoardsSold();" /> the function is Code: function getBoardsSold() { createRequest(); var url = "getUpdatedBoardSales-ajax.php"; request.open("GET", url, true); request.onreadystatechange = updatePage; request.send(null); } Why do I always receive the error Object required line 101 (refering to the function call). Seems it isn't recognizing the function mark I need to stop my mootools ticker if its opened within cms which is simplecms. I have done this before using jquery $(document).ready(function () { if ($('meta[name = "in-cms"]').size() > 0) { // your code here //stop current animation ticker.children().stop(); } but i cannot use jquery on this piece i have tried var metas = document.getElementsByTagName('META'); var i; for (i = 0; i < metas.length; i++) alert(metas[i].getAttribute('NAME')); if (metas[i].getAttribute('name') == "in-cms"){ hor.pause(); } but it doesnt work it picks up null on meta names... I know some jquery but not what it does in the background javascript derr please help me |