JavaScript - Submit Question Scheme Information(first Year Student Project)
Similar TutorialsI'm doing a correspondence course on javascript, but the terminology is giving me up-hill and after hour of battling, my Javascript was just a mess. could someone help me with the javascript function. My instruction reads: "Create a web page with 5 text boxes. Assign to each text box's value attribute a value of zero. Add to each of the text boxes an onchange event handler that calls a function named calcAvg() and passes to the function the value of that text box by referencing it's document object, form name, and name and value attributes. Within the calcAvg() function, pass the five parameters to another function, named performCalc(), and assign the returned value to a variable named calcResult, then place the returned value in to another text box with a name averageResult. In the performCalc() function, calculate the average of the five numbers (by adding the five numbers and then dividing the total by 5), then return the result to the calcAvg() function. When you preform the calculation, use the parseInt() function to insure that the passes values are calculated as numbers." Please assist be as kind as to assist me with this project so I can use it as reference to the following projects that follow on the foundation of this one... My code so far; 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Calculate average</title> <script type="text/javascript"> /*<![CDATA[*/ /*]]<*/ </script> </head> <body> <h1>Calculating averages</h1> <table> <tr> <td> <tr> <td>Value 1<br/></td> <td> <input type="text" name="valueOne" size="6" value="0" onchange="calcAvg()" /></td> </tr> <tr> <td>Value 2<br/></td> <td> <input type="text" name="valueTwo" size="6" value="0" onchange="calcAvg()" /></td> </tr> <tr> <td>Value 3<br/></td> <td> <input type="text" name="valueThree" size="6" value="0" onchange="calcAvg()"/></td> </tr> <tr> <td>Value 4<br/></td> <td> <input type="text" name="valuefour" size="6" value="0" onchange="calcAvg()"/></td> </tr> <tr> <td>Value 5</td><br/> <td> <input type="text" name="valueFive" size="6" value="0" onchange="calcAvg()"/></td> </tr> </td> </tr> </table> <form action="" name="averageResult" > <p>The average of the 5 numbers: <input type="text" name="cost" size="5" value="0" style="border-style: none; border-color:inherit; border-width:medium; background-color: Transparent" text="0"/></p> </form> </body> </html> I have a javascript program I'm trying to write for an introductory javascript class. The book is absolutely terrible and I've found I have a very weak grasp of how javascript functions work but I have an exam coming up and I'm getting desperate for help so I'm posting here hoping someone can help me get my head wrapped around this thing. The code is a simplified game of 21. It should randomly generate two cards for the dealer and two for the player, then display the total to the player and allow them to choose whether or not to take another card. It then decides who won. I'm including the script below: Code: <script type="text/javascript"> /*Declare Variables*/ var dealer = 0; var player = 0; var dealerPoints = 0; var playerPoints = 0; var rNum = 0; var rPlayer1 = 0; var rPlayer2 = 0; var rDealer1 = 0; var rDealer2 = 0; var hitMe = " "; function playGame() { while((playerPoints < 200) && (dealerPoints < 200)) { /*Generate 2 random numbers between 2 and 11 for the player*/ rPlayer1 = Math.floor((Math.random() * 10 + 2)) rPlayer2 = Math.floor((Math.random() * 10 + 2)) rDealer1 = Math.floor((Math.random() * 10 + 2)) rDealer2 = Math.floor((Math.random() * 10 + 2)) /* Find Players Total*/ player = (rPlayer1 + rPlayer2); /* Find Dealers Total*/ dealer = (rDealer1 + rDealer2); /*Display player total*/ while ((player <= 21) && (dealer <= 21)) { hitme = prompt("You drew a " + rPlayer1 + " card and a " + rPlayer2 + " card for a total of " + player + ". Do you want another card?"); if (hitMe == "yes") { rPlayer1 = Math.floor((Math.random() * 10 + 2)); player = (player + rPlayer1); alert("You drew a " + rPlayer1 + " card for a total of " + player + "."); } if ((player <= 21) && (dealer > 21)) { playerPoints = (playerPoints + player); alert("Player Wins Hand"); } if ((dealer <= 21) && (player > 21)) { dealerPoints = (dealerPoints + dealer); alert("Dealer Wins Hand"); } if ((dealer > 21) && (player > 21)) alert("Tie, no points awarded"); } if ((dealer <= 21) && (player <= 21)) { if (dealer > player) { dealerPoints = (dealerPoints + dealer); alert("Player total: " + playerPoints + ". Dealer points: " + dealerPoints + ". Dealer wins this hand."); } else if (player > dealer) { playerPoints = (playerPoints + player); alert("Player total: " + playerPoints + ". Dealer points: " + dealerPoints + ". Player wins this hand!"); } else { alert("Player total: " + playerPoints + ". Dealer points: " + dealerPoints + ". No one wins this hand."); } if (playerPoints >= 200) { alert("Player wins game!"); } else if (dealerPoints >= 200) { alert("Dealer wins game!"); } } } } </script> My site will change color schemes when a user presses the button in the top left. I want to add a third theme though. I can't figure it out though. My html as relevent Code: <!--EXTERNAL FILES--> <link rel="stylesheet" type="text/css" href="main.css" /> <!--[if IE]><link rel="stylesheet" type="text/css" href="mainIE.css" /><![endif]--> <link id="altstyle" rel="stylesheet" type="text/css" href="main.css" /> <script type="text/javascript" src="main.js"></script> <!--STOP EXTERNAL FILES--> <title>Votillity.com</title> <!--CSS INTERNAL--> <!--CSS INTERNAL--> <!--JAVASCRIPT INTERNAL--> <!--JAVASCRIPT INTERNAL--> </head> <body onload="startTime()"> <img class="Zindexsty1" style="position: fixed; top: 0px; left: 0px;" src="http://votillity.com/VotillityLogo1.png" alt="VOTILLITY" /> <img class="Zindexsty2" style="position: fixed; top: 0px; left: 0px;" src="http://votillity.com/VotillityLogo2.png" alt="VOTILLITY" /> <button id="altstyact" class="button" style="position: fixed; top: 0px; left: 170px; width: 60px;">Theme</button> Javascript Code: //ALTERNATE STYLES function changeStyle() { var obj1=document.getElementById('altstyact'); var obj2=document.getElementById('altstyle') test=true; obj1.onclick=function() { test==true? (obj2.href='main2.css',obj1.firstChild.nodeValue='Classic',test=false): (obj2.href='main.css',obj1.firstChild.nodeValue='Ice',test=true) } } if(window.addEventListener) { window.addEventListener('load',changeStyle,false); } else { if(window.attachEvent) { window.attachEvent('onload',changeStyle); } } //STOP ALTERNATE STYLES I don't think you need the css's. If, however, I'm wrong just let me know. Keep in mind that the javascript is external. Here's my site if you need a better look Votillity Thank you Hi, I am not able to submit the page details in IE 6 since am getting Javascript error: "unknown name" while submitting the page. If i press submit button for second time getting javascript error "Permission Denied". I tried to submit the details in IE 7 aswell the same error occurs. But i tried to submit the page in FireFox, its worked great... submitted without any error and the details saved in the database. I dont understand why the details are not submitted through IE6. Please assist on this. rgds, Ganny. Hi.. I just want to know how can I display Weeks in a drop down list per year. Thank you I am trying to auto submit a login form remotely using .submit() . It's submitting, but for some reason if I use submit() the login isn't processing. However, if I turn off the auto submit and use an actual submit button it logs in just fine. Now, in the form tag there is a call onsubmit for some validation, does .submit() trigger that form onsubmit="" function? Is there something that happens differently when a user clicks a button verses the .submit(). Thanks! Paul What I am looking to do is have 4 different check boxes, one for each different site. For Example: checkbox1 (if checked would popup) www.site1.com checkbox2 (if checked would popup) www.site2.com ect. When the user clicks the submit button each site that is check marked would popup in a different window. Anyone have any ideas on how to do this? An example site I came across was tripmama.com Thank you in advance. i wold like to get this working. when a user enters 4 grades into the text boxes. it would give them the Avg Grade and also what Mark they got, and if they failed one out put the module they most Repeat and if they passed all out put a smiley face.. This is what i have so far.. Code: function compute() { var c = document.getElementById("c").value; var computer = document.getElementById("computer").value; var web = document.getElementById("web").value; var math = document.getElementById("math").value; document.getElementById("cost").value = totalCost = (c * 100 + computer * 100 + web * 100 + math * 100 ) /4; if(cost >=93) alert(" You got an A+") else if((cost >=85)&(grade <93)) alert(" You got an A") else if((cost >=78)&(grade <85)) alert(" You got an B") else if((cost >=60)&(grade <78)) alert(" You got an C") else if((cost >=40)&(grade <60)) alert(" You got an D") else if(cost <40) alert(" You Failed this Module") </script> </head> <body> <form method="get" action="" onsubmit='return formValidator()' > <fieldset id="personalInfo"> <h3> Student Results </h3> <!-- A bordered table for item orders --> <table border = "border"> <!-- First, the column headings --> <tr> <th> Module Name </th> <th> Pass Mark </th> <th> Final Mark </th> </tr> <!-- Now, the table data entries --> <tr> <th> C++ </th> <td> 40 % </td> <td> <input type = "text" id = "c" size ="10" /> </td> </tr> <tr> <th> Computer Systems </th> <td> 40 % </td> <td> <input type = "text" id = "computer" size = "10" /> </td> </tr> <tr> <th> Web Development </th> <td> 40 % </td> <td> <input type = "text" id = "web" size = "10" /></td> </tr> <tr> <th> Maths </th> <td> 40 % </td> <td> <input type = "text" id = "math" size ="10" /> </td> </tr> </table> <!-- Button for precomputation of the total cost --> <p> <input type = "button" value = "Total Grade" onclick = "compute();" /> <input type = "text" size = "5" id = "cost" onfocus = "this.blur();" /> </p> </fieldset> </p> <input type='submit' value='Check Form' /> </form> </body> </html> var suitArray = ["Hearts","Diamonds","Clubs","Spades"]; var faceArray = ["Ace", - Pastebin.com Doing a school assignment and Im totally stumped, google isnt any help nor is any of these textbooks. I need to tally up the playerhands and dealer hands and display the winner. I can get it to display the value of the current card. eg 7 of diamonds = 7 points but I cannot get it to tally up all the cards dealt. I am trying to get a Javascript "script" to do a function for me. I am trying to write a a script that will run while the webpage is open, that is selected a randomized 9 digit number Less than 350000000 that will be put into a textbox and submitted. I want a adjustable time when it submits. Could this be made into an <iframe>? Also, this has to do it to a different website, not the one locally being opened. Thank you for your help. HI there.. Can you please give me code in JavaScript to create a student request form for book request from issue section of college Library.. Please help with code... Thanx in advance... Regards, Hi, I have a body onload doing multiple things, changing a select option value, changing the form submit action and then auto submitting. Everything works fine until the auto submit part of it. Code: function run() { document.myform.myselect.selectedIndex = 1; document.myform.action = 'page.php?x=1&y=2'; document.myform.submit(); } <body onload="run()"> Thanks for any help with this Hey, I have a drop down box that selects a project name. This is then taken to a javascript function that is supposed to fill in a read-only box with that name, but instead of filling it in with the project name, it fills it in with the project ID, which is how the sql database is set up. Each project has an ID, a name, and other values. Is there a way I can get the project name given the project ID in the javascript function?
On my site I have a Javascript error in my FireBug console: Year is 'null' Code: document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i); here is my site: http://harveys.blueplanetdns.com/harveys-shop/ Hi guys , How it is possible to get current & next year months and put them into array ..i.e Jan-11 --- M1[0] . . . . Dec-11 M1[11] Jan-12 M2[0] . . . Dec-13 M2[11] thanks Hello guys, I really need some help with this. I am using the jQuery cookie file to set and retrieve my cookies, but I don't know how to modify it to set all cookies for more than one day. Here's my code: Code: /** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secu true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000 * 365)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; I was told to put this in the head section before my page, and it sets it for a year, but I want all the cookies set on the page to be set for a year. Code: $(function() { $.cookie('name', 'value', {expires: 365}); }); any ideas? Hi, I have a form that when you click submit gives a warning box asking if to continue code below Now when I type in the text field and press enter it doesn't submit nor does it pop up the warning box, how would I do this Code for submit button Code: <script LANGUAGE="JavaScript"> <!-- function submitMyForm() { var agree=confirm("ARE YOU SURE ?"); if (agree) return true ; else return false ; } // --> </script> Code: <form action="admin-delete.php" method="post" name="cp_delete" id="cp_delete"> <input type="text" name="cp_delete_bg" id="cp_delete_bg"> <input type="submit" name="submit" value="submit" onclick="return submitMyForm()"/> </form> Hello all I have this code to write the year which works fine in ie ff but apparantly is not working in google chrome. I don't have chrome and so can't check can anybody tell me why chrome has an issue with it? What should I change to make it chrome compliant:-) In ie ff it displays 2012 correctly but in chrome i'm told it is showing 112 ro something like that. Code: Code: any help very much appreciated LT I want to create an array for a religious website that will display a different Bible verse for each day of the year. This is how I incremented each day of the year. Code: var myDate=new Date(); myDate.setFullYear(2011,2,4); myDate.setDate(myDate.getDate()+1); How do I make the connection between the array and the new date as it changes? This is a snippet from the array. Code: var dailyVerseRef=new Array(); dailyVerseRef[0]="Genesis 1:1"; dailyVerseRef[2]="Genesis 1:2"; dailyVerseRef[3]="Genesis 1:3"; dailyVerseRef[4]="Genesis 1:4"; dailyVerseRef[5]="Genesis 1:5"; dailyVerseRef[6]="Genesis 1:6"; dailyVerseRef[7]="Genesis 1:7"; dailyVerseRef[8]="Genesis 1:8"; I used a switch to go through the days of the week, but to go through the days of the year seems more difficult. |