JavaScript - Function Result Not Displayed
Can anyonle pls explain me why the return function is not returning the result as intended? I appreciate you help
OUTPUT ====== Student : Doe,John eMail : johndoe@gmail.com Course ID : COIN-070B.01 -------------------------------- function task() { var title = ["Assignment1", "Assignment2", "Assignment3", "Assignment4", "Assignment5", "Mid Term", "Finals"]; var points = [30, 30, 28, 27, 29, 41, 45]; for (var i = 0; i < points.length; i++) { titlePoints += title[i] + (" : " + points[i] + "\n"); } return titlePoints; } Code: <head> <title>Variable - Examples 1</title> <script type="text/javascript"> function Student(firstName, lastName, email,courseID){ this.firstName = firstName; this.lastName = lastName; this.email = email; this.courseID = courseID; this.assignments = task; } Student.prototype = { constructor : Student, toString : studentInfo }; function task(){ var title = ["Assignment1","Assignment2","Assignment3","Assignment4","Assignment5","Mid Term", "Finals"] var points = [30, 30, 28, 27, 29,41,45]; var titlePoints = ""; for (var i=0; i < points.length; i++){ titlePoints += title[i] + " : " + points[i] + "\n"; } return titlePoints; } function studentInfo(){ return "Student : " + this.lastName + "," + this.firstName + "<br>"+ "eMail : " + this.email + "<br>" + "Course ID : " + this.courseID + "<br>" + "--------------------------------" + "<br>" + this.assignments; } var student = new Student("John", "Doe", "johndoe@gmail.com","COIN-070B.01"); </script> </head> <body> <script type="text/javascript"> document.writeln(student.toString()); </script> </body> </html> Similar TutorialsGood Day, I am very new to JavaScript and I am working on an assignment that is almost finished, but I have a problem getting the result to work. When I enter the two values and then hit submit, nothing is returned. I am guessing that either my code is incorrect or I have used the wrong ids maybe. Basically, the user enters 2 parameters (hourly wage and hours worked) and the first function turns the parameters into the gross pay (depends on if the hours are standard pay or if overtime is involved). The second function takes the gross pay and does the tax amounts for local, state and federal. Then it adds all taxes to give a total of tax amount paid. The input for the parameters is done by <input> tag. The return reslut is supposed to be just the number which is the total amount of taxes to be taken out. This all has to be done by <input> tags. Could someone look over the html and JS and help me find where the problem is at. The instructor said we could use ? : operator for determining the pay rates, but I found it easier to do if/else staements because I was not sure how you would script that. Any help would be great. Thanks HTML Code 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=iso-8859-1"> <title>Calculate Tax Amount</title> <link href="style.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="calculateGross.js"></script> <script type="text/javascript" src="calculateTax.js"></script> </head> <body> <table width="60%" border="0" cellpadding="0" cellspacing="2" align="center" class="view"> <tr> <td colspan="3" class="textview">Calculate the gross pay:</td> </tr> <tr> <td class="labeltext">Pay rate(dollars per hour)</td> <td>:</td> <td><input type="text" name="payrate" id="payrate" class="textval"></td> </tr> <tr> <td class="labeltext">Hours worked</td> <td>:</td> <td><input type="text" name="hours" id="hours" class="textval"></td> </tr> <tr> <td colspan="3" align="center"><input type="button" name="" value="Submit" onclick="return calculate(); "> </td> </tr> </table> <br> <br> <table width="60%" border="0" cellpadding="0" cellspacing="2" align="center" class="view"> <tr> <td colspan="3" class="textview">Total Tax Paid:</td> <tr> </tr> <td class="labeltext">Grand Total of Taxes</td> <td>:</td> <td><input type="text" name="total" id="totalTax" class="textval" disabled="disabled"></td> </tr> </table> </body> </html> First Function JS Code: function calculate() { var payRate = document.getElementById("payrate").value; var hoursWorked = document.getElementById("hours").value; var oTime; var oPay; var oHour; var grossPay; if(hoursWorked > 40) { oTime = Number ( hoursWorked ) - 40; oPay = Number ( ( payRate ) * 1.5 ) * oTime; oHour = Number ( hoursWorked )- Number ( oTime ); grossPay = Number ( payRate ) * Number ( oHour ) + Number ( oPay ); } else grossPay = Number ( hoursWorked ) * Number ( payRate ); } The second function JS Code: function calculateTax(gross) { var gross; var localTax; var localTaxBal; var stateTax; var stateTaxBal; var fedTax; var fedTaxBal; var totalTax; localTax = Number ( gross ) * 2/100; localTaxBal = Number ( gross ) - Number ( localTax ); stateTax = Number ( localTaxBal ) * 8/100; stateTaxBal = Number ( localTaxBal ) - Number ( stateTax ); fedTax = Number ( stateTaxBal ) * 31/100; fedTaxBal = Number ( stateTaxBal ) - Number ( FedTax ); totalTax = Number ( localTax.toFixed(2) ) + Number ( stateTax.toFixed(2) ) + Number ( fedTax.toFixed(2) ); return totalTax.toFixed(2); } I'm coding a simple random sentence generator & this is the beginning part of what I'm trying to accomplish. I created 3 different functions with 3 separate buttons & 3 separate text areas to display the noun, verb, or article once the button is pressed. However, when I press a button, nothing shows up in the text area! Can someone please tell me what I'm doing wrong & give me a fix? It has to be a simple problem, but I am very very new to this & need help. Thanks in advance! Code: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script language="JavaScript"> function noun() // Assumes: nothing // Returns: a random noun { return RandomOneOf(["man", "woman", "ball"]); } </script> <script language="JavaScript"> function verb() // Assumes: nothing // Returns: a random noun { return RandomOneOf(["hit", "liked", "smelled"]); } </script> <script language="JavaScript"> function article() // Assumes: nothing // Returns: a random noun { return RandomOneOf(["the", "a", "some"]); } </script> </head> <body> <input type="button" value="Noun" onclick="document.getElementById('OutNoun').value = noun();" /> <TEXTAREA ID="OutNoun" ROWS=1 COLS=15 WRAP VALUE=""></TEXTAREA> <input type="button" value="Verb" onclick="document.getElementById('OutVerb').value = verb();" /> <TEXTAREA ID="OutVerb" ROWS=1 COLS=15 WRAP VALUE=""></TEXTAREA> <input type="button" value="Article" onclick="document.getElementById('OutArticle').value = article();" /> <TEXTAREA ID="OutArticle" ROWS=1 COLS=15 WRAP VALUE=""></TEXTAREA> </body> </html> I will tell you now that I am not a javascript programmer and this is a very basic question. Please don't flame. I have been writing a web site and have found 2 functions that work and do what I want them to do, but I want to combine them. The first function will grab the window size.(it actually prints it out to the screen and I know how to get that to stop by taking out the last 2 lines) What I want to do with the results from the function alertSize() is exactly what the function res() does though. I want it to take the window size and jump to the appropriate web directory. What I don't know is if I can write that all as one function or if I have to pass the results of function alertSize() to function res(). Or how to do it for that matter, I don't even know what this is called in programming lingo. I am not asking for an answer here I would just like someone to point me in the right direction that I may learn a little more about what it is I want to do so I can get this to work. Giving me a search term would be a BIG help. Here is the first function. Code: // <script language="JavaScript"> //--> function alertSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } window.alert( 'width = ' + myWidth ); window.alert( 'height = ' + myHeight ); } // </script> //--> and the second function. Code: // <script language="JavaScript"> //--> function res() { alert('Screen Resolution Is '+screen.width+' by '+screen.height); } if ((screen.width>=1280) && (screen.height>=1024)) { window.location="/12/index.html"; } else if ((screen.width>=1024) && (screen.height>=768)) { window.location="/10/index.html"; } else if ((screen.width>=800) && (screen.height>=600)) { window.location="lowres1.html"; } else if ((screen.width>=640) && (screen.height>=480)) { window.location="lowres2.html"; } else { window.location="lowres3.html"; } // </script> //--> Hello all, I am new to these forms, and new to Javascript as well. I have gone through some lessons, and have been trying to write a simple script on my own. Here is what I am trying to do: I am calculating a volume, and want to display the result of that calculation. I then want to take the result and multiply it by 2 and display that as well. Here is what I have so far: Code: function volume (l, w, h) { return l * w * h; } console.log("Volume = " + volume (2, 2, 2)); So far so good... but I cant figure out how to then take that result that was displayed in the console and save it as a variable (if that would be the correct way to do it) so that I can modify the result by 2. I have tried several things with no luck. How can I save the result of a function or pass it to another function? Thanks in advance! Hello! I am working on creating a basic calorie calculator with Javascript and my code is not showing the results after the user makes their selections. I've created a simple function to obtain the user's weight, activity and duration info but when I use the GetElementById to retrieve the result, it does not show up. Any help would be much appreciated to make this work. Thanks. Code: <head> <script type="text/javascript"> var myActivity = new Array(); myActivity[100] = "6.670"; myActivity[200] = "3.811"; myActivity[300] = "3.343"; myActivity[400] = "3.343"; myActivity[500] = "3.343"; myActivity[600] = "4.765"; myActivity[700] = "4.765" function CalorieBurner() { //user prompt var caloriesBurned; var myForm = document.form; //processing var caloriesBurned = (myForm.duration[formElement.value] * (myActivity[formElement.value] * 3.5 * myForm.weight[formElement.value])/200); FormElement = myForm.activity[myForm.activity.selectedIndex]; document.getElementById("caloriesBurned").innerHTML = "You will burn " + caloriesBurned + "calories doing " + myForm.duration[formElement.value] + "minutes of " + FormElement.text; } </script> </head> <body> <form name="form"> Enter your weight: <input type="text" name="weight" /> <br /><br /> Select an activity: <br /> <select name="activity"> <option value="100"> Backpacking, Hiking with pack </option> <option value="200"> Bagging grass, leaves </option> <option value="300"> Bathing dog </option> <option value="400"> Carpentry, general</option> <option value="500"> Carrying infant, level ground </option> <option value="600"> Carrying infant, upstairs </option> <option value="700"> Children's games, hopscotch... </option> </select> <br /><br /><br /> Enter the duration of your activity (in minutes): <input type="text" name="duration" /> </form> <br /><br /><br /> <input type="button" value="Results" name="btnUpdate" onClick="CalorieBurner()"/> <br /><br /><br /> <div id="caloriesBurned"></div> </body> </html> First post - spent the whole afternoon trying to figure it out and have hit a wall. I'm trying to check a database of lotto numbers against 3 different values and have gotten it that to work. What I need is to give a feedback message if no match is found once the submit button is clicked. Code: function winCheck() { var grandPrize = $('#grandPrize').val(); var otherPrize = $('#otherPrize').val(); var addPrize = $('#addPrize').val(); var resultrange = $('#resultrange').val(); db.transaction( function(transaction) { transaction.executeSql( 'SELECT * FROM entries WHERE daterange = ? ORDER BY lottonum;', [resultrange], function lottoCompare(transaction, result){ for (var i=0; i < result.rows.length; i++) { var row = result.rows.item(i); rowData = [row.lottonum]; rowStr = rowData.toString(); //the if else statements should go here. if (rowStr == grandPrize){ alert('The lotto number ' + grandPrize + ' is a jackpot winner'); } if (rowStr.slice(-7) == otherPrize.slice(-7)){ alert('The lotto number ' + rowStr + ' is a winner of $40,000'); } if (rowStr.slice(-6) == otherPrize.slice(-6)){ alert('The lotto number ' + rowStr + ' is a winner of $10,000'); } if (rowStr.slice(-5) == otherPrize.slice(-5)){ alert('The lotto number ' + rowStr + ' is a winner of $4,000'); } if (rowStr.slice(-4) == otherPrize.slice(-4)){ alert('The lotto number ' + rowStr + ' is a winner of $1,000'); } if (rowStr.slice(-3) == otherPrize.slice(-3)){ alert('The lotto number ' + rowStr + ' is a winner of $200'); } if (rowStr.slice(-3) == addPrize){ alert('The lotto number ' + rowStr + ' is a winner of $200'); } } }, errorHandler ); } ); return false; } Any help is appreciated Hi, My webpage can work normally in IE but not in Safari(e.g. when I clicked on some buttons like 'Delete' button, the page opened in Safari stays the same while it should delete the object chosen). When I tried debugging on Safari, after clicking the 'update' button, this message error appeared: "TypeError: Result of expression 'this.form.fireEvent' [undefined] is not a function". I believe this code makes the incompatability between the 2 browser: Code: function DeleteClick() { var frmSWO = document.getElementById("form"); var answer = confirm("Do you really want to delete?") if (answer != 0) { frmSWO.action = "/domsWeb/mtd/doms/web/operation/eDepotMNR/controller/manageWorkOrder/DeleteJobOrImage.do"; frmSWO.method = "post"; this.form.fireEvent('onsubmit'); frmSWO.submit(); } } Any suggest how should I amend the script for it to work on 2 browser concurrently? Thanks all! Hi, I tried displaying few images as MENU using Javascript. These images are showed normally in Firefox and chrome except Internet Explorer. Help plz
Hello everyone! Hi, I am a complete beginner at Javascript(started a few days ago) and was having trouble with some functions. I'm trying to get the inputs required to change based on an option selected in a drop down menu. I was intending to run different scripts based on whatever is chosen but when I ran a test using an alert function, I realized my code isn't working. I went online and found really confusing stuff like "running a for loop through an array to make a dynamic select feature". Still confused any help would be appreciated. My code thus far: Code: <html> <head> <title>Practice</title> <script language="javascript"> function myScript() { var loanType = document.form1.loan.options.text if (loanType == "Bank A") { alert("Working") } } </script> </head> <body> <form name="form1"> <select id="loan" name="loan" onchange="myScript"> <option></option> <option>Bank A</option> <Option>Bank B</Option> </select> </form> </body> </html> Reply With Quote 01-29-2015, 12:02 PM #2 vwphillips View Profile View Forum Posts Visit Homepage Senior Coder Join Date Mar 2005 Location Portsmouth UK Posts 4,540 Thanks 3 Thanked 513 Times in 500 Posts Code: <html> <head> <title>Practice</title> <script language="javascript"> function myScript() { var s=document.form1.loan,loanType = s.options[s.selectedIndex].text if (loanType == "Bank A") { alert("Working") } } </script> </head> <body> <form name="form1"> <select id="loan" name="loan" onchange="myScript();"> <option></option> <option>Bank A</option> <Option>Bank B</Option> </select> </form> </body> </html> or better Code: <html> <head> <title>Practice</title> <script language="javascript"> function myScript(s) { if (s.value == "Bank A") { alert("Working") } } </script> </head> <body> <form name="form1"> <select id="loan" name="loan" onchange="myScript(this);"> <option></option> <option value="Bank A" >Bank A</option> <Option value="Bank B">Bank B</Option> </select> </form> </body> </html> Code: function my_fav_quote_show_optin_form() { if (!empty($_POST['my_fav_quote_email'])) { my_fav_quote_opt_in(); } $out2 = ''; $out = '<form action="" name="myform "method="post" id="requestQuote">'; $out .= '<table style="padding="0px" width="40px">'; $out .= '<tr><td>Name:*</td><td><input type="text" name="my_fav_quote_name" id="my_fav_quote_name"/></td></tr>'; $out .= ''; $out .= '<tr><td>Email:*</td><td><input type="text" name="my_fav_quote_email" id="my_fav_quote_email"/></td></tr>'; $out .= ''; $out .= '<tr><td>Phone:*</td><td><input type="text" name="my_fav_quote_phone" id="my_fav_quote_phone"/></td></tr>'; $out .= ''; $out .= '<tr><td>Event Date(optional):</td><td><input type="text" name="my_fav_quote_date" id="my_fav_quote_date"/></td></tr>'; $out .= ''; $out .= '<tr><td>Estimated Number of Guests(optional):</td><td><input type="text" name="my_fav_quote_guest" id="my_fav_quote_guest"/></td></tr>'; $out .= ''; $out .= '<tr><td>Desired Price Range Per Person (optional):</td><td><input type="text" name="my_fav_quote_rate" id="my_fav_quote_rate"/></td></tr>'; $out .= ''; $out .= '<tr><td style="vertical-align: middle;">Message:<br>(List your special requests, any food allergies , event description , special menu items that are not listed or any other information you think will helpful) </td><td><textarea placeholder="" name="my_fav_quote_message" id="my_fav_quote_message"></textarea></td></tr>'; $out .= ''; $out .= '<tr><td>Security code:*</td><td><img src='.get_bloginfo('wpurl').'/wp-content/plugins/quote-cart/captcha.php?width=60&height=30&characters=5" /></td></tr>'; $out .= ''; $out .= '<tr><td>Input Above Security Code He *</td><td><input type="text" name="security_code" id="security_code" size="5"></td></tr>'; $out .= ''; $out .='<tr><td colspan="2">'; if ( function_exists( 'my_fav_quote_display' ) ){ $out .= my_fav_quote_display(); } if ( function_exists( 'my_fav_quote_display3' ) ){ $out .= my_fav_quote_display3(); } $out .='</td></tr>'; $out .= '<tr><td colspan=2 align=center><input type="submit" value="Request Quote" onclick="return chk_validation()" style="background-color:#000;color:#FFF;padding:5px;margin-top:10px;border:none;cursor:pointer;"/> <input type="button" onclick="formReset()" value="Reset form" /> </td></tr>'; $out .='</table></form>'; echo $out; ?> <script language="javascript" type="text/javascript"> //<![CDATA[ function validate_email(field,alerttxt) { apos=field.indexOf("@"); // alert(apos); dotpos=field.lastIndexOf("."); //alert(dotpos); if (apos<1||dotpos-apos<2) { return false;} else {return true;} } function chk_validation() { if(document.getElementById("my_fav_quote_name") && document.getElementById("my_fav_quote_name").value == '') { alert("Please Enter Name"); document.getElementById("my_fav_quote_name").focus(); return false; } if(document.getElementById("my_fav_quote_email").value == '') { alert("Please Enter Email"); document.getElementById("my_fav_quote_email").focus(); return false; } else { //alert(validate_email(document.getElementById("my_fav_quote_email").value,"Not a valid e-mail address!"); if (validate_email(document.getElementById("my_fav_quote_email").value,"Please enter valid e-mail address!")==false) { alert("Please enter valid e-mail address!"); document.getElementById("my_fav_quote_email").focus(); return false; } } if(document.getElementById("security_code").value == '') { alert("Please Enter Security Code"); document.getElementById("security_code").focus(); return false; } if(document.getElementById("quotes").value == '') { alert("Please add atleast one request quote"); document.getElementById("quotes").focus(); return false; } //return true; } //]]> </script> <?php } can we reset the display functions data when we click on reset button? Hello. I have a <div> html element which contains other html tags, as well as plain text inside those tags. How do I grab only the content within the div that will actually be displayed in the browser, and put it in a Javascript string variable? Thanks in advance. 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 Hi, I am a complete beginner at Javascript(started a few days ago) and was having trouble with some functions. I'm trying to get the inputs required to change based on an option selected in a drop down menu. I was intending to run different scripts based on whatever is chosen but when I ran a test using an alert function, I realized my code isn't working. I went online and found really confusing stuff like "running a for loop through an array to make a dynamic select feature". Still confused any help would be appreciated. My code thus far: <html> <head> <title>Practice</title> <script language="javascript"> function myScript() { var loanType = document.form1.loan.options.text if (loanType == "Bank A") { alert("Working") } } </script> </head> <body> <form name="form1"> <select id="loan" name="loan" onchange="myScript"> <option></option> <option>Bank A</option> <Option>Bank B</Option> </select> </form> </body> </html> Reply With Quote 01-08-2015, 10:52 AM #2 Primus View Profile View Forum Posts New Coder Join Date Oct 2014 Posts 92 Thanks 0 Thanked 14 Times in 14 Posts Code: <script> function myScript() { var selectedIndex = document.form1.elements.loan.options.selectedIndex; // returns 0-2 in this case var loanType = document.form1.elements.loan.options[selectedIndex].value; // returns the value of the selected item if (loanType == "Bank A") { alert("Working") } } </script> <form name="form1"> <select id="loan" name="loan" onchange="myScript()"> <option></option> <option>Bank A</option> <option>Bank B</option> </select> </form> Maybe not the best way, but it does the trick. Reply With Quote 01-08-2015, 11:43 AM #3 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts You have quite a lot of obsolete code:- 1) It is obsolete to assign a name to a form and permitted only for the sake of backwards compatibility. 2) <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead (in fact also deprecated but still necessary for IE<9). 3) Scripts should normally be placed right in front of the </body> tag. Any script can optionally go in the head if you wrap it inside a load event listener so that it can't run before the page loads. 4) Use the value of a select box option, not the text. 5) It is recommended that you place the opening brace following the function, if, else, for, while, do, switch, and try statements on the same line and not on the following line. Apart from that every Javascript statement should be followed by a semi-colon (;). It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage. Code: <html> <head> <title>Practice</title> </head> <body> <form> <select id="loan" name="loan" onchange="myScript()"> <option value = "">Chosoe...</option> <option value = "Bank A">Bank A</option> <Option value = "Bank B">Bank B</Option> </select> </form> <script type = "text/javascript"> function myScript() { var loanType = document.getElementById("loan").value; if (loanType == "Bank A") { alert("Working") } } </script> </body> </html> If you really want to use the option text ... Code: <html> <head> <title>Practice</title> </head> <body> <form> <select id="loan" name="loan" onchange="myScript(this)"> <option value = "">Choose...</option> <option value = "Bank A">Bank A</option> <Option value = "Bank B">Bank B</Option> </select> </form> <script type = "text/javascript"> function myScript(element) { var loanType = element.options[ element.selectedIndex ].text; if (loanType == "Bank A") { alert("Working") } } </script> </body> </html> The Warrington players can hang their heads high. - Commentator, BBC Radio 2 Hi, I am new to this forum but I am in dire need of help. I am sorry if this isn't they way you normally do things. I read through some of the rules, but it is late and I am in a hurry. Any help would be greatly appreciated. I need the image file names in my array to be shown in the text box. I am not quite sure how to do this. I have been trying for some time but cannot figure it out. Here is my code. <head> <title>Asn4CStartup.htm by Todd Bowman</title> <style type="text/css" > h1, h2, h3 {font-family: 'arial black';} .controls { font-family: 'arial black'; font-size:10pt;} </style> <script type="text/javascript"> /* <![CDATA[ */ // Note: variables declared inside a function // using the var keyword are all local variables. It means that these // variables are only known inside the function. Other functions cannot see // the values. // On the other hand if a variable is declared outside any function, these are global // variables. The values of global variables are available in all other functions. // Other function can change the values of global variables. // Declare a global var n: var n=0; // we will use this global variable to keep track of exactly which element of the array // is being displayed now. When the user clicks Next button, we will add 1 to n and // then display the image file in the nth element of the array // Declare a global array that will contain the names of image files. var imgArray = new Array(); // The following function will be triggered on the onload event of the page. function fillArray() { // alert ("Hello on load"); imgArray[0]="Bus1.jpg"; imgArray[1]="Bus2.jpg"; imgArray[2]="Fam1.jpg"; imgArray[3]="Fam2.jpg"; imgArray[4]="Honey1.jpg"; imgArray[5]="Honey2.jpg"; imgArray[6]="Map1.png"; // for ( i in imgArray) // alert (imgArray[i]); } function showNext() // This function will be triggered on click of the Next button { // alert ("Hello showNext"); // alert(n); n = n+1; //alert (n); if (n > imgArray.length-1) { alert ('You are already on the last image'); n = n-1; } else document.getElementById('imgPic').src='images/'+imgArray[n]; } // end showNext() function showPrevious() // This function will be triggered on click of the Previous button { // alert("Hello Previous"); // alert(n); n = n-1; // alert (n); if (n < 0) { alert ('You are already at the first image'); n = n+1; } else document.getElementById('imgPic').src='images/'+imgArray[n]; } // end showPrevious() function showFirst() //This function will be triggered on click of the First button { // alert (n); if (n == 0) { alert ('You are already on the first image'); } else document.getElementById('imgPic').src='images/'+imgArray[0]; } function showLast() { // alert (n); if (n > imgArray.length-1) { alert ('You are already on the last image'); } else document.getElementById('imgPic').src='images/'+imgArray.length-1; } /* ]]> */ </script> </head> <body onload="fillArray();"> <div> <h1> Asn4CStartup.htm by Mesbah Ahmed </h1> <h2>Windsurf Image Navigation </h2> Name of the image file shown below:   <input type="text" id="imageName" size="20" readonly="readonly" /> <br/><br/> <img id="imgPic" src = "images/Bus1.jpg" alt="picture" width="500px" height="350px" /> <br/> <input type="button" value="Next" class="controls" onclick="showNext();" /> <input type="button" value="Previous" class="controls" onclick="showPrevious();" /> <input type="button" value="First" class="controls" onclick="showFirst();" /> <input type="button" value="Last" class="controls" onclick="showLast();" /> <br/> <p> <img src="http://www.w3.org/Icons/valid-xhtml11.png" alt="Valid XHTML 1.1!" height="31px" width="88px" /> <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue.png" alt="Valid CSS!" height="31px" width="88px" /> </p> </div> </body> </html> Hello, I am fairly new to javascript so patience is appreciated. I have some javascript I need to execute that is located in an SSI footer. The purpose of the code is to find out what domain the page was loaded at and then to tailor some links to match. Because of how the hosting environment is set up (which I have no control over) when the links don't match the domain they aren't included. I also have to use a complete url (as opposed to relative url) because the footer is included in many different web pages. The problem is that the code is executed but it also is displayed as plain text in firefox. The test site is http://test.ci.edina.mn.us Help! The code is: Code: <script type="text/javascript"> var domainName, strOut; domainName = document.domain; strOut = '<link rel="stylesheet" type="text/css" href="http://' + domainName + '/js/jquery.fancybox/jquery.fancybox.css" media="screen" />'; document.write(strOut); strOut = '<script src="http://' + domainName + '/js/jquery-1.3.2.min.js" type="text/javascript"></script>'; document.write(strOut); strOut = '<script src="http://' + domainName + '/js/jquery.fancybox/jquery.fancybox-1.2.1.js" type="text/javascript"></script>'; document.write(strOut); strOut = '<script src="http://' + domainName + '/js/jquery.easing.1.3.js" type="text/javascript"></script>'; document.write(strOut); </script> I have an iFrame that is loaded when a user types a url into a text box. Is it possible to display the meta-description of the page that is diplayed in the iFrame in the main (parent) page ? Here is the Iframe code I am using in the body: Code: <iframe src="http://www.mhgoebel.com" frameborder="0" id="frame" width="320" height="356" scrolling="no"> </iframe> and here is the script in the header: Code: <script> function goTo() { var input = get("box").value, frame = get("frame"); if(input.match(/\bhttp(.)*/)) { frame.src = input; } else { input = "http://" + input; frame.src = input; } } function get(id) { return document.getElementById(id); } </script> Working on an Adobe form (non web) The "Award" field is a bit troublesome. Award is not required every time therefore I left that out of it's field properties. I have also set the maxium amount of characters to 5. At times, it will be required therefore I want to set up validation that will return an error message if 1-3 characters are filled in but won't give any error message if 4 or 5 characters are entered in the field. I.e 0= Do nothing 1= Error 2= Error 3= Error 4= Do nothing 5= Do nothing Code: if ((event.value.length > 1) && (event.value.length < 4)) //trigger alert if 1-3 characters are entered { app.alert("The minimum amount of characters is 4"); event.rc = false; } else { // do nothing if 0,4 or 5 characters are entered } Hi, I'm trying to code a script that will display an approximate postage price based on different combinations of variables, but the numbers I defined for each case aren't reflected in the text box. I'm using a switch statement for all the different combinations of options, which the user will choose by selecting check-boxes. I'd really appreciate if anyone could point out where I'm going wrong. (Additionally, I know that this code probably isn't a very efficient way of doing what I'm doing - I'm open to suggestions on how to improve it.) I've attached all the relevant parts of the code, including how I defined variables originally. Many thanks in advance, Gil Code: <script type="text/javascript"> function count() { var firstclass = document.calc.firstclass.value; var postcard = document.calc.firstclass.value; var numpages = document.calc.numpages.value; var nms = document.calc.nms.value; var large = document.calc.large.value; var numpages = parseInt(document.calc.numpages.value); if (document.calc.grabber.checked) { var vweight = (numpages + 8) * 0.17636981; } else { var vweight = numpages * 0.17636981; } var postageprice = 0; switch(postageprice) { case document.calc.postcard.checked: var postageprice = 28; break; case document.calc.firstclass.checked && vweight <= 1: var postageprice = 44; break; case document.calc.firstclass.checked && vweight <= 2: var postageprice = 61; break; case document.calc.firstclass.checked && vweight <= 3: var postageprice = 78; break; case document.calc.firstclass.checked && vweight <=3.5: var postageprice = 95; break; case document.calc.firstclass.checked && document.calc.large.checked && vweight <= 1: var postageprice = 88; break; case document.calc.firstclass.checked && document.calc.large.checked && vweight <= 2: var postageprice = 105; break; case document.calc.firstclass.checked && document.calc.large.checked && vweight <= 3: var postageprice = 122; break; case document.calc.firstclass.checked && document.calc.large.checked && vweight <= 4: var postageprice = 139; break; case document.calc.firstclass.checked && document.calc.nms.checked && vweight <= 1: var postageprice = 64; break; case document.calc.firstclass.checked && document.calc.nms.checked && vweight <= 2: var postageprice = 81; break; case document.calc.firstclass.checked && document.calc.nms.checked && vweight <= 3: var postageprice = 98; break; case document.calc.firstclass.checked && document.calc.nms.checked && vweight <= 3.5: var postageprice = 105; break; case document.calc.firstclass.checked && document.calc.nms.checked && document.calc.large.checked && vweight <= 1: var postageprice = 122; break; case document.calc.firstclass.checked && document.calc.nms.checked && document.calc.large.checked && vweight <= 2: var postageprice = 139; break; case document.calc.firstclass.checked && document.calc.nms.checked && document.calc.large.checked && vweight <= 3: var postageprice = 156; break; case document.calc.firstclass.checked && document.calc.nms.checked && document.calc.large.checked && vweight <= 4: var postageprice = 173; break; default: var postageprice = 0 } document.calc.pay.value = postageprice } </script> <form name="calc" method="POST"> <input type="text" name="numpages" size="10" value=10 onpropertychange="count()" onkeypress="keypress(event)" onclick="SelectAll()"> <input type=button name=clearnumber value="Clear" onclick="document.calc.numpages.value=0"> <p></p> <input type="checkbox" name="firstclass" size="10" onclick="count()"><p> <input type="checkbox" name="large" size="10" onclick="count()"></p> <p> <input type="checkbox" name="nms" size="10" onclick="count()"></p> <p> <input type="checkbox" name="postcard" size="10" onclick="count()"></p> <p> <input type="checkbox" name="grabber" size="10" onclick="count()"></p> <p>$<input type="text" name="pay" size="10"> $<input type="text" name="perthousand" size="10"> </p> </form> Thanks again. Is it possible to scrape displayed text you can't find in html source code ? The text shows up only when you click a link, but is still not visible in source code. That link has got a userid and is used as a variable in function ShowUserPhone(userid). If someone knows how to solve this mystery, please help. I added http://www.mediafire.com/file/9eo72u...wUserPhone.txt file as available .js source linked to that smart page. I've also put some comments there about URL original location. Here is the main function where the process started I guess: Code: function ShowUserPhone(userid){ var UserPhoneLink=document.getElementById("UserPhoneLink"); var UserPhone = document.getElementById("UserPhone"); if(document.images){ (new Image()).src="/pp-owners-list-click-counter.asp?UserId="+escape(userid)+"&counterType=detailsphone"; } if (UserPhoneLink){ UserPhoneLink.style.display="none"; } if (UserPhone){ UserPhone.style.display="block"; } } Please help. |