JavaScript - Needing Help With A Form. Writing A Function?
Okay so this is a homework assignment. I have completed MOST of it. What I am completely lost on is how make the totals show up in the shipping fee section based on what products the user selects.
"When the user selects an option from the Hand Tool selection list (and only the Hand Tool selection list) Display $20.00 in the Item 1 text box. Display $0 in the Item 2 text box. Display $5.00 in the Shipping text box. Display $25.00 in the Total text box. When the user selects an option from the Power Tool selection list (and only the Power Tool selection list) Display $0 in the Item 1 text box. Display $30.00 in the Item 2 text box. Display $10.00 in the Shipping text box. Display $40.00 in the Total text box. When the user selects both an option from the Hand Tool selection list and an option from the Power Tool selection list Display $20.00 in the Item 1 text box. Display $30.00 in the Item 2 text box. Display $15.00 in the Shipping text box. Display $65.00 in the Total text box. If the user returns back to the default (the words Hand Tool and Power Tool in the selection list) you must treat that as de-selecting the tool and change the text boxes accordingly." 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" xml:lang="en" lang="en"> <head> <title> Project 2 </title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="js_styles.css" type="text/css" /> <script type="text/javascript"> /* <![CDATA[ */ function jumpto(x){ if (document.form1.jumpmenu.value != "null") { document.location.href = x } } function checkForNumber(fieldValue) { var numberCheck = isNaN(fieldValue); if (numberCheck == true) { window.alert("You must enter a numeric value!"); return false; } } function confirmSubmit() { if (document.forms[0].first_name.value == "" || document.forms[0].last_name.value =="" || document.forms[0].address_1.value =="" || document.forms[0].city.value =="" || document.forms[0].state.value == "") { window.alert("You have not entered the requested personal information."); return false; } } function confirmReset() { var resetForm = window.confirm("Are you sure you want to reset the form?"); if (resetForm == true) return true; return false; } /* ]]> */ </script> </head> <body> <h2>Purchase Order</h2> <form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded" onsubmit="return confirmSubmit();" onreset="return confirmReset();"> <h3>Products</h3> Hand Tools $20.00 <select name="jumpmenu" onChange="jumpto(document.form1.jumpmenu.options[document.form1.jumpmenu.options.selectedIndex].value)"> <option value="$0.00">Hand Tool</option> <option value="$20.00">Saw</option> <option value="$20.00">Hammer</option> <option value="$20.00">Screwdriver</option> <option value="$20.00">Wrench</option> <option value="$20.00">Pliers</option> </select> Power Tool $30.00 <select name="jumpmenu" onChange="jumpto(document.form1.jumpmenu.options[document.form1.jumpmenu.options.selectedIndex].value)"> <option value="$0.00">Power Tool</option> <option value="$30.00">Circular Saw</option> <option value="$30.00">Sabre Saw</option> <option value="$30.00">Drill</option> <option value="$30.00">Belt Sander</option> <option value="$30.00">Table Saw</option> </select> <h3>Shipping Fees</h3> <p>Item 1: <input type="text" name="city" size="15" /> Item 2: <input type="text" name="city" size="15" /> Shipping: <input type="text" name="city" size="15" /> Total: <input type="text" name="city" size="15" /> <h3>Customer Information</h3> <p>First Name <input type="text" name="first_name" size="25" value="First Name" onclick="document.forms[0].first_name.value = '';" /> Last Name <input type="text" name="last_name" size="25" value="Last Name" onclick="document.forms[0].last_name.value = '';" /> <p>Street Address 1 <input type="text" name="address_1" size="50" value="Address 1" onclick="document.forms[0].address_1.value = '';" /> <p>City <input type="text" name="city" size="20" value="City" onclick="document.forms[0].city.value = '';" /> State <input type="text" name="state" size="15" value="State" onclick="document.forms[0].state.value = '';" /> Zip <input type="text" name="zip" size="10" value="Zip" onclick="document.forms[0].zip.value = '';" /> <p>Phone <input type="text" name="phone" size="20" value="Phone" onchange="return checkForNumber(this.value)" onclick="document.forms[0].phone.value = '';" /> Fax <input type="text" name="fax" size="20" value="Fax" onchange="return checkForNumber(this.value)" onclick="document.forms[0].fax.value = '';" /> <p>Payment Method? <input type="radio" name="visa" />Visa<input type="radio" name="master_card" />Master Card <input type="radio" name="american_express" />American Express</p> <p>Credit Card Number <input types="text" name="cc_number" size="50" /> <p> Expiration Month: <select name="jumpmenu" onChange="jumpto(document.form1.jumpmenu.options[document.form1.jumpmenu.options.selectedIndex].value)"> <option>Month</option> <option value="january">January</option> <option value="february">February</option> <option value="march">March</option> <option value="april">April</option> <option value="may">May</option> <option value="june">June</option> <option value="july">July</option> <option value="august">August</option> <option value="september">September</option> <option value="october">October</option> <option value="november">November</option> <option value="december">December</option> </select> Expiration Year <select name="jumpmenu" onChange="jumpto(document.form1.jumpmenu.options[document.form1.jumpmenu.options.selectedIndex].value)"> <option>Year</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> </select> </p> <p><input type="image" alt="Graphical image of a subscribe button" src="subscribe.png" /></p> <p><input type="reset" value="Reset Registration Form" onchange="confirmReset" /></p> </form> <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" style="border: 0px;" /></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"> <img src="http://www.austincc.edu/jscholl/images/vcss.png" alt="Valid CSS!" height="31" width="88" style="border: 0px;" /></a> </p> </body> </html> I'm not looking for someone to complete this for me. I just need some help with how I would write a function for this. Similar TutorialsHello all, I've been working on a webcode for a basic form and check page. The forms work, just I'm having an issue with when I submit the form, even with incomplete data (AKA the email verification) it submits anyway instead of halting the page. 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" xml:lang="en" lang="en"> <head> <title>About</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link type="image/x-icon" rel="SHORTCUT ICON" href="EpicIcon.ico" /> <script type="text/javascript"> /* <![CDATA[ */ function firstNameFunc(){ if(document.forms[0].myName.value == 'Enter your first name here.'){ document.forms[0].myName.value = ''; } } function firstNameBlur(){ if(document.forms[0].myName.value == ''){ document.forms[0].myName.value = 'Enter your first name here.'; } } function lastNameFunc(){ if(document.forms[0].myName2.value == 'Enter your last name here.'){ document.forms[0].myName2.value = ''; } } function lastNameBlur(){ if(document.forms[0].myName2.value == ''){ document.forms[0].myName2.value = 'Enter your last name here.'; } } /**E-Mail verification and codes**/ <!--Beginning regular expression function for e-mail check--> <!--End test for Regular Expression--> function emailFocus(){ if(document.forms[0].myEMail.value == 'Enter your email here.'){ document.forms[0].myEMail.value = ''; } } function emailBlur(){ if(document.forms[0].myEMail.value == ''){ document.forms[0].myEMail.value = 'Enter your email here.'; } } <!--Verifying to submitting/resetting the form--> function confirmSubmit(){ var formSubmit = window.confirm("Are you sure you wish to submit the form?"); var emailReg = new RegExp(/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\.-]+\.(com|org|net|edu|gov)$/); /** -- ^[a-zA-Z0-9._-] will check for alpha-numeric characters (upper/lower) as well as allow periods, hyphens, and underscores. -- @ is the combining symbol for email adresses. -- [a-zA-Z0-9.-]+ will allow another set of alpha-numeric numbers that can also contain periods and hyphens. -- \. will seperate the characters from the domain and subdomains. -- (com|org|net|edu|gov)$/ will limit which domains those are. **/ if(document.forms[0].myName.value =='' ||document.forms[0].myName2.value =='' ||document.forms[0].myEMail.value ==''){ alert("You must enter data in the 'First Name,' 'Last Name,' and 'E-Mail' fields."); return false; } else if(document.forms[0].myEMail.value == 'Enter your email here.'){ document.forms[0].myEMail.value = ''; }if(document.forms[0].myEMail.value != ''){ if(emailReg.test(document.forms[0].myEMail.value) == false){ window.alert("Non-certified email used!"); document.forms[0].myEMail.focus(); document.forms[0].myEMail.select(); return true; } return false;} return true; } function confirmReset(){ var formReset = window.confirm("Are you sure you wish to reset the form?"); if(formReset == true) return true; return false; } <!--End of verification--> /* ]]> */ </script> </head> <body> <p align="center"> <form id="userInfo" method="post" onsubmit="confirmSubmit()" onreset="confirmReset()"> <table border="0"> <tr><td> First Name: </td><td align="center"><input type="text" id="myName" value="Enter your first name here." onFocus = "firstNameFunc()" onBlur="firstNameBlur()"/></td></tr> <tr><td>Last Name: </td><td align="center"><input type="text" id="myName2" value="Enter your last name here." onFocus = "lastNameFunc()" onBlur="lastNameBlur()"/></td></tr> <tr><td>E-Mail: </td><td align="center"><input type="text" id="myEMail" value="Enter your email here." onFocus = "emailFocus()" onBlur="emailBlur()"/></td></tr> <tr><td>Message: </td><td align="center"> <textarea id="message" cols="40" rows="5" onFocus="document.forms[0].message.value='';">Enter a message here...</textarea> </td></tr> <tr><td><td align="center"> <input type="Submit" value="Submit"/> <input type="Reset" value="Reset"/> </td></td></tr> </table> </form> </p> <a href="about.html">Click to return</a> </body> </html> Now I've tried making a seperate function for the regular expression and e-mail verification and got no where with it (though I'm sure it can be done easily). My question (though it is bolded): How do I prevent the page from continuing the submit function if data is incomplete? EDIT Code: function confirmSubmit(){ var formSubmit = window.confirm("Are you sure you wish to submit the form?"); var emailReg = new RegExp(/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\.-]+\.(com|org|net|edu|gov)$/); /** -- ^[a-zA-Z0-9._-] will check for alpha-numeric characters (upper/lower) as well as allow periods, hyphens, and underscores. -- @ is the combining symbol for email adresses. -- [a-zA-Z0-9.-]+ will allow another set of alpha-numeric numbers that can also contain periods and hyphens. -- \. will seperate the characters from the domain and subdomains. -- (com|org|net|edu|gov)$/ will limit which domains those are. **/ if(document.forms[0].myName.value =='' ||document.forms[0].myName2.value =='' ||document.forms[0].myEMail.value ==''){ alert("You must enter data in the 'First Name,' 'Last Name,' and 'E-Mail' fields."); return false; } else if(document.forms[0].myEMail.value == 'Enter your email here.'){ document.forms[0].myEMail.value = ''; }if(document.forms[0].myEMail.value != ''){ if(emailReg.test(document.forms[0].myEMail.value) == false){ window.alert("Non-certified email used!"); document.forms[0].myEMail.focus(); document.forms[0].myEMail.select(); return true; } return false;} return true; } I have the following form working with on onsumbit function, but I would like to change it so that instead of having to click the purchase button to see total price, you only have to change the quanity text box input. I would welcome any help. I just can not seem to get it to work. Code: <script language="javascript" type="text/javascript"> function checkQuantity(frm) { var succesful = false; var numQuantity; numQuantity = parseInt(frm.Quantity.value); var numTotalPrice; if (numQuantity != 0) { numTotalPrice = numQuantity * 4; frm.TotalPrice.value = numTotalPrice; //new String(numTotalPrice); successful = true; } else { alert("Sorry must order more than 0"); successful = false; } return succesful; } </script> Code: <form action="" onsubmit="return checkQuantity(this)" style="width: 193px"> <table cellpadding="4" style="width:111%"> <tr> <td class="style1"> Quanity:</td> <td class="formInputCell"> <input name="Quantity" type="text" style="width: 55px" /></td> </tr> <tr> <td class="style1"> Total Price $ </td> <td class="formInputCell"> <input name="TotalPrice" type="text" style="width: 55px" /></td> </tr> <tr> <td class="style2"></td> <td><input id="Submit1" type="submit" value="Buy Now" class="buttonstyle" /></td> </tr> </table> </form> Hi everyone In the below code i tried to write java scirpt in action attribute of form tag in html . Why i wrote that was i want to get the scirpt variable as a part of the url of the target page . I also tried using the location.href="targetpage?value="+value . But It is not redirecting to targetpage because of the action attribute in the form tag. And if we use location.href without action attribute only that script variable was posted and all other remaining textboxes and other form items are being not posted .. Thats why I wrote the scirpt in action attribute. I want the action attribute to work and also the java script variable to be posted .so i wrote the script tag in action attribute of form tag . I hope u got the Scenario . Please help me to resolve the issue.. Thank in advance .. <!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <? if($_POST['submit'] ) { $var = $_GET['width'] ; } ?> <form name="form_submit" method="post" action="test2.php?width= '<script type= text/javascript> document.write(num)</script>' " onsubmit="return fun(); "> <script type="text/javascript"> function fun() { width = screen.width; height = screen.height; if (width > 0 && height >0) { window.location.href = "http://localhost/test2.php?width=" + width + "&height=" + height; } else exit(); } </script> <input type="text" name="txt" value="sample text" /> <input type="submit" name="submit" value="submit" /> </form> </body> </html> I'm completely new to Java Script, but about a year ago I decided to learn how to build a website from scratch. I am confident with HTML and CSS, but Java seems to be flying over my head. Could anybody possibly help me with my coding? I'm sure the problem is obvious, but I don't know if this is the right place to post this sort of beginnier question. So if it is not, please redirect me to where I can. Thanks a lot! Quote: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title></title> </head> <body> <script type="text/javascript"> function addzero(zero) { return zero; } var d = new Date(); var time=d.getHours function tod1 () { document.write("The time is "); document.write(addzero(d.getHours())); document.write(":"); document.write(addzero(d.getMinutes())); } function tod2 () { document.write("The time is "); document.write(addzero(d.getHours()+1)); document.write(":"); document.write(addzero(d.getMinutes())); } function tod3 () { document.write("The time is "); document.write(addzero(d.getHours()+2)); document.write(":"); document.write(addzero(d.getMinutes())); } function tod4 () { document.write("The time is "); document.write(addzero(d.getHours()+3)); document.write(":"); document.write(addzero(d.getMinutes())); } if (time>10) { alert("Good morning"); } </script> <p id="city"></p> <form name="form" action="wtf.php" method="post"> Vancouver: <input type="radio" name="city" id="Vancouver" onchange="tod1()"> Calgary: <input type="radio" name="city" id="Calgary" onchange="tod2()"> Winnipeg: <input type="radio" name="city" id="Winnipeg" onchange="tod3()"> Toronto: <input type="radio" name="city" id="Toronto" onchange="tod4()"> </form> </body> </html> Hi, I'm currently building a website at the moment & I have a feature on the page that I would like to perform a nice slideshow. However, its not just in a single square frame, i've made it nice and complicated for myself that i've kind of got myself in a muddle trying to work out the best way of going about this feature. Below is an image that'll hopefully save me from babbling too much. So as you can see, in photoshop i've used masking on the images to produce the effect. So at the moment, two images are showing...each taking up four of these rectangles. I'd like every 7 seconds lets say, for both images to slide off and two more to replace them. Whats the best way to do this? As i'm wanting to use jquery/javascript for this feature. thanks for any advice. This is my first time in this forum. I've been searching all day for a solution to the js problem I have. I think I've worked outa what I need to do with the code I have to get my page working but I don't know how to amend the code to what I need. I have a form which I'm using to return a number count of records in my db. Each time a select is changed in the form it calls a function which generates a url based on the selections and then returns this to the page. There are 2 parts of this I'm struggling with. 1. First is a checkbox which allows a user to return all results or only results with an image. The problem I have is that the code below will always show the checkbox with a value. 2. There will be occasions where the model field is not present in the form, how can I change the code below so that it checks to see if there is a model value and if there is none it just doesn't put the model var in the url string that it generates. Please can someone help me. I've posted threads on other forums and no-one will reply. Any help would be greatly appreciated with this, the code I'm trying to change is below. Code: function showTotalUsedBikes(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ticker'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var drop_1 = document.getElementById('drop_1').value; var model = document.getElementById('model').value; var mileage = document.getElementById('mileage').value; var colour = document.getElementById('colour').value; var age = document.getElementById('age').value; var min_price = document.getElementById('min_price').value; var max_price = document.getElementById('max_price').value; var min_engine_size = document.getElementById('min_engine_size').value; var max_engine_size = document.getElementById('max_engine_size').value; //var pics = document.getElementById('pics').value; var pics = $('input:checkbox:checked').val(); // get the value from a checked checkbox var keywords = document.getElementById('keywords').value; var queryString = "?drop_1=" + drop_1 + "&model=" + model + "&mileage=" + mileage + "&colour=" + colour + "&age=" + age + "&min_price=" + min_price + "&max_price=" + max_price + "&min_engine_size=" + min_engine_size + "&max_engine_size=" + max_engine_size + "&pics=" + pics + "&keywords=" + keywords; ajaxRequest.open("GET", "numberOfBikes.php" + queryString, true); ajaxRequest.send(null); } heelo people im hoping someone can help me with this for some reason my code isnt working can anyone help me fiind a solution thanks Code: <?xml version="1.0"?> <!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> <title> Activity 14 question 1 </title> </head> <body> <h1>Comparing Height</h1> <p>Click on the button to compare heights</p> <script type="text/javascript"> <!-- function height() { var height; var DispWin; DispWin = window.open("","NewWin", " width=400,height=200"); if(height <178); { DispWin.document.write("Your height is less than or equal to the average"); } else { DispWin.document.write("Your height is more than or equal to the average"); } } --> </script> <form name="calch"> <p>height: <input type="text" size="10" name="compare height" /></p> <p><input type="button" value="Compare Height" onClick="height(document.calch.height.value;" /> </p> </form> </body> </html> thanks This javascript code is supposedly to show the current date, and show a famous person's birthday on each day. Not sure if I am suppose to have birthdates in js files, or in first files. [CODE]Filename: births.htm Supporting files: functions.js, logo.jpg --> <title>Welcome to Happy Birthday.com</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" type="text/javascript"> var births = new Array(); births[1] = "J.D. Salinger (1919) - Author"; births[2] = "Isaac Asimov (1920) - Author"; births[3] = "Clement Attlee (1883) - 42 Prime Minister"; births[4] = "Floyd Patterson (1935) - Heavyweight boxer"; births[5] = "King Camp Gillette (1855) - Invented safety razor"; births[6] = "Mel Gibson (1956) - Actor"; births[7] = "Millard Fillmore (1800) - 13th US President"; births[8] = "Elvis Aaron Presley (1935) - King of rock 'n' roll"; births[9] = "Richard Nixon (1913) - 37th US President"; births[10] = "George Foreman (1949) - Heavyweight boxing champ"; births[11] = "Alexander Hamilton (1755) - American Founding Father"; births[12] = "Joe Frazier (1947) - Heavyweight boxing champ"; births[13] = "Orlando Bloom (1977) - Actor"; births[14] = "Benedict Arnold (1741) - American"; births[15] = "Martin Luther King (1929) - Civil-rights "; births[16] = "Andre Michelin (1853) - Inventor of rubber tires"; births[17] = "Muhammad Ali (1942) - Boxer Cassius Clay"; births[18] = "David D Kaminsky (1913) - Danny Kaye"; births[19] = "James Watt (1736) - Inventor of the steam engine"; births[20] = "Edwin 'Buzz' Aldrin (1930) - Second man on Moon"; births[21] = "Telly Savalas (1924) - Actor"; births[22] = "Sam Cooke (1935) - Singer"; births[23] = "Princes Caroline (1957) - Royal of Monaco"; births[24] = "John Belushi (1949) - Actor"; births[25] = "Robert Burns (1759) - Scottish poet"; births[26] = "Paul Newman (1925) - Actor"; births[27] = "Amadeus Mozart (1756) - Composer"; births[28] = "Elijah Wood (1981) - Actor"; births[29] = "William McKinley (1843) - American President"; births[30] = "Franklin D. Roosevelt (1882) - American President"; births[31] = "Mario Lanza (1921) - Tenor singer"; births[32] = "Clark William Gable (1901) - Actor"; births[33] = "James Joyce (1882) - Author"; births[34] = "Gertrude Stein (1874) - Author"; births[35] = "Charles Lindbergh (1902) - Aviator"; births[36] = "John Boyd Dunlop (1840) - Inventor of the pneumatic tire"; births[37] = "Ronald Reagan (1911) - 40th US President"; births[38] = "Charles Dickens (1812) - Author"; births[39] = "James Dean (1931) - Actor"; births[40] = "Sandy Lyle (1958) - British golfer"; births[41] = "Harold Macmillan (1894) - 44th UK Prime Min"; births[42] = "Thomas Alva Edison (1847) - Inventor of the electric light bulb"; births[43] = "Abraham Lincoln (1809) - 16th US President"; births[44] = "George Segal (1934) - Actor"; births[45] = "Jimmy Hoffa (1913) - Union Leader"; births[46] = "Galileo Galilei (1564) - Italian astronomer"; births[47] = "John McEnroe (1959) - Tennis player"; births[48] = "Michael Jordan (1963) - Basketball player"; births[49] = "Enzo Ferrari (1898) - Sports car builder"; births[50] = "Prince Andrew (1960) - Queens 3rd child"; births[51] = "Sidney Poitier (1927) - First black Oscar win"; births[52] = "Jilly Cooper (1937) - Author"; births[53] = "George Washington (1732) - 1st US President"; births[54] = "Linda Nolan (1959) - Singer" births[55] = "Steven Jobs (1955) - Software pioneer"; births[56] = "George Harrison (1943) - Ex-Beatle guitarist"; births[57] = "William F Cody (1846) - Buffalo Bill"; births[58] = "Elizabeth Taylor (1932) - Actress Oscar winner"; births[59] = "Barry McGuigan (1961) - Featherweight boxer"; births[60] = "Gioacchino Rossini (1792) - William Tell Overture"; births[61] = "Glen Miller (1904) - Bandleader"; births[62] = "Mikhail Gorbachev (1931) - Soviet President"; births[63] = "Alexander G Bell (1847) - Inventor of telephone"; births[64] = "Patrick Moore (1923) - Astronomer"; births[65] = "William Oughtred (1574) - Inventor of the slide rule"; births[66] = "Valentine Tereshkova (1937) - First woman in space"; births[67] = "Armstrong Jones (1930) - Lord Snowdon (photographer)"; births[68] = "Karl Von Grafe (1787) - Plastic surgery pioneer"; births[69] = "Yuri Gagarin (1934) - First man in space"; births[70] = "Chuck Norris (1942) - Karate film actor"; births[71] = "Sir Harold Wilson (1916) - 46th UK Prime Min"; births[72] = "Liza Minnelli (1946) - Actress"; births[73] = "Joseph Priestley (1733) - Discoverer of oxygen gas"; births[74] = "Albert Einstein (1879) - Theory of relativity"; births[75] = "Andrew Jackson (1767) - 7th US President"; births[76] = "George Ohm (1787) - Measure of electricity"; births[77] = "Gottlieb Daimler (1834) - Inventor of the combustion engine"; births[78] = "Neville Chamberlain (1869) - 40th UK Prime Min"; births[79] = "David Livingstone (1813) - Explorer"; births[80] = "Mr. Rodgers (1928) - Children's entertainer"; births[81] = "Johann Sebastian Bach (1685) - Composer"; births[82] = "Andrew Lloyd Webber (1948) - British songwriter"; births[83] = "Sir Roger Bannister (1948) - First runner to break the four-minute mile"; births[84] = "Steve McQueen (1930) - Actor"; births[85] = "Reginald K Dwight (1947) - Singer Elton John"; births[86] = "Diana Ross (1944) - Singer"; births[87] = "Henry Royce (1863) - Co founder of Rolls-Royce"; births[88] = "Neil Kinnock (1942) - Former Labour leader"; births[89] = "John Major (1947) - 50th UK Prime Min"; births[90] = "Vincent Van Gogh (1854) - Dutch painter"; births[91] = "Gordie Howe (1928) - Hockey player"; births[92] = "William Harvey (1578) - Discoverer of blood circulation"; births[93] = "Hans Chris Andersen (1805) - The Ugly Duckling"; births[94] = "Doris Kappelhoff (1924) - Doris Day (actress)"; births[95] = "Maya Angelou (1928) - Poet"; births[96] = "Lord Joseph Lister (1827) - Introduced antiseptic"; births[97] = "Harry Houdini (1874) - Escape artist"; births[98] = "William Wordsworth (1843) - Poet"; births[99] = "Julian Lennon (1963) - Singer"; births[100] = "Isambard Brunel (1806) - Engineer of the Thames tunnel"; births[101] = "Michel Shalhouz (1932) - Actor Omar Sharif "; births[102] = "Joel Grey (1932) - Actor"; births[103] = "Tom Clancy (1947) - Author"; births[104] = "Garry Kasparov (1963) - British chess champ"; births[105] = "Rod Steiger (1925) - Acotr"; births[106] = "Leonardo da Vinci (1452) - Genius"; births[107] = "Charlie S Chaplin (1889) - Silent comedy actor"; births[108] = "Nikita Krushchev (1894) - Soviet leader"; births[109] = "Hayley Mills (1946) - Child star actress"; births[110] = "Dudley Moore (1935) - Actor 'Arthur' and '10'"; births[111] = "Adolf Hitler (1889) - German leader"; births[112] = "Queen Elizabeth II (1926) - Head of British Commonwealth"; births[113] = "Jack Nicholson (1938) - Actor"; births[114] = "William Shakespeare (1564) - Playwright and Poet"; births[115] = "Barbra Streisand (1942) - Singer"; births[116] = "Ella Fitzgerald (1918) - Singer"; births[117] = "Jet Li (1963) - Actor"; births[118] = "Samuel Morse (1791) - Inventor of Morse Code"; births[119] = "Saddam Hussein (1937) - Deposed Iraq President"; births[120] = "Hirohito (1901) - Emperor of Japan"; births[121] = "Kath Smith (1909) - Singer"; births[122] = "Duke of Wellington (1769) - 23rd UK Prime Min"; births[123] = "Harry (Bing) Crosby (1904) - Singer/Actor"; births[124] = "Arnold G Dorsey (1936) - Engelbert Humperdink"; births[125] = "Michael Barrymore (1952) - Entertainer"; births[126] = "Tammy Wynette (1942) - Singer"; births[127] = "Sigmund Freud (1856) - Psychoanalysis"; births[128] = "Johannes Brahms (1833) - German composer"; births[129] = "Harry S Truman (1884) - 33rd US President"; births[130] = "Glenda Jackson (1936) - Actress"; births[131] = "Fred Astaire (1899) - Actor and tap-dancer"; births[132] = "Phil Silvers (1912) - Actor"; births[133] = "Florence Nightingale (1820) - Crimean war nurse"; births[134] = "Stevie Wonder (1950) - Singer"; births[135] = "Thomas Gainborough (1727) - Landscape painter"; births[136] = "James Mason (1909) - Actor"; births[137] = "Henry Fonda (1905) - Actor"; births[138] = "Grace Jones (1955) - Singer"; births[139] = "Karol Wojtyla (1920) - Pope John Paul II"; births[140] = "Pete Townshend (1945) - Singer"; births[141] = "James M Stewart (1908) - Comedy actor"; births[142] = "Leo Sayer (1948) - Singer"; births[143] = "Laurence Olivier (1907) - Actor"; births[144] = "Joan Collins (1933) - Film & TV actress"; births[145] = "Queen Victoria (1819) - Longest reigning Queen"; births[146] = "Miles Davis (1926) - Musician"; births[147] = "Marion Morrison (1907) - Actor John Wayne"; births[148] = "Vincent Price (1911) - Horror movie actor"; births[149] = "Ian Fleming (1908) - Author"; births[150] = "John F Kennedy (1917) - 35th US President"; births[151] = "Peter the Great (1672) - Emperor of Russia"; births[152] = "Clint Eastwood (1930) - Actor"; births[153] = "Norma Jean Baker (1926) - Marilyn Monroe"; births[154] = "Johnny Weissmuller (1903) - Actor"; births[155] = "King George V (1865) - 2nd son of Edward VII"; births[156] = "Christopher Cockerel (1910) - Inventor of the hovercraft"; births[157] = "John Couch Adams (1819) - British Astronomer"; births[158] = "Robert Falcon Scott (1868) - 1st Brit to South Pole"; births[159] = "Tom Jones (1940) - Singer"; births[160] = "Nancy Sinatra (1940) - Singer"; births[161] = "George Stephenson (1781) - Inventor of the first steam locomotive"; births[162] = "Judy Garland (1922) - Singer"; births[163] = "Vince Lombardi (1913) - Coach of the Green Bay Packers"; births[164] = "George Herbert Bush (1924) - 41st US President"; births[165] = "Tim Allen (1953) - Actor"; births[166] = "Boy George (1961) - Singer "; births[167] = "Mario Cuomo (1932) - Former governor of New York"; births[168] = "Stan Laurel (1890) - Laurel & Hardy duo"; births[169] = "Barry Manilow (1946) - Singer"; births[170] = "Paul McCartney (1942) - Singer"; births[171] = "Blaise Pascal (1623) - French mathematician"; births[172] = "Errol Flynn (1909) - Action-adventure film"; births[173] = "Prince William (1982) - Prince & Princess Wales son"; births[174] = "Meryl Streep (1949) - Actress"; births[175] = "Charles R Darwin (1809) - Theory of evolution"; births[176] = "Jack Dempsey (1895) - Heavyweight boxing"; births[177] = "Eric Arthur Blair (1903) - George Orwell"; births[178] = "William T Kelvin (1827) - Inventor of the absolute temperature scale"; births[179] = "Helen Keller (1880) - Author"; births[180] = "Mel Brooks (1926) - Writer/Actor"; births[181] = "Nelson Eddy (1901) - Singer"; births[182] = "Mike Tyson (1966) - Boxer"; births[183] = "Dianna Spencer (1961) - Princess Diane"; births[184] = "Richard Petty (1937) - Racecar driver"; births[185] = "Tom Cruise (1962) - Actor"; births[186] = "Calvin Coolidge (1872) - American president"; births[187] = "Bjorn Borg (1980) - Wimbledon tennis champion"; births[188] = "Bill Haley (1925) - Singer"; births[189] = "Richard Starkey (1940) - Ringo Starr"; births[190] = "Ringo Starr (1940) - Ex-Beatle drummer"; births[191] = "Sir Edward Heath (1916) - 47th UK Prime Min"; births[192] = "Virginia Wade (1945) - Tennis champion"; births[193] = "Yul Brynner (1917) - Actor"; births[194] = "Josiah Wedgwood (1730) - Blue & white pottery"; births[195] = "Harrison Ford (1942) - Actor"; births[196] = "Gerald Rudolph Ford (1913) - 38th US President"; births[197] = "Rembrandt (1606) - Dutch artist & painter"; births[198] = "Roald Amundsen (1872) - First man to reach the South Pole"; births[199] = "James Cagney (1899) - Actor"; births[200] = "John Glenn (1921) - First man to orbit Earth"; births[201] = "Samuel Colt (1814) - Inventor of the colt revolver"; births[202] = "Sir Edmund Hillary (1919) - First to climb Mt. Everest"; births[203] = "Ernest Hemingway (1899) - Author"; births[204] = "Bob Dole (1923) - Former U.S. Senator"; births[205] = "Monica Lewinsky (1973)"; births[206] = "Amelia Earhart (1898) - 1st woman to fly Atlantic"; births[207] = "Arthur James Balfour (1848) - 33rd UK Prime Min"; births[208] = "Mick Jagger (1944) - Singer"; births[209] = "Joseph Hilary Belloc (1870) - Author"; births[210] = "Beatrix Potter (1866) - Author"; births[211] = "Peter Jennings (1938) - Journalist"; births[212] = "Emily Bronte (1818) - Wuthering Heights"; births[213] = "J. K. Rowling (1965) - Author"; births[214] = "Herman Melville (1819) - Author"; births[215] = "Peter O'Toole (1932) - Lawrence of Arabia"; births[216] = "Stanly Baldwin (1868) - 38th UK Prime Min"; births[217] = "Queen Elizabeth (1900) - King George 6th wife"; births[218] = "Neil Armstrong (1930) - First man on the Moon"; births[219] = "Andy Warhol (1928) - Artist"; births[220] = "Mata Hari (1876) - Spy for the Germans"; births[221] = "Dustin Hoffman (1937) - Actor"; births[222] = "Thomas Telford (1757) - Road & bridge Engineer"; births[223] = "Herbert Clark Hoover (1874) - 31st US President"; births[224] = "Enid Blyton (1897) - Author"; births[225] = "King George 4th (1762) - King of England"; births[226] = "John Logie Baird (1888) - Inventor of television"; births[227] = "John Galsworthy (1867) - Author"; births[228] = "Napoleon Bonaparte (1769) - French leader"; births[229] = "Madonna (1959) - Singer"; births[230] = "May West (1892) - Actress"; births[231] = "Robert Redford (1937) - Actor"; births[232] = "Orville Wright (1871) - Inventor of the first airplane"; births[233] = "Jim Reeves (1924) - Singer"; births[234] = "William Murdock (1754) - Inventor of coal-gas lighting in 1792"; births[235] = "Ray Bradbury (1920) - Author"; births[236] = "Gene Kelly (1912) - Actor/Dancer"; births[237] = "Craig Kilborn (1962) - Actor"; births[238] = "Sean Connery (1930) - Actor"; births[239] = "Robert Walpole (1676) - 1st UK Prime Minister"; births[240] = "Sam Goldwyn (1910) - Film producer"; births[241] = "David Soul (1828) - Actor"; births[242] = "Michael Jackson (1958) - Singer"; births[243] = "Denis Healey (1917) - Politician"; births[244] = "Sir Bernard Lovell (1928) - Inventor of the radio telescope"; births[245] = "Rocky Marciano (1923) - Heavyweight boxer"; births[246] = "Salma Hayek (1968) - Actress"; births[247] = "Alan Ladd (1913) - Actor"; births[248] = "Tom Watson (1949) - Golfer"; births[249] = "Raquel Welch (1940) - Actress"; births[250] = "Britt Ekland (1942) - Actress"; births[251] = "Queen Elizabeth I (1533) - Queen of England"; births[252] = "King Richard I (1157) - Richard the Lion Heart"; births[253] = "William Bligh (1754) - Mutiny on the Bounty"; births[254] = "Arnold Palmer (1929) - US golfing champion"; births[255] = "O. Henry (1862) - Author"; births[256] = "Richard Gatling (1818) - Inventor of the Gatling Gun"; births[257] = "Claudette Colbert (1905) - Actress"; births[258] = "Jack Hawkins (1910) - British film actor"; births[259] = "Agatha Christie (1891) - Detective storywriter"; births[260] = "B. B. King (1925) - Musician"; births[261] = "John Ritter (1948) - Actor"; births[262] = "Samuel Johnson (1709) - 18th century writer"; births[263] = "George Cadbury (1839) - Chocolate manufacturer"; births[264] = "Sophia Loren (1934) - Italian film actress"; births[265] = "H G Wells (1866) - Science fiction novelist"; births[266] = "Michael Faraday (1791) - Inventor of the electric generator 1831"; births[267] = "Julio Iglesias (1943) - Singer"; births[268] = "Anthony Newley (1931) - Actor"; births[269] = "Meat Loaf (1947) - Singer"; births[270] = "George Gershwin (1898) - Composer"; births[271] = "Mike Schmidt (1949) - Baseball player"; births[272] = "Lech Walesa (1943) - Founder of Solidarity"; births[273] = "Horatio Nelson (1758) - Commander"; births[274] = "Johnny Mathis (1935) - Singer"; births[275] = "Jimmy Carter (1924) - 39th American President"; births[276] = "Mahatma K Gandhi (1869) - Hindu spiritual leader"; births[277] = "Chubby Checker (1941) - Singer"; births[278] = "Buster Keaton (1895) - Silent film comedy actor"; births[279] = "Donnald Pleasence (1919) - Actor"; births[280] = "George Westinghouse (1846) - Inventor of the railway air brake"; births[281] = "Yo-Yo Ma (1955) - Musician"; births[282] = "R. L. Stine (1943) - Author"; births[283] = "John Lennon (1940) - Beatles song writer"; births[284] = "William Morris (1877) - Motoring pioneer"; births[285] = "Henry J Heins (1844) - Food products manufacturer"; births[286] = "Ramsay MacDonald (1866) - 39th British Prime Minister"; births[287] = "Margaret H Thatcher (1925) - First woman Prime Minister"; births[288] = "Dwight Eisenhower (1890) - 34th American President"; births[289] = "John L Sullivan (1858) - World heavyweight boxing champion"; So I have a scheduler on a website that shows events . Currently, the scheduler defaults to 1 pm. However, I would like it to default to the time of day to show what is happening right now. So, says it's 5 p.m., when someone visits the site, I'd like it to automatically open up to 5pm. I talked to the creator of it and he said it can be done through javascript. Any ideas of what I would add to this script to do so? <script type="text/javascript" src="http://kacvtv.org/rotatorjs/flashobject.js"></script> <div id="flashcontent"><a href="/Schedule/"><img border="0" src="/images/flash_viewschedule.gif" alt="" /></a><a href="http://www.macromedia.com/go/getflashplayer"><img border="0" src="/images/flash_getflash.gif" alt="" /></a></div> <script type="text/javascript">var fo = new FlashObject("/schedule.swf?currentTime=Nov 29, 2006 01:20:27 PM", "homeflash", "595", "240", "7", "#FFFFFF"); fo.addParam("wmode","transparent"); fo.write("flashcontent"); </script> I dont know the first thing about java script but I also didnt know the first thing about html and css but someone showed me a few basic things to gt started and Ive excelled in both using dreamweaver. I just needed the basics and then I was able to work through it. Just like that I need help starting out with Java Script. Basically, Ive made a website and now I am trying to put in a slider(it is a photo slider which has a box drop down on the right with a description when it changes photos.) I was told to make a slider.css file in the css folder and a slider.js file in the java script folder. I coded everything correctly in the source code page to get the slider up and running. But it wont work. Am I supposed to have a Java script program downloaded or something? Please help if you know what Im talking about Ive hit a road block and if you can walk me through this process I would really appreciate it and I can continue with my project. Thanks So I was asked to input a recipe coding into my page, so that when you get the output of the servings, it's multiplied by what I put in the code. Here is the assignment : http://webct.dvc.edu/SCRIPT/COMSC100...C100_5059_FA11.. it's assignment # 7 and here is my coding ; html> <head> <title> COMSC 100 Assignment 7 by John Doe [1190802] </title> <script> function getInputAsText(_id){return document.getElementById(_id).value} function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)} function setOutput(_id, _value){document.getElementById(_id).value = _value} function calculate() { // declare all variables var amount1 var amount2 var amount3 var amount4 var amount5 // get variable's value first = getInputAsNumber("first") second = getInputAsNumber("second") third = getInputAsNumber("third") fourth = getInputAsNumber("fourth") fifth = getInputAsNumber("fifth") // perform conversions amount1=amount1 / servingsBase * servingsNeeded amount2=amount2 / servingsBase * servingsNeeded amount3=amount3 / servingsBase * servingsNeeded amount4=amount4 / servingsBase * servingsNeeded amount5=amount5 / servingsBase * servingsNeeded // write output value setOutput("servingsBase", servingsNeeded) } </script> </head> <body> Recipe Converter:<br> To change the recipe for each<br> type the amount of each ingrediant<br> type the amount of servings<br> click go<br> converted amounts will where original amounts we <br> <br> Input AND Output values:<br> For this many servings: <input id="first"> sugar:<input id="second"><br> milk:<input id="third"><br> food:<input id="fourth"><br> water:<input id="fifth"><br> <input type="submit" value="go" onclick="calculate()"><br> </body> </html> what am I doing wrong?! my teacher is no help at all! ugh Starting off by saying this is directly from a book: Code: <script type="text/javascript"> /* <![CDATA[ */ function validateCard(){ //American Express if(document.forms[0].cardName.value =="American Express"){ var cardProtocol = new RegExp("^3[47][0-9]{13}$"); if(cardProtocol.test(document.forms[0] .cardNumber.value)) document.forms[0].ccResult.value ="Valid credit card number"; else document.forms[0].ccResult.value ="Invalid credit card number"; } //Diners Club else if(document.forms[0].cardName.value =="Diners Club"){ var cardProtocol = new RegExp("^3(?:0[0-5]|[68][0-9])[0-9]{11}$"); if(cardProtocol.test(document.forms[0] .cardNumber.value)) document.forms[0].ccResult.value ="Valid credit card number"; else document.forms[0].ccResult.value ="Invalid credit card number"; } //Discover else if(document.forms[0].cardName.value =="Discover"){ var cardProtocol = new RegExp("^6(?:011|5[0-9]{2})[0-9]{12}$"); if(cardProtocol.test(document.forms[0] .cardNumber.value)) document.forms[0].ccResult.value ="Valid credit card number"; else document.forms[0].ccResult.value ="Invalid credit card number"; } //JCB else if(document.forms[0].cardName.value =="JCB"){ var cardProtocol = new RegExp("^(?:2131|1800|35\d{3})\d{11}$"); if(cardProtocol.test(document.forms[0] .cardNumber.value)) document.forms[0].ccResult.value ="Valid credit card number"; else document.forms[0].ccResult.value ="Invalid credit card number"; } //Mastercard else if(document.forms[0].cardName.value =="Mastercard"){ var cardProtocol = new RegExp("^5[1-5][0-9]{14}$"); if(cardProtocol.test(document.forms[0] .cardNumber.value)) document.forms[0].ccResult.value ="Valid credit card number"; else document.forms[0].ccResult.value ="Invalid credit card number"; } //Visa else if(document.forms[0].cardName.value =="Visa"){ var cardProtocol = new RegExp("^4[0-9]{12}(?:[0-9]{3})?$"); if(cardProtocol.test(document.forms[0] .cardNumber.value)) document.forms[0].ccResult.value ="Valid credit card number"; else document.forms[0].ccResult.value ="Invalid credit card number"; } } /* ]]> */ </script> With a drop down box for the card type and a text-box to input a credit card number of appropriate length. My question, the teacher asked us to help make this code more "efficient" and I'm still learning the language, and was wondering if a loop could be utilized to make the code more efficient? Switch statement would just repeat the code practically Hi I use dreamweaver to build sites, and so don't really have to do much with the code, however adobe cs5 has removed the navigation bar tool and I am totally lost without it. I know Java script is needed... Could anyone help? If someone has some code ,for a vertical navigation bar with 8 buttons, 3 images for each button, buttonup mouse over and button down (which is of course a link to another page), that I could copy and edit, it would help alot! Hi! First of, I want to say that I don't have a lot of knowledge with js, so please bare with me. I have this function: Code: function formFunction() { return new LightFace({ title: $('demo1title').value, content: $('demo1content').value, draggable: true }).open(); } It is a part of a code that displays a small on-page window. However, within that code I want to have a form that posts $('demo1title').value as a hidden value. Any idea how to do this? The below script keeps a running total dollar tab. It uses the "name" of the elements but I would like it to use the "ID" instead. Can somebody pretty please adjust the function to look at the id. I've changed the first 2 form elements to id. Tracy Code: <script language="JavaScript" type="text/javascript"> <!-- function CalculateTotal(frm) { var order_total = 0 // Run through all the form fields for (var i=0; i < frm.elements.length; ++i) { // Get the current field form_field = frm.elements[i] // Get the field's name form_name = form_field.name // Is it a "product" field? if (form_name.substring(0,4) == "PROD") { // If so, extract the price from the name item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1)) // Get the quantity item_quantity = parseInt(form_field.value) // Update the order total if (item_quantity >= 0) { order_total += item_quantity * item_price } } } // Display the total rounded to two decimal places frm.TOTAL.value = round_decimals(order_total, 2) } function round_decimals(original_number, decimals) { var result1 = original_number * Math.pow(10, decimals) var result2 = Math.round(result1) var result3 = result2 / Math.pow(10, decimals) return pad_with_zeros(result3, decimals) } function pad_with_zeros(rounded_value, decimal_places) { // Convert the number to a string var value_string = rounded_value.toString() // Locate the decimal point var decimal_location = value_string.indexOf(".") // Is there a decimal point? if (decimal_location == -1) { // If no, then all decimal places will be padded with 0s decimal_part_length = 0 // If decimal_places is greater than zero, tack on a decimal point value_string += decimal_places > 0 ? "." : "" } else { // If yes, then only the extra decimal places will be padded with 0s decimal_part_length = value_string.length - decimal_location - 1 } // Calculate the number of decimal places that need to be padded with 0s var pad_total = decimal_places - decimal_part_length if (pad_total > 0) { // Pad the string with 0s for (var counter = 1; counter <= pad_total; counter++) value_string += "0" } return value_string } //--> </script> <FORM> <TABLE BORDER =3> <TR><TD ALIGN="CENTER"><B>Please <BR> enter <BR> quantity:</FONT></TD> <TD ALIGN="CENTER"><B>Description</TD><TD ALIGN="CENTER"><B>Price<BR> (each)</B></TD></TR> <TR> <TD ALIGN="CENTER"><INPUT TYPE=TEXT ID="PROD_SP_4.99" SIZE=3 MAXLENGTH=3 onkeyup="CalculateTotal(this.form)"></TD><TD>Spelt Bread 24 oz</TD><TD ALIGN="RIGHT">$4.99</TD> </TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT ID="PROD_SPMG_4.99" SIZE=3 MAXLENGTH=3 onkeyup="CalculateTotal(this.form)"></TD><TD>Spelt Multi-Grain Bread* 24 oz</TD><TD ALIGN="RIGHT">$4.99</TD> </TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_SPCR_4.99" SIZE=3 MAXLENGTH=3 onkeyup="CalculateTotal(this.form)"></TD><TD>Spelt Cinnamon-Raisin Bread 24 oz</TD><TD ALIGN="RIGHT">$4.99</TD> </TR> <TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_SW_3.99" SIZE=3 MAXLENGTH=3 onkeyup="CalculateTotal(this.form)"></TD><TD>Spelt White Bread* 18 oz</TD><TD ALIGN="RIGHT">$3.99</TD> </TR> <TD>TOTAL</TD> <TD ALIGN="RIGHT"><INPUT TYPE=TEXT NAME=TOTAL SIZE=10 onFocus="this.form.elements[0].focus()"></TD> </TABLE> <P> </FORM> I am trying to create a form that writes text to an HTML canvas when submitted. Eventually, the function that writes the text will be more complex. The problem is the text only appears briefly, because the function is only called once when the form is submitted. I want the function to be called continuously after the form is submitted. How do I do this? I have had very little experience with JS. A lame (failed) attempt... Code: <html> <head> </head> <body> <canvas id="canvas" width="790" height="605"> Sorry, your browser doesn't support HTML5 </canvas> <form name="frm1" action=" " onsubmit="greeting()"> <input type="text" name="fname" /> </form> </body> <script type="text/javascript"> function init() { //use canvas "canvas" and assign to variable canvas canvas=document.getElementById("canvas"); c=canvas.getContext("2d"); } function greeting() { c.fillText("var!!!", 100, 460); var test = 1; } if (test == 1) { greeting(); } init(); </script> </html> Thanks Hi, I am quite new to javascript but I'm quite sure this problem is very easy to solve. I have a vague idea of what might be going wrong but I have no idea what I should be doing instead. Here is what I'm trying to do: User inputs X and Y coordinates into form validate that they are numbers do a little bit of maths redirect to a php script with a single variable tacked onto the end of the url Here is the form code: Code: //part of a larger php script to make the form echo "<form name='gotoForm' onsubmit='return coordCalc()'> <fieldset> <legend>Go to Square</legend> X <input type='text' id='X' size='1' maxlength='3'/> Y <input type='text' id='Y' size='1' maxlength='3'/> <input type='submit' value='Go To' /> </fieldset> </form> "; which references these functions in the header: Code: //Is it a number function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } //deal with the input, check if they are both numbers with the above function //if they are do some maths on the input //add the result onto a url and redirect function coordCalc (){ var Xcoord = document.getElementById('X'); var Ycoord = document.getElementById('Y'); if(isNumeric(Xcoord, "Please enter a Number for X")){ if(isNumeric(Ycoord, "Please enter a Number for Y")){ //Takes the X and Y coordinates and transforms them into a single number //not fully coded in case you try putting some numbers into the formula btw :) var X = parseInt(document.getElementById('X').value); var Y = parseInt(document.getElementById('Y').value); var G = 16; var Z = (((G + 1) - Y) - Y); var A = (Y + Z); var B = (X - 1); var L = ((A * (G - 1)) + B); window.location = "map.php?start=" + L; } } return false; } The number validation works but the url ends up as map.php?start=NaN. Now, this simply must be the way I am assigning the Xcoord and Ycoord variables with the document.getElementByID() function I am sure. But like I said, I have no idea what to do instead, any help is massively appreciated. Thankyou! Newbie developer/sys admin working on a SalesForce platform here, so excuse my ignorance with terminology. This is a file upload problem. The current code first inserts a record into Salesforce, THEN posts to Amazon S3. The record is just a unique URL that is a link to where Amazon houses the file. Problem here is that sometimes users cancel/close the page before form submits, but the record is already created. Now, I need to reverse this so that it first posts to Amazon S3, then inserts the "link" record. Is there a way to evaluate if a post is successful THEN trigger the apex method OR a second javascript function? Relevant bits he (if we need the entire page, i can paste that too, but alot of it is apex and salesforce specific) Code: <script type="text/javascript"> var sendFile = false; var ProgressImage = document.getElementById('{!$Resource.ajaxloader}'); document.getElementById('{!$Component.hiddenServerURL}').value = '{!$Api.Enterprise_Server_URL_140}'; function setFileName(file) { var f = file.replace(/\\/g, ""); f = f.replace(/C\:fakepath/g, ""); <!--Required for IE8--> document.s3Form.key.value = "{!CustomerName}/{!OrderName}/" + f; document.getElementById('{!$Component.fileName}').value = f; suffix = f.lastIndexOf(".") + 1; contentType = f.slice(suffix); document.getElementById('{!$Component.contentType}').value = contentType; } function setFileType(type) { document.getElementById('{!$Component.fileType}').value = type; } function checkFile() { if (document.s3Form.file.value=="") { alert("Please, select a file."); return false; } else if (document.s3Form.fType.value=="--None--") { alert("Please, select a file type."); return false; } else { loadSubmit(); insertFile(); sendFile = true; } } function submitFile() { if(sendFile = false) { return false; } else { document.s3Form.submit(); } } function loadSubmit() { document.getElementById("progress").style.visibility = "visible"; setTimeout(function(){ProgressImage.src = ProgressImage.src},100); return true; } function cancelFile() { window.location.href = "{!$Setup.companyInfo__c.colliers__c}"; } function completeFile() { completeOrder(); } </script> apex:actionFunction on this page, javascript can directly make a call to the class and invoke a method there. Code: <apex:actionFunction name="insertFile" action="{!insertFile}" oncomplete="submitFile();return false;"/> the pertinent "html" (visualforce) for this page Code: <apex:pageBlockButtons location="bottom"> <input class="btn" type="button" value="Upload File" onClick="checkFile();return false;"/> <input class="btn" type="button" value="Cancel" onClick="cancelFile();return false;"/> <input class="btn" type="button" value="Complete Order" onClick="completeFile();return false;"/> </apex:pageBlockButtons> This piece is from the class/extension: Code: //SF File insert on an object (passed from page) public PageReference insertFile() { this.file.Name = fileName; this.file.Type__c = fileType; this.file.Content__c = contentType; insert this.file; return null; } Ideally, i would like to change the checkFile() function to something like the below - but haven't had much luck in researching how to accomplish this... Code: function checkFile() { if (document.s3Form.file.value=="") { alert("Please, select a file."); return false; } else if (document.s3Form.fType.value=="--None--") { alert("Please, select a file type."); return false; } else { loadSubmit(); if(document.seForm.submit() = true) insertFile(); } } UPDATE: I just learned that S3 should return a "success_action_status" if the post is successful - how do i use this to achieve what I need? (http://docs.amazonwebservices.com/Am...POSTForms.html) I am trying to create a function or have this work some how where it displays the first number when you make your choice in the first drop down box, which is working so far. In the second drop down box, if any of the answers are chosen except for none, it will take off 10% of the first number. Then add or subtract from there. I just have a problem with creating a function to take off that 10%. Here is the javascript: Code: /* This source is shared under the terms of LGPL 3 www.gnu.org/licenses/lgpl.html You are free to use the code in Commercial or non-commercial projects */ //Set up an associative array //The keys represent the size of the cake //The values represent the cost of the cake i.e A 10" cake cost's $35 var practice_field = new Array(); practice_field["None"]=0; practice_field["Allergy and Immunology"]=4400; practice_field["Endocrinology"]=4400; practice_field["Pathology"]=4400; practice_field["Dermatology"]=4400; practice_field["Geriatrics"]=4400; practice_field["Physical Rehabilitation"]=4400; practice_field["Family Practice"]=6900; practice_field["General Practice"]=6900; practice_field["Internal Medicine"]=6900; practice_field["Oncology"]=6900; practice_field["Oral Surgery"]=6900; practice_field["Radiology"]=6900; practice_field["Gastroenterology"]=6900; practice_field["Infectious Disease"]=6900; practice_field["Nephrology"]=6900; practice_field["Ophthalmology"]=6900; practice_field["Pediatrics"]=6900; practice_field["Urology"]=6900; practice_field["Anesthesiology"]=9000; practice_field["Cosmetic Surgery"]=9000; practice_field["General Surgery"]=9000; practice_field["Neurology"]=9000; practice_field["Otolaryngology"]=9000; practice_field["Plastic Surgery"]=9000; practice_field["Vascular Surgery"]=9000; practice_field["Cardiology"]=9000; practice_field["Emergency Medicine"]=9000; practice_field["Gynecology"]=9000; practice_field["Orthopedic Surgery"]=9000; practice_field["Pain Management"]=9000; practice_field["Pulmonary Surgery"]=9000; practice_field["Neurological Surgery"]=9900; practice_field["Obstetrics"]=9900; //Set up an associative array //The keys represent the filling type //The value represents the cost of the filling i.e. Lemon filling is $5,Dobash filling is $9 //We use this this array when the user selects a filling from the form var society_member= new Array(); society_member["None"]=1; society_member["BCMA"]=0.10; society_member["DCMA"]=0.10; society_member["FOGS"]=0.10; society_member["FNS"]=0.10; society_member["PBCMS"]=0.10; society_member["FSPS"]=0.10; //This function finds the filling price based on the //drop down selection function getPracticeField() { var docPracticeField=0; //Get a reference to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the select id="filling" var selectedPracticeField = theForm.elements["practice"]; //set cakeFilling Price equal to value user chose //For example filling_prices["Lemon".value] would be equal to 5 docPracticeField = practice_field[selectedPracticeField.value]; //finally we return cakeFillingPrice return docPracticeField; } //This function finds the filling price based on the //drop down selection function getSelectedSociety() { var docSelectedSociety=0; //Get a reference to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the select id="filling" var selectedSociety = theForm.elements["society"]; //set cakeFilling Price equal to value user chose //For example filling_prices["Lemon".value] would be equal to 5 docSelectedSociety = society_member[selectedSociety.value]; //finally we return cakeFillingPrice return docSelectedSociety; } //candlesPrice() finds the candles price based on a check box selection function candlesPrice() { var candlePrice=0; //Get a reference to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the checkbox id="includecandles" var includeCandles = theForm.elements["includecandles"]; //If they checked the box set candlePrice to 5 if(includeCandles.checked==true) { candlePrice=5; } //finally we return the candlePrice return candlePrice; } function insciptionPrice() { //This local variable will be used to decide whether or not to charge for the inscription //If the user checked the box this value will be 20 //otherwise it will remain at 0 var inscriptionPrice=0; //Get a refernce to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the checkbox id="includeinscription" var includeInscription = theForm.elements["includeinscription"]; //If they checked the box set inscriptionPrice to 20 if(includeInscription.checked==true){ inscriptionPrice=20; } //finally we return the inscriptionPrice return inscriptionPrice; } function calculateTotal() { //Here we get the total price by calling our function //Each function returns a number so by calling them we add the values they return together var cakePrice = getPracticeField() * getSelectedSociety() + candlesPrice() + insciptionPrice(); //display the result var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Price For the Cake $"+cakePrice; } function hideTotal() { var divobj = document.getElementById('totalPrice'); divobj.style.display='none'; } Hello I am fairly new to Javascript. I have a function which takes a string which consists of key value pairs and sets a form control based on key being the form element name and value being the value to set. eg string could be "key1=orange;key2=2;key3=whetever" Here is the function: function processresponse(frm, serverResponse) { var items = serverResponse.split(";"); for(var i = 0; i < items.length; i++) { var item = items[i]; var eqchar = item.search("="); if(eqchar != -1) { var key = item.slice(0, eqchar); var value = item.slice(eqchar+1); var elemname = key; if(document.getElementById(elemname) != null) { var type = frm.elements[elemname].type; if (type=="checkbox") { value == "1" ? frm.elements[elemname].checked=true : frm.elements[elemname].checked=false; } else if (type=="text"){ //do processing for text (text input) frm.elements[elemname].value = value; } else if(type=="select-one"){ //only one is openformmode - default to [0] - true if(value == "0" || value.length == 0) { frm.elements[elemname].options[0].selected = true; } else { frm.elements[elemname].options[1].selected = true; } } else { alert("unknown ctrl type: " + type + " name: " + frm.elements[elemname].name + " val: " + value + " key: " + key); } } //if(frm.getElementById(elemname) } } } The problem line is: var type = frm.elements[elemname].type; elemname is case sensitive so if for example the form element is called dog and the string elemname is Dog, then the line fails with Error: 'elements[...].type' is null or not an object So my check if(document.getElementById(elemname) != null) is insufficient to guard against this. I realise I could do a try catch but there must be a more legant way than that. How can I test the formname more reliably? Any ideas would be very welcome. Angus |