JavaScript - Need Help With Javascript Controlling Functions With Paypal Form
I am trying to do a custom add to cart to use with paypal and need to utilize javascript to achieve inserting some code or a weight value per the paypal forms' options choice. Here is my dilemma, All of my items have multiple weights, for instance the below example called Aqua Max 100 comes in .5lbs, 1.5lbs., 10lbs., 20lbs., and 50lbs. Paypal allows you to enter weight but it's one weight per item and I would have to create 5 Paypal buttons just for this one item to calculate the different weights per zip code. I need help making javascript insert the following code within the paypal forms' code upon option select before clicking submit?
<input type="hidden" name="weight" value=".5"> <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="1.5"> <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="10 <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="20 <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="50 <input type="hidden" name="weight_unit" value="lbs"> The code I came up with is wrong as I'm getting an error but I was originally trying to make it enter a weight using a hidden fillable number and without any real javascript training, just alot of googling but I think I'm pretty close. Please take a look at the code I've came up with so far and maybe point me in the correct direction: <html> <body> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="test@test.com"> <input type="hidden" name="currency_code" value="USD"> <input type='hidden'text' name='amt' id='amt' value="0.00"/> <table> <tr> <td> <input type="text" name="on0" value="Aqua Max 100">Aqua Max 100</td></tr> <tr><td> <select name="os0" onChange="getamt()"> <option value="select">Please Select</option> <option value="1/2 lb.">1/2 lb. $3.99 USD</option> <option value="1 - 1/2 lbs">1 - 1/2 lbs $7.59 USD</option> <option value="10 lbs.">10 lbs. $25.80 USD</option> <option value="20 lbs.">20 lbs. $42.75 USD</option> <option value="50 lbs.">50 lbs. $86.20 USD</option> </select></td></tr> </table> <script type="text/javascript"> function getamt() { var sh=0; var choice = document.getElementById("os0").selectedIndex; if (choice == 0) { sh=0; } if (choice == 1) { sh=.5; } if (choice == 2) { sh=1.5; } if (choice == 3) { sh=10; } if (choice == 4) { sh=20 } if (choice == 5) { sh=50.00; } document.getElementById("on0").value=sh; } </script> <input type="image" src="https://images.paypal.com/images/sc-but-03.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </body> </html> Similar TutorialsHi all, I'm new here and need some help. I don't know Javascript at all. I have a paypal form that looks like this: Code: <FORM action="https://www.paypal.com/cgi-bin/webscr" method="post"> <INPUT type="hidden" name="cmd" value="_s-xclick"> <INPUT type="hidden" name="hosted_button_id" value="VMMCF6CUGBPAN"> <INPUT type="hidden" name="on0" value="DATA">DATA<BR> <SELECT name="os0"> <OPTION value="250" selected="selected">DATA</OPTION> <OPTION value="400">DATA</OPTION> <OPTION value="1000">DATA</OPTION> </SELECT> <INPUT type="hidden" name="currency_code" value="USD"> <BR> <INPUT type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><IMG alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </FORM> This form works perfectly with my system now. I'm trying to add one fourth option that will redirect to another page, but I'm not sure if changing the name of the select will break the paypal transaction. So I tried this solution: Code: <FORM action="https://www.paypal.com/cgi-bin/webscr" method="post"> <INPUT type="hidden" name="cmd" value="_s-xclick"> <INPUT type="hidden" name="hosted_button_id" value="VMMCF6CUGBPAN"> <INPUT type="hidden" name="URL" value="DATA">DATA<BR> <SELECT name="URL" onchange="window.location.href= this.form.URL.options[this.form.URL.selectedIndex].value"> <OPTION value="250" selected="selected">DATA</OPTION> <OPTION value="500">500 Words</OPTION> <OPTION value="1000">1000 Words</OPTION> <OPTION value="project.html">1000+ Words</OPTION> </SELECT> <INPUT type="hidden" name="currency_code" value="USD"> <BR> <br> <INPUT type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><IMG alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </FORM> It works great if I select the fourth option with a internal url in it. But if I choose one of the other options it tries to dynamically change to a page "250", "500", or "1000" and they don't exist. Also, I'm not sure if changing the select name or the option value will break the transaction with paypal. What I'd like the form to do is nothing on all options except the fourth; which is a redirect. The first, second, and third option require the used to click a paypal buy now button. Can't I just take this... Code: onchange="window.location.href= this.form.URL.options[this.form.URL.selectedIndex].value" ...put it in the option tag and change it to onSelect or something? This is as far as I can go. I copied the code and altered it. Can anyone here help please? Hello, I need your help. I have 2 checkboxes. How would I control one from the other? Eg. [ ] Option A [ ] Option B - If Option A was checked first and, I put a checkmark in option B then Uncheck Option A and leave option B checked. - If Option B was checked and, I put a check mark in Option A then uncheck Option B and leave Option A checked. How would that be written in Javascript, I am totally confused. Any help with this is much and foremost greatly appreciated. Cheers, J I have the following code ... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <title></title> <style type="text/css"> body { background-color:#000; } #scenery { width:964px; height:482px; padding:318px 0 0 316px; margin:auto; background-image:url('http://www.deshow.net/d/file/travel/2009-10/new-zealand-scenery-738-20.jpg'); } </style> </head> <body> <div id="scenery"> <img src="http://cdn3.iconfinder.com/data/icons/softwaredemo/PNG/128x128/DrawingPin1_Blue.png" alt=""> </div> </body> </html> ... in which I would like to use Javascript to control the values in the 'padding'. Code: padding:318px 0 0 316px; May I know how can I use Javascript to control that 'padding' values? Appreciate any help. I am trying to use JavaScript to manipulate the appearance of a web browser. (1) Initially I need to identify and save the current browser settings (e.g. position, height, width, caption on or off, menubar on or off, border on or off). (2) Then I need to change the appearance of the browser to full screen, no border, no caption, no status bar, no menubar). (3) Finally, I need to return the browser to the initial settings using the settings saved at the beginning. I am a novice at JavaScript and am having a difficult time locating details of the language that permit me to accomplish my objectives. John Chapman jchapman@onlinecbt.com Hey guys, I need some help with my website I am making, I have gotten into reading over javascript to try to learn but I am probably far from being able to do anything. If someone wouldnt mind helping that would be great. This is what I am trying to do. here is a sample page of what the code needs to go along with- yes please excuse the crappy coding of HTML and what not. http://decaldude.net/honda.html i am using paypals add to cart buttons. the problem with them is that they only allow you to specify a single price for an item. the two drop down boxes you see have options that can change the cost of that item. so basically what i need is some javascript that looks at the options chosen and based on what is selected, modify the price that is sent to paypal. so yeah would be great if someone could help. dont want to ask too much but if someone else wanted to make it display that change in price where i have the price listed that would be awesome. yeah i make decals so if anyone wants to help out and wants a custom sticker made for them just lemme know. Hi Guys I have a existing Java script that passes payments to Paypal, i now need it changing but have not got a clue about Java, so im looking for some help. would be really gratfull if anyone could help Hi, I have three buttons on my site. When a button is clicked it pulls down a javascript pop up questionaire box. When the person closes the box they're redirected to Paypal depending on which button they clicked, hence the 3 if else options toward the end of this script. How might the following code be rewritten so that the pop up box no longer exists, but so the options still function and redirect correctly to Paypal? Code: <script type="text/javascript"> function popup(option){ Modalbox.show('<div><p>How did you learn about Dinosaur Pop?</p> <textarea id="message" name="message" rows="4" cols="30"></textarea><br><br><input type="button" value="Send" onclick="Modalbox.hide(); redirect(' + option + ');" /> or <input type="button" value="No, leave it!" onclick="Modalbox.hide(); redirect(' + option + ');" /></div>', {title: "Question", width: 300}); return false; } function redirect(option) { var messageObj = document.getElementById("message"); if (messageObj != null && messageObj.value != "") { var url = 'submit_message.php?message=' + encodeURIComponent(messageObj.value); new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { } }) } if (option == 1) document._xclick.submit(); else if (option == 2) document._xclick1.submit(); else if (option == 3) window.location = "download/Dinosaur Pop Book.pdf"; } </script> Okay, here is my assignment: reate an HTML document with 2 JavaScript functions as described below. Call the document useparameters.html The first function will use a parameter for the Width of a horizontal rule. When called, the function will draw a horizontal rule of a width specified by the Functions argument. Prompt the user for the pixel width information. The second function will use parameters for two heading sizes. The parameters will be used for the size of the text that will be displayed on the first line and the size of the text that will be displayed on the second line. The heading size will be different on the first and second lines. Prompt the user for these two headings as well (one prompt for each). The body of the HTML document will contain a page heading and call the two functions you created, displaying a horizontal rule and two lines of text which will be formated based upon the parameters the user entered into the prompts. Here is my code: <!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=UTF-8" /> <title>Use Parameters</title> <script type="text/javascript"> <!-- var hrsize var htwosize var psize function bar() { hrsize = window.prompt( "Please enter the size you want your horizontal rule to be (in pixels)", 50 ) hsize = hrsize document.write("<HR ALIGN='left' width=" + hrsize + ">"); } function output() { htwosize = window.prompt( "Please enter the size you want your heading to be (in pixels)", 18 ) htwosize = htwosize document.write("<h2" + htwosize + "/h2>") } function output() { psize = window.prompt( "Please enter the size you want your paragraphcs to be (in pixels)", 12 ) psize = psize document.write("<p" + psize + "/p>") } --> </script> </head><body> <script type="text/javascript"> <!-- bar(hrsize) output(htwosize) output (psize) --> </script> <h2>JavaScript Rules!</h2><p>Using JavaScript is fun! </p> <p> This is some standard HTML, unlike the above which was generated with javaScript.</p> </body> </html> What am I doing wrong? I would like to start off by saying I know there isn't a sure fire, 100% way to tell if javascript is enabled on a users browser. Because of this, it's a good idea to check form input using a php (or another server-side language) function. Now, let's say the user DOES have javascript enabled. I would like to check that same form input with a javascript function, instead of a php function. How would I be able to do that? If both php and javascript functions are in the same script, how does the browser know which one to run and how can I make it run the javascript function if the user has javascript enabled? Hello all here is a more intelligent question. This one is just on an exercise I am doing. I have to call a function using parameter values. my main function is this Code: function showResults(race,name,party,votes) or just function showResults in the next lines below i have to call the function is this the right way Code: <script type="text/javascript"> { showResults=("race[0],name1,party1,votes1"); } </script> or should it be without the { and } like this? Code: script type="text/javascript"> showResults=("race[0],name1,party1,votes1"); </script> or is it like this Code: script type="text/javascript"> showResults(race[0],name1,party1,votes1); </script> Thanks all, what would be the proper method Thanks Forgive me if the code is rather bad, I am new to Javascript. Now what I'm aiming to do is after I have entered the contents of the Array's I then want to query the newly created array/database, based on the track number, Via a seprate function. However all the values I entered, always come up empty. No matter how many solutions I tried I can't get the query to work. So I've decided to come to you guys/gals for help. Code: mainMenu() function mainMenu() { menu = 0; menu = eval(prompt("Select an Operation to Continue\n ====================\n 1 - Create new Database\n 2 - Query Database\n 3 - Show Report\n Any other to exit")); switch (menu) { case 1: insert(trackNumber) break; case 2: query(trackNumber) break; case 3: break; } } // Enter the track number function trackNumber() { var theNumber = eval(prompt("Enter Track Number")); if ((theNumber >= 0) && (theNumber < 100)) { return theNumber; // Stores the track number for insert(trackNumber) } } // This function will allow the user via the (trackNumber) // parameter to insert the contents of the database function insert(trackNumber) { // Create new Array's trackNum = new Array(5) trackName = new Array(5) trackArtist = new Array(5) // For each Track we want to hold the trackNumber(), // the track name and the track's artist. for(var i = 0; i < trackNum.length; i++) { trackNum[i] = trackNumber() trackName[i]= prompt("Enter Track Name: " + i) trackArtist[i] = prompt("Enter Track Artist: " + i) } } // This Function will allow the user to query the database, based on track number. function query(trackNumber) { var trackSearch = trackNumber() var j = 0; for(j in query) { if (query[j] == trackSearch) { alert("Track Number: " + trackSearch + "\nTrack Name: " + trackName[j] + "\nTrack Artist " + trackArtist[j]); break; } else if (query[j] != trackSearch) { alert("Track Number: Empty" + "\nTrack Name: Empty" + "\nTrack Artist: Empty"); break; } } } If someone could please help me by posting some relevant code that would help accomplish this, I would greatly appreciate it, as so far I have been scratching my head puzzled, at how I could solve this. i am new to JavaScript and i have an assignment to create a tour calculator here is the code and its not working please help its urgent thanks. [code] <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> .font { font-size: 28pt; } font2 { font-size: 15pt; } </style> </head> <body> <strong class="font">USA Tour Cost Calculator</strong> <br/> <br/> Conplete the form below to calculate the cost of your tour of the United States <script type="text/javascript"> function calculate(){ var cost=0; var accomodation=0 var radio1 var radio2 var duration=0 function accomodation() { for (var i=1; i<=3; i++) {radio1= document.getElementById("radio"+i); if (radio1.checked==true) {accomodation=i;}} if (accomodation=1){cost=parseInt(radio.value); return value;} else if (accomodation=2){cost=parseInt(radio.value); return value;} else if (accomodation=3) {cost=parseInt(radio.value);return value;} else {window.alert("Please select the type of accomodation")} } function peak() { var cost=accomodation() var peak=document.getElementById("check1") if (peak.checked==true) {cost +=parseInt(checkbox.value); return value;} else {cost=accomodation()} } function calc(){ var cost=peak() for (var i=1; i<=4; i++){ radio2=document.getElementById("Radiobutton"+i); if (radio2.checked==true) {duration=i;} if (duration=1) {cost*=parseInt(radio.value); return value;} else if (duraion=2){cost*=parseInt(radio.value); return value;} else if(duration=3) {cost*=parseInt(radio.value); return value;} else if(duration=4){caost*=parseInt(radio.value); return value;} else {alert("Please select the duration of tour")} } } </script> <br/> <form id="form2" name="form2" method="post" action=""> <p> <label> <input type="radio" name="RadioGroup2" value="95" id="Radio1" /> Camping</label> <br /> <label> <input type="radio" name="RadioGroup2" value="140" id="Radio2" /> Budget Hotel</label> <br /> <label> <input type="radio" name="RadioGroup2" value="170" id="Radio3" /> Premier Hotel</label> <br /> </p> </form> Click here if you will be travelling during the peak season of June to August: <input name="" type="checkbox" value="20" id="check1" /> <br/> <br/> Duration of tour: <form id="form1" name="form1" method="post" action=""> <label> <input type="radio" name="RadioGroup1" value="4" id="Radiobutton1" /> 4 days, 1sate</label> <br /> <label> <input type="radio" name="RadioGroup1" value="7" id="Radiobutton2" /> 7 dasy, 3 states</label> <br /> <label> <input type="radio" name="RadioGroup1" value="14" id="Radiobutton3" /> 14 days, 12 states</label> <br /> <label> <input type="radio" name="RadioGroup1" value="20" id="Radiobutton4" /> 20 days, 18 states</label> <br /> </p> </form> <br/> <p> <input type="submit" value="Calculate" onClick='alert("The total cost of your tour is $calculate();")'><input type="reset" value="Reset" /></p> </body> </html> [code] Hello, Iam currently experimenting with Java Scripting and have hit a wall about the use of Functions. I am trying to create a difference function which would work out the difference between two numbers. e.g. 14 and 18 I am able to create a function and if statement to find the larger number of a argument but am having trouble writing one to find the difference between two numbers. Iam also confused (i know probably a silly question) but is the operator used the same for this function. Hope people can make sense of that. Thanks, Hi guys, I need some help here.. I have created a simple JS and HTML NAME form validation and checked box as shown (If anyone can help me about the check box a better and easy way to code would be great). I would like to use the functions that I have created - can anyone tell me HOW I can use them please? I tried to use like this.. Code: var name = document.getElementById('name').value; if(name(!notEmpty && !isAlphabet)) { error_mesg += "\nPlease enter your Name"; error_num++; } ..but it does not work...anyone can give me some idea? Code: .. .. <script type='text/javascript'> function formValidation(){ var error_mesg = "Following error found\n"; var error_num = 0; var name = document.getElementById('name').value; if(name==""){ error_mesg += "\nPlease enter your Name"; error_num++; } var terms = !document.getElementById('terms').checked; //Can anyone tell me what is the function of "checked" here for? if (terms){ error_mesg += "\nPlease check the terms and conditions"; error_num++; } if(error_num>0){ alert(error_mesg); elem.focus(); return false; }else{ //submit form return true; } } function notEmpty(elem, error_mesg){ if(elem.value.length == 0){ alert(error_mesg); elem.focus(); // set the focus to this input return false; } return true; } function isAlphabet(elem, error_mesg){ var alphaExp = /^[a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(error_mesg); elem.focus(); return false; } } .. .. [HTML FORM] .. <form name="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="return formValidation()"> <tr align="left" valign="top> <td width="20%">NAME:<font color="#CE0000" >*</font></td> <td width="80%"><input name="name" type="text" id="name" size="30" /></td> </tr> <tr><td><input type=checkbox name=terms value='yes'>I agree to terms and conditions </td></tr> .. .. <input type="hidden" name="action" value="register"/> <input name="submit" type="submit" value="Proceed" /> All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero Hello folks: I've got an html table populated by a php foreach routine. One field in this table is an Input type=checkbox. The goal is to run a javascript function when the user checks the checkbox. But, since the checkbox is in a table populated by a foreach routine, I'm having some problems. Below is the applicable code for my table: <?php foreach($results as $row) { $bk_owner = $row['BookOwner']; $addrss_owner = $row['AddressOwner']; $f_name = $row['FName']; $l_name = $row['LName']; $email = $row['EmailAddress']; $d_phone = $row['DeskPhone']; $ext = $row['Ext']; $cell = $row['CellPhone']; $title = $row['Title']; echo "<tr>"; echo "<td class='a'>".$l_name ."</td>"; echo "<td class ='a'>".$f_name ."</td>"; echo "<td class ='c'>".$email ."</td>"; echo "<td class ='a'>".$d_phone ."</td>"; echo "<td class='b'>".$ext."</td>"; echo "<td class='a'>".$cell."</td>"; echo "<td class='c'>".$title."</td>"; echo "<td class='b'><input type='checkbox' id='chk_Bx' value=". $addrss_owner. " onClick='selectFunction()'></input></td>"; echo "</tr>"; } echo"</tbody>"; ?> Specifically, note this line: echo "<td class='b'><input type='checkbox' id='chk_Bx' value=". $addrss_owner. " onClick='selectFunction()'></input></td>"; the value is set to $address_owner. This value is a primary key value and will allow me to run routines related to the record chosen when the checkbox is checked. Following is the javascript code for selectFunction(): function selectFunction(){ var check = document.getElementById("chk_Bx").checked; var val = document.getElementById("chk_Bx").value; alert(val); } At this point the javascript is very simple. All I'm trying to do is pick up applicable values for the record selected. But - I believe because the table is populated through a foreach loop, the javascript alert is returning the same primary key value for every record checked (or unchecked). Also, if I alert out check, it continually returns false, even if I've checked the box and it should read true. I am assuming this is also related to the foreach table presentation. How do I grab ONLY the primary key value, or checked true/false for the applicable record? Thanks in advance: Pavilion Hi all, I've written the following script: Code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Keys2</title> <script type="text/javascript"> function keyPress(key){ document.getElementById('rect01').style.fill = "red"; } </script> <style> .button { width: 100px; padding-right:10px; height:2em; background-color:#FC3; border-radius:3px; color:#fff; font-weight:bold; } ul { list-style-type: none; padding: 0; margin-left:25px; } li { float:left; width:30px; margin-right:25px; padding:10px; height:2em; background-color:#FC3; font-size:xx-large; } </style> </head> <body> <div> <svg width="1000" height="200"> <rect x="25" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect01"/> <rect x="100" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect02"/> <rect x="175" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect03"/> <rect x="250" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect04"/> <rect x="325" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect05"/> <rect x="400" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect06"/> <rect x="475" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect07"/> <rect x="550" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect08"/> </svg> </div> <div> <ul> <li><a href="#" class="button" onClick="keyPress(rect01);">A</a></li> <li><a href="#" class="button" onClick="keyPress(rect02);">B</a></li> <li><a href="#" class="button" onClick="keyPress(rect03);">C</a></li> <li><a href="#" class="button" onClick="keyPress(rect04);">D</a></li> <li><a href="#" class="button" onClick="keyPress(rect05);">E</a></li> <li><a href="#" class="button" onClick="keyPress(rect06);">F</a></li> <li><a href="#" class="button" onClick="keyPress(rect07);">G</a></li> <li><a href="#" class="button" onClick="keyPress(rect08);">H</a></li> </ul> </div> </body> </html> Now, I could write a version of the keypress function for each rectangle, but that seems like poor coding. Can anyone point out how I might restructure the function or the code so that I can pass the number in the onClick to the rectangle it refers to? Thanks Hi, i was wondering if there was a way to call a nested javascript function directly, from outside of the function its nested in? for example, if i have the following functions: Code: <script type="text/javascript"> var test = function(){ var testInner = function(){ alert('testInner'); } } </script> can i then call the 'testInner' function directly from an onclick action something like this: Code: <a href="#" onclick="test.testInner()">TEST JS</a><br /><br /> That code is obviously not working for me, but is there something similar to what ive shown here that will work? Thanks in advanced Hi I've set up an html page that contains 3 buttons, which have a sprite rollover effect when hovered over. This is handled by css. When one of the buttons is clicked - a value is passed to an input field. This is handled by Javascript. Both of these functions work. What I would like to do is add a second function when a button is clicked - so that the hover sprite remains selected. Could anyone tell me how to do this please? Here is the button code I have: <button type="button" class="fantasy_button_blue_sprite" id="mcgyver" value="mcgyver" onclick="setHiddenControlValue('option1');">next</button> Here is the input field that gets populated: <input type="<?php echo $type;?>" id="fantasy_friend" name="fantasy_friend" value="<?php echo $fantasy_friend; ?>"> This is the javascript I'm using: <!-- // set the hidden form field when a button is clicked function setHiddenControlValue(selectedValue) { document.getElementById("fantasy_friend").value = selectedValue; parent.document.options_form.their_firstname.value=selectedValue; } And this is the sprite css: .fantasy_button_green_sprite { background: transparent url("/images/align_page/fantasy_button1.jpg") 0 1px no-repeat; height:61px; width:164px; border:none; text-indent:-99999px; cursor: pointer; margin-top:20px; } .fantasy_button_green_sprite:hover { background: transparent url("/images/align_page/fantasy_button1.jpg") 0 -61px no-repeat; } Thanks! Tom --> Hello, I am new to javascript and have managed to create the below form with few fields validation that is working. I also have an email format validation function which is not working. Any help would be hightly appreciated. Below with the form with the javascript <html> <script language="JavaScript" type="text/javascript"> <!-- var radio_selection=""; function checkform ( form ) { **// ** START ** **if (form.name.value == "") { ****alert( "Please enter your name." ); ****form.name.focus(); ****return false; **} if (form.Phone.value == "") { ****alert( "Please enter your phone number." ); ****form.Phone.focus(); ****return false; **} **if (form.email.value == "") { ****alert( "Please enter your email." ); ****form.email.focus(); ****return false; } if (radio_selection=="") { alert("Please indicate your attendance."); return false; } *// ** END ** **return true; } function checkEmail(form) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) { return true; } alert("Invalid E-mail Address! Please re-enter."); return false; } //--> </script> <body> <form style="font-family:lucida calligraphy;font-size:120%;color:maroon" action="invitees.php" method="post" onsubmit="return checkform(this);checkEmail(this.email.value);"> <table cellspacing="5" cellpadding="5" border="0"> <tr> <td valign="top" > <style="font-family:lucida calligraphy;font-size:100%;color:maroon">Name: </td> <td valign="top"> <input type="text" name="name" id="name" size="40" value="" /> </td> </tr> <tr> <td valign="top"> Phone Number </td> <td valign="top"> <input type="text" name="Phone" id="Phone" size="40" value="" /> </td> </tr> <tr> <td valign="top"> Email Address: </td> <td valign="top"> <input type="text" name="email" id="email" size="40" value="" /> </td> </tr> <tr> <td valign="top"> Will You Attend </td> <td valign="top"> <input type="radio" name="Attendance" id="Attendance_0" value="Yes" onClick="radio_selection='yes'" /> Yes <input type="radio" name="Attendance" id="Attendance_1" value="No" onClick="radio_selection='no'"/> No <input type="radio" name="Attendance" id="Attendance_2" value="Maybe" onClick="radio_selection='maybe'"/> Maybe<br/> </td> </tr> <tr> <td valign="top"> Adults <select name ="adults" id="Adults" > <option>0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> </select> </td> <td valign="top"> Kids <select name="kids" id="Kids" > <option>0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> </select> </td> </tr> <tr> <td valign="top"> Post a Note </td> <td valign="top"> <textarea name="Note" id="Note" rows="6" cols="35"></textarea> </td> </tr> <tr> <td colspan="3" align="center"> <input type="submit" value=" Submit Form " /> </td> </tr> </table> </form> </html></body> |