JavaScript - Script Generated Button Code Creating Corrupted Code
I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files
F:\Textbooks.html F:\eBooks.txt F:\FirstBook.txt F:\SecondBook.txt F:\ThirdBook.txt textbooks.html is my DHTML app eBooks.txt is the Library file with a listing of all of my eBooks. Inside of eBooks.txt is the following data: ----------------- FirstBook.txt, SecondBook.txt, ThirdBook.txt, ----------------- FirstBook.txt to ThirdBook.txt are my actual ebooks. The problem that i'm having is that When i try to click on any buttons other than the FirstBook button, i get the following error: ---------------------------------- Error: unterminated string literal Source File: file:///F:/Textbooks.html Line: 1, Column: 10 Source Code: LoadEbook(' ---------------------------------- So, unlike clicking on the FirstBook button, these other buttons do not load the eBook data into the DIV for displaying the eBook data. I use the DOM insepector to checkout the DOM of the button code, and it seems like whitespace maybe is the problem. However, i have removed whitespace from the HTMLdata string, and that's not fixing the problem. did i forget something silly? LOL i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers. here is my HTML code: <html> <head> <script language="JavaScript"> var eBookLibrary = "eBooks.txt"; var SystemPath = "f:" + String.fromCharCode(92) function Init() { // Initialize the eBook reader document.getElementById("EbookCanvas").style.visibility = "hidden"; document.getElementById("EbookToolbar").style.visibility = "visible"; document.getElementById("FileManager").style.visibility = "visible"; // Load the List of eBooks in the Library LoadBookList(); } function UpdateEbookList() { // Update the Library of Ebooks alert("Updating eBook Library"); // Go back to the File Manager, and Reload the List of Ebooks LoadBookList(); } function LoadBookList() { // This will load the list of books that are available var EbookList = LoadFromDisk(SystemPath + eBookLibrary); var EbookListArray = EbookList.split(","); for(var x = 0; x < EbookListArray.length -1; x++) { // Strip the Filename Extension off of the eBook File Name // The Name of the Book is always the first Index in the Array var BookName = EbookListArray[x].split("."); // Remove the weird whitespace - it screws things up...i think... BookName[0] = BookName[0].replace(/(^\s*|\s*$)/g, ""); var HTMLdata = HTMLdata + "<input type='button' value='" + "FirstBook" + "'" + " onClick=LoadEbook('" + EbookListArray[x] + "');><br>"; } // For some ****ed up reason the first string always generates an 'undefined' even though it's nonsense // So just delete that from the HTMLdata string, because it's just ugly - LOL HTMLdata = HTMLdata.replace("undefined", ""); HTMLdata = HTMLdata.replace("", " "); // Write the HTML data to the DIV document.getElementById("FileManager").innerHTML = HTMLdata; } function LoadEbook(EbookName) { // Hide the File Manager and Show the Ebook Canvas document.getElementById("FileManager").style.visibility = "hidden"; document.getElementById("EbookCanvas").style.visibility = "visible"; document.getElementById("EbookToolbar").style.visibility = "visible"; // Load the Ebook content into the Ebook Reader Pannel var EbookContent = LoadFromDisk(SystemPath + EbookName); document.getElementById("EbookCanvas").innerHTML = EbookContent; } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } </script> </head> <body onLoad="Init();"> <div id="FileManager" style="position: absolute; top: 0px; left: 0px; visibility: visible;"> The eBook Library's List of Books will be listed here. Click on one to open it in the eBook Reader </div> <br> <div id="EbookCanvas" style="position: absolute; top: 0px; left: 0px; visibility: hidden;"> </div> <br> <div id="EbookToolbar" style="position: absolute; top: 100px; left: 0px;"> <input type="button" value="Open" OnClick="Init();"> <input type="button" value="Update" OnClick="UpdateEbookList();"> <input type="button" value="Exit" OnClick="MainMenu();"> </div> </body> </html> Similar TutorialsWhen i try to understand why a control is not raised - i check the F12 "code".. then, when i look for the required control there - it appears under CDATA tag. So - why? thx, Rach Hi guys.. I really need a bit of help.. is anyone looking at this good with JS? I have a php form validation script but i think its a bit slow and would rather a JS script instead... here is what i have in php.. PHP Code: <?php if(isset($_POST['submit'])) { $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $mobile = $_POST['mobile']; $comments = $_POST['comments']; $errors = array(); function display_errors($error) { echo "<p class=\"formMessage\">"; echo $error[0]; echo "</p>"; } function validateNames($names) { return(strlen($names) < 3); } function validateEmail($strValue) { $strPattern = '/([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})/sim'; return(preg_match($strPattern,$strValue)); } function validateMobile($strValue) { $strPattern = '/^\d{10}$/'; return(preg_match($strPattern,$strValue)); } function validateComments($comments) { return(strlen($comments) < 10); } if(validateNames($firstName)) { $errors[] = 'Please Enter Your First Name'; } if(validateNames($lastName)) { $errors[] = 'Please Enter Your Second Name'; } if(!validateEmail($email)) { $errors[] = 'Please Enter Your Correct Email'; } if(!validateMobile($mobile)) { $errors[] = 'Please Enter Your Correct Mobile Number'; } if(validateComments($comments)) { $errors[] = 'Please Enter A Comment More Than 10 Characters'; } if(empty($errors)) { $to = "info@eventpromotion.ie"; $subject = "Event Promotion Enquiry!"; $body = "First Name: " . $_POST['firstName'] . "\nLast Name: " . $_POST['lastName'] . "\nEmail: " . $_POST['email'] . "\nMobile: " . $_POST['mobile'] . "\nMessage: " . $_POST['comments']; $headers = "From: ". $firstName ." ". $lastName . " <" . $email . ">\r\n"; if (mail($to, $subject, $body, $headers)) { echo("<p class=\"formMessage\">Thanks for submitting your enquiry.</p>"); } else { echo("<p class=\"formMessage\">Message delivery failed.</p>"); } } else { //echo "error"; display_errors($errors); } } ?> <form id="form" method="post" action="index.php#quickContact"> <p> <label>First Name</label><br /> <input type="text" name="firstName" value="<?php if(isset($firstName)){echo $firstName;} ?>" /> </p> <p> <label>Last Name</label><br /> <input type="text" name="lastName" value="<?php if(isset($lastName)){echo $lastName;} ?>" /> </p> <p> <label>Email:</label><br /> <input type="text" name="email" value="<?php if(isset($email)){echo $email;} ?>" /> </p> <p> <label>Mobile:</label><br /> <input type="text" name="mobile" value="<?php if(isset($mobile)){echo $mobile;} ?>" /> </p> <p> <label>Comments:</label> <br /> <textarea name="comments" cols="30" rows="3" ><?php if(isset($comments)){echo $comments;} ?></textarea> </p> <p> <input class="send" type="image" src="images/submit2.gif" name="submit" value="Submit" /></p> </form> does anyone know how to transfer this to JS so that it will be easy to understand.. Im not good with JS at all Hi, I am new here without any coding skills but willing to learn. I know how to use html code. I am thinking of how to write the code for below scenario to create a simple online customize calculator: There is 1 box which allow us to enter any number=x (representing amount of money). So whenever we entered a number in the box and click "CALCULATE" buton below the box, there will be 3 results generated in 3 boxes below it based on the set of of rules i.e. 1. if the amount entered is <21,000 Result 1 = 1.5%*x*12 Result 2 = 1.5%*x*48 Result 3 = 1.5%*x*120 2. if the amount entered is >=21,000 and <210,000 Result 1 = 1.8%*x*12 Result 2 = 1.8%*x*48 Result 3 = 1.8%*x*120 3. if the amount entered is >=210,000 Result 1 = 2.2%*x*12 Result 2 = 2.2%*x*48 Result 3 = 2.2%*x*120 I understand that this code will involve If...else if...else Statement.. Anyone can give me any references/examples similar to this scenario? Thanks. Hello! I am trying to create a javascript code in which I prompt the user for a number (an integer from 0 to 100) to search for, then search a function with the number they entered and then display whether the number was found, and if found, a location where it can be found within the list. Can you please tell me what is wrong? <html> <head> </head> <body> <script language = "javascript"> var list = new Array(200); for (var i=0; i < 200; i++){ list=Math.round(Math.random()*100) + " "; document.write(list); } var value=prompt("What is the number you are searching for? ", " "); if (list[i]==value){ {alert("Number has been found in location" +i)}; } </script> </body> </html> Thank you Hello! Im having problem generating the labels for content created by the following function: Code: function setOutput(){ if(httpObject.readyState == 4){ var answer = httpObject.resultsponseText.split(","); var results = document.getElementById("resultsultadosScan1"); var article = document.createElement("div"); var weight = document.createElement("div"); var price = document.createElement("div"); article.className = "article"; weight.className = "weight"; price.className = "price"; document.getElementById('outputText0').value = httpObject.innerHTML= answer[0]; document.getElementById('outputText1').value = httpObject.innerHTML= answer[1]; document.getElementById('outputText2').value = httpObject.innerHTML= answer[2]; article.innerHTML = httpObject.innerHTML= answer[0]; weight.innerHTML = httpObject.innerHTML= answer[1]; price.innerHTML = httpObject.innerHTML= answer[2]; results.appendChild(article); results.appendChild(weight); results.appendChild(price); } } A friend wrote this sample script to achieve generation of labels on my script, but I have been trying for hours with no luck, can someone take a look and tell me the correct usage of this script: Code: function createLabel() { var target = document.getElementById("target"); var label = document.createElement("label"); var text = document.createTextNode("Article"); label.appendChild(text); target.appendChild(label); } Can you help me with the correct "combination" using my script above, a "real life" example? Thanks a lot! I would like for the script to say "Ok here is the button on this page *clicks* (or submit)" I have tried this with out help, I'm not really sure what to do. I've tried learning what I can on my own, I've tried using the search tool. Here is the part of the code I am trying to use to make my click button. Code: <div id="interactiveBox"> <div class="divpad3"> <form name="buyform" method="POST" action="/marketplace/userstore/2690240/buy/?id=567595175&step=submit" ENCTYPE="application/x-www-form-urlencoded"> <strong>Buy It Now</strong> <strong>Password</strong> <input type="password" class="marketplaceInputField" name="password"> <input type="hidden" name="nonce" value="860307364.1283901229.441212630"> <button type="submit" class="cta-button-sm"><span>Buy Now</span></button> <br /><br /> </form> Here is what I have tried and failed.. This code will be used in combination with greasemonkey Code: <script>function clickOnLoad() { document.buyform.submit.value = "true"; } body onload="clickOnLoad()"</script> Hi all. I'm having some trouble w/ my radiobutton code and i dont know why. for instance if i select yes for the 1st radio button, and no for the 2nd, instead of doing what it should do for no, it gets rid of w/e it did for yes.. also, if i enter something into the 1st box, and select another radio button, it deletes w/e is in all boxes... Code: <html> <head><title>So you want to make a website?</title></head> <body> <script> var lvl=0; var cssbgc=0; var ischecked=0; var isgroup1=0; var isgroup2=0; function get_funcs(lvl){ if(lvl == "Easy"){ a='<hr>\n'; a+='<h1>Website Controls</h1>\n'; a+='Do you want to add a title to your website?<br>\n'; a+='Yes <input onclick="checkchecks()" type="radio" name="group1" value="Yes"> No<input onclick="checkchecks()" type="radio" name="group1" value="No"><br><br>\n'; a+='<div id="websitep">- Does not want website title</div><br>\n'; a+='Do you want to add a background image to your website?<br>\n'; a+='Yes <input onclick="checkchecks()" type="radio" name="group2" value="Yes1"> No<input onclick="checkchecks()" type="radio" name="group2" value="No1"><br><br>\n'; a+='<div id="websiteq">- Does not want website background</div><br>\n'; a+='Your Website scripts:<br><input name="websitescripts" type="text" size="30"> <a href="javascript:answerq(\'websitescripts\');">Help?</a><br>\n'; a+='<br>Your website content (this will appear inbetween <body></body>)<br>This can be done for you if you wish: <a href="javascript:answerq(\'webcontent\');">Help?</a><br><textarea rows="15" cols="45" id="websitecontent" name="websitecontent"></textarea><br>\n'; a+='<input type="button" value="Submit" name="sub1" id="sub1" onClick="checkconts(lvl)"><br>\n'; a+='<h1>Your Website</h1><hr>\n'; a+='<textarea rows="15" cols="45" id="websitelvl" name="websitelvl"></textarea>\n'; document.getElementById("websitecontrols").innerHTML = a; }else if(lvl == "Medium"){ a='<hr>\n'; a+='<h1>Website Controls</h1>\n'; a+='<table>\n'; a+='<tr><td>\n'; a+='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n'; a+='Your Website scripts:<br><input name="websitescripts" type="text" size="30"> <a href="javascript:answerq(\'websitescripts\');">Help?</a><br>\n'; a+='Do you want a website background color using css?<br><br>Yes<input onclick="check()" type="checkbox" value="Yes" id="group1" name="group1"> No<input onclick="check()" type="checkbox" value="No" id="group1" name="group1"><br>\n<div id="cssbc"></div>\n'; a+='<br>Your website content (this will appear inbetween <body></body>)<br>This can be done for you if you wish: <a href="javascript:answerq(\'webcontent\');">Help?</a><br><textarea rows="15" cols="45" id="websitecontent" name="websitecontent"></textarea><br>\n'; a+='<input type="button" value="Submit" name="sub1" id="sub1" onClick="checkconts(lvl)"><br>\n'; a+='</td></tr>\n'; a+='</table>\n'; a+='<h1>Your Website</h1><hr>\n'; a+='<textarea rows="15" cols="45" id="websitelvl" name="websitelvl"></textarea>\n'; document.getElementById("websitecontrols").innerHTML = a; } } function checkchecks(){ for (i=0; i<document.forms.radioform.group1.length; i++){ if(i == 0 && document.forms.radioform.group1[i].checked == true){ ischecked = 1; isgroup1 = 1; isgroup2 = 0; }else if(i == 1 && document.forms.radioform.group1[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } for (i=0; i<document.forms.radioform.group2.length; i++){ if(i == 0 && document.forms.radioform.group2[i].checked == true){ ischecked = 1; isgroup1 = 0; isgroup2 = 1; }else if(i == 1 && document.forms.radioform.group2[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } if(isgroup1 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='Your Website Title:<br><input name="webtitle" type="text" size="30"> <a href="javascript:answerq(\'webtitle\');">Help?</a><br>\n'; document.getElementById("websitep").innerHTML = a; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website title<br>\n'; document.getElementById("websitep").innerHTML = a; } if(isgroup2 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); b='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n'; document.getElementById("websiteq").innerHTML = b; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website background image<br>\n'; document.getElementById("websiteq").innerHTML = b; } alert('isgroup1:'+isgroup1+'|'+'isgroup2:'+isgroup2+''); } function check(){ for (i=0; i<document.forms.radioform.website.length; i++){ if(document.forms.radioform.website[i].checked == true){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); if(i == 0 && document.forms.radioform.website[1].checked == true){ cssbgc = 0; document.forms.radioform.website[1].checked = false; }else if(i == 1 && document.forms.radioform.website[0].checked == true){ cssbgc = 1; document.forms.radioform.website[0].checked = false; } } } if(cssbgc == 0){ alert('ok then'); }else if(cssbgc == 1){ document.getElementById("cssbc").innerHTML = ""; } } function preview_website(){ if(document.forms.radioform.websitecontent.value != ""){ alert('Previewing your website...'); a='<center><h1>Website Preview<\/h1><\/center>\n<br><br>\n'; a+=document.forms.radioform.websitecontent.value+'\n'; document.write(a); } } function previewconts(){ if(document.forms.radioform.websitecontent.value != "" || document.forms.radioform.webtitle.value != "" || document.forms.radioform.webback.value != "" || document.forms.radioform.weblvl.value != ""){ preview_website(lvl); }else{ alert('Please enter something into the box before continuing...'); } } function checkconts(lvl){ if(document.forms.radioform.websitecontent == null || document.forms.radioform.websitecontent == null || document.forms.radioform.webtitle == null || document.forms.radioform.webback == null || document.forms.radioform.weblvl == null){ alert('Please select an option 1st...'); }else if(document.forms.radioform.websitecontent.value == null || document.forms.radioform.websitecontent.value == null || document.forms.radioform.webtitle.value == null || document.forms.radioform.webback.value == null || document.forms.radioform.weblvl.value == null){ alert('Please enter something into the box before continuing...'); }else{ a=document.forms.radioform.websitelvl.value = website(lvl); document.getElementById('websitecontent').innerHTML = a; } } function get_option(which){ if(which == "webtitle"){ return document.radioform.webtitle.value; }else if(which == "webback"){ return document.radioform.webback.value; }else if(which == "websitecontent"){ return document.radioform.websitecontent.value; }else if(which == "websitescripts"){ return document.radioform.websitescripts.value; } } function answerq(divname){ if(divname == "webtitle"){ alert('This is where you enter the name of your website that appears in the top left corner of your web browser.'); }else if(divname == "webback"){ alert('This is where you enter a background image link or a select a picture from your hard drive (IE: When selected you will see something like C:/mypics/pic.jpg appear in the box).'); }else if(divname == "webcontent"){ alert('this is where you enter what you want to appear on the page (this can be done for you if you wish).'); }else if(divname == "websitescripts"){ alert('This is where you enter any file locations to your script file(s).'); } } function website(lvl){ if(lvl == "Easy"){ a = "<html>\n"; a += "<head><title>"+get_option('webtitle')+"</title></head>\n"; if(document.forms.radioform.webback.value == ""){ a += "<body>\n"; }else{ a += "<body background=\""+get_option('webback')+"\">\n"; } if(document.forms.radioform.websitecontent.value != ""){ a += get_option('websitecontent')+"\n"; a += "</body>\n"; }else{ a += "</body>\n"; } a += "</html>\n"; } return a; } function callcontrols(lvl){ if(lvl == "Easy" || lvl == "Medium" || lvl=="Hard" || lvl == "Extreme"){ get_funcs(lvl); }else{ document.getElementById("websitecontrols").innerHTML = "NO!"; } } function getwebsite(lvl){ if(lvl == "Easy" || lvl == "Medium" || lvl == "Hard" || lvl == "Extreme"){ callcontrols(lvl); } } function get_radio_value() { for (var i=0; i < document.radioform.website.length; i++) { if (document.radioform.website[i].checked) { var rad_val = document.radioform.website[i].value; getwebsite(rad_val); } } lvl = rad_val; alert(lvl); } </script> <center> <h1>So you want to build a website?</h1><br> Easy - HTML Website<br> Medium - HTML / JavaScript / CSS Website<br> Hard - HTML / JavaScript / CSS / PHP Website<br> Extreme - HTML / Encrypted HTML / JavaScript / Encrypted JavaScript / CSS / PHP Website<br><br> You have four choices: <br> <form name="radioform"> Step 1:<br>Choose an option<br><br> Easy<input type="radio" onclick="get_radio_value()" name="website" value="Easy">Medium<input onclick="get_radio_value()" type="radio" name="website" value="Medium">Hard<input onclick="get_radio_value()" type="radio" name="website" value="Hard">Extreme<input onclick="get_radio_value()" type="radio" name="website" value="Extreme"><br><br> <div id="websitecontrols"></div> </form> </center> </body> </html> The functions you are looking at are checkchecks() and checkconts(). here's the functions: checkchecks(): Code: function checkchecks(){ for (i=0; i<document.forms.radioform.group1.length; i++){ if(i == 0 && document.forms.radioform.group1[i].checked == true){ ischecked = 1; isgroup1 = 1; isgroup2 = 0; }else if(i == 1 && document.forms.radioform.group1[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } for (i=0; i<document.forms.radioform.group2.length; i++){ if(i == 0 && document.forms.radioform.group2[i].checked == true){ ischecked = 1; isgroup1 = 0; isgroup2 = 1; }else if(i == 1 && document.forms.radioform.group2[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } if(isgroup1 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='Your Website Title:<br><input name="webtitle" type="text" size="30"> <a href="javascript:answerq(\'webtitle\');">Help?</a><br>\n'; document.getElementById("websitep").innerHTML = a; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website title<br>\n'; document.getElementById("websitep").innerHTML = a; } if(isgroup2 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); b='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n'; document.getElementById("websiteq").innerHTML = b; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website background image<br>\n'; document.getElementById("websiteq").innerHTML = b; } alert('isgroup1:'+isgroup1+'|'+'isgroup2:'+isgroup2+''); } checkconts(): Code: function checkconts(lvl){ if(document.forms.radioform.websitecontent == null || document.forms.radioform.websitecontent == null || document.forms.radioform.webtitle == null || document.forms.radioform.webback == null || document.forms.radioform.weblvl == null){ alert('Please select an option 1st...'); }else if(document.forms.radioform.websitecontent.value == null || document.forms.radioform.websitecontent.value == null || document.forms.radioform.webtitle.value == null || document.forms.radioform.webback.value == null || document.forms.radioform.weblvl.value == null){ alert('Please enter something into the box before continuing...'); }else{ a=document.forms.radioform.websitelvl.value = website(lvl); document.getElementById('websitecontent').innerHTML = a; } } Hi.. I don't know if my idea is possible and if how can I do that. I have functions for button onclick. I have 3 buttons and I want to change the color of my button if it is active here is my code Code: <script type="text/javascript"> //=========display parameter settings==========// function display_PS(){ document.loading_kanban.action="ParameterSettings.php"; document.loading_kanban.submit(); } //=======display kanban=========// function display_Kanban(){ document.loading_kanban.action="kanban_report.php"; document.loading_kanban.submit(); } //=========display SR==========// function display_SR){ document.loading_kanban.action="StockRequisition.php"; document.loading_kanban.submit(); } </script> <div id="main_button"> <input type="button" name="parameter_settings" value="Parameter Settings" onclick="display_PS()"> <input type="button" name="parameter_settings" value="Stock Requisition" onclick="display_SR()"> <input type="button" name="parameter_settings" value="Kanban Report" onclick="display_Kanban()"> </div> Is it possible to add code in my function for css active button..If no what should I do to change the color of my button for the client to know what page she is. Thank you Hi, I have 31 audio files and want to play one each day from a single html button. I have the audio files in the same directory as the html page. I have tried to adapt some code to do this, but have not had success. Any help would be much appreciated! Here is what I have so far: Code: <body> <button id="button" onclick=" " return false">Play</button> </body> <script type="text/javascript"> var currentDay = (new Date()).getDate(); document.getElementById('button').onclick = "proverbs" + currentDay + ".mp4" ; </script> I have some code that will check a users screen resolution and open a new window with a particular version of my website in, I have several sites for different page sizes. But when this code runs in Safari the pop-up is blocked so I would like the image on my page to be a button that runs the code to open the 'correct' window (based on the screen res) and as a button is launching the new window Safari should be okay about it. Unless I am doing something wrong? http://www.meta.projectmio.com/pop.html But how do I modify the code to do this, I'm hopeless? Thanks. Here's my HTML: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>The Happy Hoppin' Hotel</title> <script src="happyhoppin.js" language="javascript" type="text/javascript"></script> </head> <body> <h1>The Happy Hoppin' Hotel Checkout Page</h1> <h2>Fill out the form below to calculate balance due</h2> <form> Guest ID Number: <input type="text" id="guestID" /> <br /> <br /> Room Type: <select id="roomType"> <option></option> <option>Parlor</option> <option>Single</option> <option>Double</option> </select> <br /> <br /> Length of Stay: <input type="text" id="stayLength" /> <br /> <br /> Number of Drinks: <input type="text" id="drinkNumber" /> <br /> <br /> Number of Towels: <input type="text" id="towelNumber" /> <br /> <br /> Number of Flushes: <input type="text" id="flushNumber" /> <br /> <br /> Bug Complaints?: <br /> <form name="bugComplaintRadio"> <input type="radio" name="bugComplaint" value="No" />No</label> <br /> <input type="radio" name="bugComplaint" value="Yes" />Yes</label> <br /> </form> <br /> Customer Comments: <br /> <textarea name="customerComment" cols="50" rows="5">Enter your comments here...</textarea> <br /> <br /> <input type="button" onclick="calculateBill()" value="Calculate Bill"> </form> </body> </html> Here's my Javascript: Code: const parlorPrice = 80; const singlePrice = 100; const doublePrice = 150; const drinkPrice = 5; const towelPrice = 3; const flushPrice = 1; var guestID = 0; var roomPrice = 0; var stayLength = 0; var drinkNumber = 0; var towelNumber = 0; var flushNumber = 0; var totalDue = 0; var totalCharge = 0; function calculateBill(){ validateForm(); //roomType// if(roomType == "Parlor"){ roomPrice = parlorPrice; } if(roomType == "Single"){ roomPrice = singlePrice; } if(roomType == "Double"){ roomPrice = doublePrice; } //roomType// //drinkCharge// drinkCharge = drinkNumber * drinkPrice; //drinkCharge// //towelCharge// towelCharge = towelNumber * towelPrice; //towelCharge// //flushCharge// flushCharge = flushNumber * flushPrice; //flushCharge// //totalCharge// totalCharge = roomPrice + drinkCharge + towelCharge + flushCharge; //totalCharge// //**bugDiscount**// function getCheckedRadio() { bugValue = ""; bugLength = document.bugComplaintRadio.bugComplaint.length; var bugDiscount = 0; for (x = 0; x < bugLength; x ++) { if (document.bugComplaintRadio.bugComplaint[x].checked) { bugValue = document.bugComplaintRadio.bugComplaint[x].value; } } if (bugValue == "") { alert("You did not choose whether you had a bug complaint or not"); } if (bugValue = "No"){ bugDiscount = 0; } if (bugValue = "Yes"){ bugDiscount = 20; } } //**bugDiscount**// getCheckedRadio(); //totalDue// totalDue = totalCharge + bugDiscount //totalDue// displayBill(); } function validateForm(){ //guestID// guestID = parseInt(document.getElementById("guestID").value); if(isNaN(guestID)){ alert("Guest ID must be a number"); return; } if(guestID <= 0){ alert("Guest ID must be greater than zero"); return; } //guestID// //roomType// roomType = document.getElementById("roomType").value; if(roomType == ""){ alert("Room type must be selected"); return; } //roomType// //stayLength// stayLength = parseInt(document.getElementById("stayLength").value); if(isNaN(stayLength)){ alert("Length of stay must be a number"); return; } if(stayLength <= 0){ alert("Length of stay must be greater than zero"); return; } //stayLength// //drinkNumber// drinkNumber = parseInt(document.getElementById("drinkNumber").value); if(isNaN(drinkNumber)){ alert("Number of drinks must be a number"); return; } if(drinkNumber <= 0){ alert("Number of drinks must be greater than zero"); return; } if(drinkNumber > 25){ alert("Number of drinks has exceeded 25"); return; } //drinkNumber// //towelNumber// towelNumber = parseInt(document.getElementById("towelNumber").value); if(isNaN(towelNumber)){ alert("Number of towels must be a number"); return; } if(towelNumber <= 0){ alert("Number of towels must be greater than zero"); return; } //towelNumber// //flushNumber// flushNumber = parseInt(document.getElementById("flushNumber").value); if(isNaN(flushNumber)){ alert("Number of flushes must be a number"); return; } if(flushNumber <= 0){ alert("Number of flushes must be greater than zero"); return; } //flushNumber// //customerComment// customerComment = document.getElementById("customerComment"); //customerComment// } function displayBill(){ var newPage = "<html><head><title>Billing Summary</title></head>"; newPage += "<body><h1>Happy Hoppin Hotel</h1>"; newPage += "<h2>Guest Billing Statement</h2>"; newPage += "Guest Identification: #" + guestID; newPage += "<br />"; newPage += "Room Type: " + roomType; newPage += "<br />"; newPage += "Room Charge: $" + roomPrice; newPage += "<br />"; newPage += "Length of Stay: " + stayLength + " days"; newPage += "<br />"; newPage += "Drink Charge: $" + drinkCharge; newPage += "<br />"; newPage += "Towel Charge: $" + towelCharge; newPage += "<br />"; newPage += "Flushing Charge: $" + flushCharge; newPage += "<br />"; newPage += "Total Charge: $" + totalCharge; newPage += "<br />"; newPage += "Discount: $" + bugDiscount; newPage += "<br />"; newPage += "Total Due: $" + totalDue; newPage += "<br />"; newPage += "<h3>Come back and visit us again at the Happy Hoppin' Hotel!</h3>"; var z = window.open("","","width=400,height=500"); z.document.write(newPage); z.document.close(); } My question is, I've been spending countless hours trying to: 1. Make two radio buttons indicating "No" and "Yes", 2. Retrieve which selection the user has made, 3. Change the value of "bugDiscount" or the amount of money ($20 or $0) depending on which choice the user made; $0 for No & $20 for Yes. 4. Subtract the value of bugDiscount (0 or 20) from the totalCharge to get TotalDue I know I'm close, but I've tried any number of variations in my code and I still can't seem to get it right. Can anyone help? basically i have a form with lots of fields.. drop down boxes and textarea's and standard input text.. now what i need is a way to change all of these fields with a fetch button. i can get the value for the fields from the perl script on my server side. the form basicslly sends lots of fields to my perl script and saves each field of data into seperate text docs. now my customer would like to retrieve the data back to the form to change aspects of it to be resubmitted . i am struggling with the simplist of codes to set the value of the fields from a javascript variable any ideas please. I need this code to calculate the sales tax when you hit the submit button and I can't get it to work. I need to figure out how to connect it to the function. Can someone please point out where I am going wrong? I am very new at this and am woundering what I am doing wrong with my code. This is homework, I am not looking for the answer I just need someone to direct me in the right way.Thanx Here is my Code: I need this code to calculate the sales tax when you hit the submit button and I can't get it to work. Can someone please point out where I am going wrong? Code: <script type="text/javascript"> /*<![CDATA [*/ //Shipping & handling fee function calculateShipping() { var num = new Number(price); //This will add $1.50 to any purchases that are less than or equal to $25.00. if (num <= 25){ return 1.5; //Here 10% will be added to any purchase that is greater than $25.00 but do not inlcude the $1.50 fee. } else{ return num * 10 / 100; } } window.alert("Your total is $" + total + ".") /* ]]> */ </script> </head> <body> <h1>Enter Purchase Price Here</h1> <script type="text/javascript"> /* <![CDATA[ */ document.write(parseFloat"); if(price <=25.00){var shipping=1.50} else{var shipping=price*(10/100)}; var total=(price+shipping).toFixed(2); /* ]]> */ </script> <form id="btncalcprice" action="submit-form.php"> <input type='text' name='query'> </form> <form> <input type="button" value="Submit" onClick="alert('YOUR total is $'); return true"> </form> </body> This post will contain a few guidelines for what you can do to get better help from us. Let's start with the obvious ones: - Use regular language. A spelling mistake or two isn't anything I'd complain about, but 1337-speak, all-lower-case-with-no-punctuation or huge amounts of run-in text in a single paragraph doesn't make it easier for us to help you. - Be verbose. We can't look in our crystal bowl and see the problem you have, so describe it in as much detail as possible. - Cut-and-paste the problem code. Don't retype it into the post, do a cut-and-paste of the actual production code. It's hard to debug code if we can't see it, and this way you make sure any spelling errors or such are caught and no new ones are introduced. - Post code within code tags, like this [code]your code here[/code]. This will display like so: Code: alert("This is some JavaScript code!") - Please, post the relevant code. If the code is large and complex, give us a link so we can see it in action, and just post snippets of it on the boards. - If the code is on an intranet or otherwise is not openly accessible, put it somewhere where we can access it. - Tell us any error messages from the JavaScript console in Firefox or Opera. (If you haven't tested it in those browsers, please do!) - If the code has both HTML/XML and JavaScript components, please show us both and not just part of it. - If the code has frames, iframes, objects, embeds, popups, XMLHttpRequest or similar components, tell us if you are trying it locally or from a server, and if the code is on the same or different servers. - We don't want to see the server side code in the form of PHP, PERL, ASP, JSP, ColdFusion or any other server side format. Show us the same code you send the browser. That is, show us the generated code, after the server has done it's thing. Generally, this is the code you see on a view-source in the browser, and specifically NOT the .php or .asp (or whatever) source code. Quote: <html> <body> <script type="text/javascript"> N = prompt ("Enter your Name", "") Q1 = prompt ("Enter your First grade", "") Q2 = prompt ("Enter your Second grade", "") Q3 = prompt ("Enter your Third grade", "") CS.toFixed() = parseInt(Q1) + parseInt(Q2) + parseInt(Q2)/3 M.toFixed() = prompt ("Enter your Major Exam", "") M.toFixed() = ((CS.toFixed()*.6) + (M.toFixed()*.4)) document.write ("Your grade is " + CS.toFixed() + M.toFixed()) </script> </body> </html> My problem is i want the output to not show points (2.7, 3.3) The code works when i dont put .toFixed() on my code also it shows it on document.write but when i put .toFixed() on my code it doesnt show up on document.write already tinkering it for half an our now but i give up here is the html code that i have PHP Code: <td valign="middle" valign="middle"> <input type="radio" name="gender" id="genderM" value="Male" /> Male <input type="radio" name="gender" id="genderFM" value="Female" /> Female </td> and here is the js funtion PHP Code: var $j = jQuery.noConflict(); function isValidEmail(str) { return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); } function validateForm(){ var firstName; var lastName; var email; var mobile; var comment; var error; firstName = $j('#firstName').val(); lastName = $j('#lastName').val(); email = $j('#email').val(); mobile = $j('#mobile').val(); comment = $j('#comment').val(); if(firstName=='' || firstName.length < 3){ error = 'Please Enter Your First Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(lastName=='' || lastName.length < 3){ error = 'Please Enter Your Second Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } //mob //$jmob_pattern = '^\d{10}$j'; if(mobile.length != 10 || isNaN(mobile)){ error = 'Please Enter Your Mobile Number'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(email=='' || !isValidEmail(email)){ error = 'Please Enter Your Email Address'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(comment.length < 5){ error = 'Please Enter A Comment'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } return true; } Does anybody know how i check to see if the radio button is select and also can anybody tell me how i can check for an email in the correct format the function isValidEmail in the above alows emails to pass through if they are in this format aaa@aaa. i only want them to go through if they are aaa@aaa.com Thanks for your help if you give it hello, i am looking a a specific javascript code for a school project. what the code does is it re-sizes your window to a specific size, and then makes it jump around to the four corners of your screen. a perfect example of this would be the rick roll site called http://www.20b.org/rickroll.html its best viewed in internet explorer, and will take effect after you allow it on the top pop up window. it seems that the latest version of firefox disables the window resizing and movement, so use IE. after examining the page source, i managed to find this code. window.resizeTo(640,625); window.moveTo(0,0); for (i = 1; i <= 9; i++){ setTimeout('window.moveTo(1599,1199);', i+"000"); i++; setTimeout('window.moveTo(0,1199);', i+"000"); i++; setTimeout('window.moveTo(1599,0);', i+"000"); i++; setTimeout('window.moveTo(0,0);', i+"000"); } the code worked perfectly on the macs used at school. but however, when i took it home and tried it on my PC, which has a different sized monitor, it didnt work right. my copied code section seemed to jump off the edges of the screen, like it was using the size of a Macs monitor, yet the original website works fine. this led me to believe that the source code seems to find the size of the monitor and adjust the position of where it moves. i cant seem to find that part of the code. any help would be appreciated I need a java script code that can be installed in to my chrome (plugin) but all it will do is. Code: If (code) is display quite current tab. else if code isnt displayed leave tab open. The code would the zip code that is filled in on a page like this. http://www.locationary.com/place/en/...1023990998.jsp to see the code properly you need to sign in to the site (free sign up takes like 2 seconds) so if zip code is filled in then quit tab please any help on this would be great Hello, I have an html script and a .php script. The .php requests a random word from a table of words in a mysql database. I wrote a html form to display the requested word in a text box. Here is my html file: Code: <html> <body> <script type="text/javascript"> function myfunction() { var xmlhttp; if(window.XMLHttpRequest) { xmlhttp= newHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.myLingo.word.value=xmlhttp.responseText; } } xmlhttp.open("GET", "get_Word.php",true); xmlhttp.send(null); } </script> <form name="myLingo"> <input type="button" name="button" value="New Word" onClick="myFunction();" /> <input type="text" name="word" /> </form> </body> </html> and here is my .php script: Code: <?php $con=mysql_connect('localhost', 'xxxx', 'xxxx'); if (!$con) { die('Could not connect: '.mysql_error()); } mysql_select_db("my_lingo", $con); $sql=mysql_query("SELECT `word` FROM `words` ORDER BY RAND()") or trigger_error('Error: ' .mysql_error()); $word=mysql_fetch_array($sql); echo $word[0]; mysql_close($con); ?> When I run this in Internet Explorer; I get a error that is asking for an object on line 32 which is the line that has my button in the javascript. When i run it in firefox, I don't receive an error, but the page still does nothing. Any suggestions? The main function of the page is that, when I click the button, it's supposed to return me a random word from the .php script Thanks, jcjst21 Hi First sorry for my bad English! may any one interpret the JavaScript code below for me? A Device code ( a "random number") and the DVD code gives an activation code! Each install time a random number and thus a new activation code! i works in cookie base manner! clear cookie couse program become unusable and another activation will be needed! I want to change random Number to a fix one so it Becomes constant and does not change regularly! and then no need for change activation code... Where do I change? I'm sure help ... best regards thanks ----------------------------------------------------------------------------------- <html> <head> <title>Activation</title> <script type="text/javascript" src="../js/ajax.js"></script> <script type="text/javascript"> var _0x8834=["\x72\x65\x70\x6C\x61\x63\x65","\x68\x72\x65\x66", "\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x73\x65\x72\x 69\x61\x6C","\x61\x63\x74\x69\x76\x61\x74\x69\x6F\ x6E\x43\x6F\x64\x65","\x72\x61\x6E\x64","\x73\x75\ x62\x73\x74\x72\x69\x6E\x67","\x4D\x6F\x62\x69\x55 \x70\x54\x6F\x44\x61\x74\x65\x5F\x33","\x4D\x6F\x6 2\x69\x55\x70\x54\x6F\x44\x61\x74\x65\x5F\x34","\x 4D\x6F\x62\x69\x55\x70\x54\x6F\x44\x61\x74\x65\x5F \x35","\x2E\x2E\x2F\x4D\x6F\x62\x69\x55\x70\x54\x6 F\x44\x61\x74\x65\x2E\x68\x74\x6D\x3F"];function GET(){var _0x84efx2={};var _0x84efx3=window[_0x8834[2]][_0x8834[1]][_0x8834[0]](/[?&]+([^=&]+)=([^&]*)/gi,function (_0x84efx4,_0x84efx5,_0x84efx6){_0x84efx2[_0x84efx5]=_0x84efx6;} );return _0x84efx2;} ;if(GET()[_0x8834[3]]!=undefined&&GET()[_0x8834[4]]!=undefined&&GET()[_0x8834[5]]!=undefined){var num=(parseInt(GET()[_0x8834[3]][_0x8834[6]](0,7))%5555)*(parseInt(GET()[_0x8834[5]]%30)+1);if(num==parseInt(GET()[_0x8834[4]])){setf(_0x8834[7],GET()[_0x8834[5]]);setf(_0x8834[8],GET()[_0x8834[3]]);setf(_0x8834[9],GET()[_0x8834[4]]);window[_0x8834[2]]=_0x8834[10];} ;} ; </script> </head> <body align="center"> <h1>Activation</h1> To get activation code visit*************<br> <script language="javascript"> if (GET()['serial']!=undefined) document.write('<br>Incorrect serial or activation code. Try again please!<br>'); </script> <form action="./activation.htm?" method="GET"> <table align="center"> <tr> <td>Device code:</td> <td><script language="javascript"> if (getf('rand_num')==undefined) setf('rand_num', Math.floor(Math.random()*9999)); var rand_num=getf('rand_num'); document.write(rand_num+'<INPUT TYPE="hidden" NAME="rand" VALUE="'+rand_num+'">'); </script></td> </tr> <tr> <td>Serial</td> <td> <input name="serial"></input></td> </tr> <tr> <td>Activation code</td> <td> <input name="activationCode"></input></td> </tr> </table> <input type='submit' value="Activate"></input> </form> </body> </html> |