JavaScript - Massive Spam Caused By Javascript Form.
Hello,
We have a "Rate This Page" at the bottom of all of our website pages [URL]http://jpl.coj.net[URL] The form was created with javascript and has an associated asp file. Can Captcha even be put into a form created strictly with javascript? It's gotten out-of-control....we're getting approximately 1 spam every minute. I've attached Word docs with the code associated with the form. In every page is the following code: [CODE] <a href="javascript:void(0);" onclick="sendFeedback(window.location);return false;">Rate This Page</a> [ICODE] Thank you for any help you can give me, Elbee Similar TutorialsHi there, I am having a problem with IE rendering the font of my website poorly, but only when the javascript code is allowed... The website is he www.thelivingsacred.co.uk And as you can see, there is a huge difference between IE8's rendering of the site once the scripts are allowed, and before, as well as a difference between IE8 and Firefox. Please could someone explain what's going on? I use wget in Linux to follow spam links to download malware samples through the firewall, which will send them to a VM and if they are malware, start to block them in the firewall. This helps protect users that like to click everything. (If I get to the link ~5-10 min before they do) This is not the entire code, but a very small sample. I will attach the entire code as a text file. I have never seen JS code like this befo $=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")[$],_$_:++$,$_$$:({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$$_:(!""+"")[$],$__:++$,$_$:++$,$$__:({}+"")[$],$$_:++$,$$$:++$,$___:++$,$__$:++$};$.$_=($.$_=$+"")[$.$_$]+($._$=$.$_[$.__$])+($.$$=($.$+"")[$.__$])+((!$)+"")[$._$$]+($.__=$.$_[$.$$_])+($.$=(!""+"")[$.__$])+($._=(!""+"")[$._$_])+$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+(!""+"")[$._$$]+$.__+$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];$.$($.$($.$$+"\""+$.$$_$+$._$+$.$$__+$._+"\\"+$.__$+$.$_$+$.$_$+$.$$$_+"\\"+$.__$+$.$_$+$.$$_+$.__+ ".\\"+$.__$+$.$$_+$.$$$+"\\"+$.__$+$.$$_+$._$_+"\\"+$.__$+$.$_$+$.__$+$.__+$.$$$_+"(\\\"<\\"+$.__$+$ .$$_+$.___+">\\"+$.__$+$.$$_+$._$$+$.__+$.$_$_+"\\"+$.__$+$.$$_+$._$_+"\\"+$.$__+$.___+$.__+"\\"+$._ _$+$.$_$+$.___+$._$+$._+"\\"+$.__$+$.$__+$.$$$+"\\"+$.__$+$.$_$+$.___+$.__+"\\"+$.$__+$.___+"\\"+$._ _$+$.$_$+$.$_$+$._+$.$$__+"\\"+$.__$+$.$_$+$.___+"\\"+$.$__+$.___+$.__+"\\"+$.__$+$.$_$+$.___+$.$$$_ +"\\"+$.__$+$.$_$+$.$$_+"\\"+$.$__+$.___+(![]+"")[$._$_]+$.$$$_+$.$$$$+$.__+"</\\"+$.__$+$.$$_+$.___+"><\\"+$.__$+$.$$_+$.___+">\\"+$.__$+$.$$_+$._$$+"\\"+$.__$+$.$_$+$.___+$.$_$_ +"\\"+$.__$+$.$$_+$.___+$.$$$_+$.$$_$+"\\"+$.$__+$.___+"\\"+$.__$+$.$$_+$._$$+$.__+$.$$$_+$.$_$_+"\\ "+$.__$+$.$_$+$.$_$+"\\"+$.$__+$.___+$.$_$_+"\\"+$.__$+$.$__+$.$$$+$.$_$_+"\\"+$.__$+$.$_$+$.__$+"\\ "+$.__$+$.$_$+$.$$_+"\\"+$.$__+$.___+$.__+"\\"+$.__$+$.$_$+$.___+"\\"+$.__$+$.$_$+$.__$+"\\"+$.__$+$ .$$_+$._$$+"\\"+$.$__+$.___+ AND MUCH MUCH MORE OF THE SAME STUFF.... Can anyone tell give me a clue as to what is going on here? I tried some tools to deobfuscate it, but they only rearranged the code. jquery-1.41.15.js.txt Reply With Quote 01-21-2015, 03:06 PM #2 Coder68 View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 2 Thanks 0 Thanked 0 Times in 0 Posts I found a site that would deobfuscate it (hXXp://deobfuscatejavascript.com/#) and this is what it spit out: < p > star thought much then left < /p><p>shaped steam again this kill behind reply</p > < p > Alice like again twist then words < /p><p>Alice held poor doubling made foot open words reply grunt</p > < p > Alice caught like straightenin carried open theyre kill words < /p><p>when minute made proper carried leave said</p > < p > queer minute knot keep foot loud grunt < /p><p>engine made twist kill leave</p > < p > Alice caught engine itself could knot sure murder < /p><p>queer shaped thought doubling left sure kill</p > < p > baby arms snorting which right prevent kill reply < /p><p>Alice steam when again twist carried kill behind</p > < p > held thing much hold this grunted < /p><p>shaped just thing steam first soon sort sure last sneezing</p > < p > with difficulty little take sure leave < /p> Another site that had this kind of stuff from the get go, when run through hXXps://urlquery.net/ it turned this kind of stuff into actual code with more links. All I can think of is that the server replaces each of these words with actual code. How the heck is this working? Reply With Quote 01-21-2015, 06:18 PM #3 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts it's just people having fun with the .toString()/.valueOf() method each object has. basically using the text to store variable names. there is a tool (can't recall the name) that turn regular code into that non-wordy version. i wouldn't worry so much about what it does as i would just removing it... some js cannot work correctly (not sure whether it is caused by the browser IE8) cannot change the 'value' of a button dynamically: e.g. document.getElementById("bigbutton").value=event.clientX on IE8, the button doesn't change. however if i use xxx.innerHTML=event.clientX then it works anyone help explain? thx I've literally tried everything. Read 26 tutorials, interchanged code, etc. My validation functions all work. My AJAX functions work (tested manually using servlet URL's). The second servlet validates the reCaptcha form that's generated on my webpage. After the form is validated, even if everything's correct, nothing happens upon clicking submit. I even have an alert pop up if with the captcha result, just for middle-layer debugging purposes. I want to do all of my validation clientside; none serverside. However, going to be tough if I can't get my god damn form to submit. I've been puzzled by this for close to 36 hours straight. I can't see, and I'm going to get some rest and hope that there is some useful insight on my problem when I return. html form: Code: <form id="f1" name="form1" onsubmit="validate_form(this); return false;" action="register" method="post"> <table cellspacing="5" style="border: 2px solid black;"> <tr> <td valign="top"> <table cellspacing="5"> <tr> <td>*First name</td> <td align="right"><span id="valid_one"></span></td> <td><input type="text" style="width: 320px;" id="fn" name="fn" onBlur="validate_one();"></td> </tr> <tr> <td align="left">*Last name</td> <td align="right"><span id="valid_two"></span></td> <td><input type="text" style="width: 320px;" id="ln" name="ln" onBlur="validate_two();"></td> </tr> <tr> <td align="left">*Email address</td> <td align="right"><span id="result"></span></td> <td><input type="text" style="width: 320px;" id="mailfield" name="email" onBlur="startRequest();"></td> </tr> <tr> <td align="left">*Phone number</td> <td align="right"><span id="valid_three"></span></td> <td><input type="text" style="width: 320px;" id="pn" name="pn" onBlur="validate_three();"></td> </tr> <tr> <td align="left">*City/Town</td> <td align="right"><span id="valid_four"></span></td> <td><input type="text" style="width: 320px;" id="c" name="c" onBlur="validate_four();"></td> </tr> <tr> <td></td> <td></td> <td> <select name="s"> <option value="AL">Alabama <option value="AK">Alaska <option value="AZ">Arizona <option value="AR">Arkansas <option value="CA">California <option value="CO">Colorado <option value="CT">Connecticut <option value="DE">Delaware <option value="FL">Florida <option value="GA">Georgia <option value="HI">Hawaii <option value="ID">Idaho <option value="IL">Illinois <option value="IN">Indiana <option value="IA">Iowa <option value="KS">Kansas <option value="KY">Kentucky <option value="LA">Louisiana <option value="ME">Maine <option value="MD">Maryland <option value="MA">Massachusetts <option value="MI">Michigan <option value="MN">Minnesota <option value="MS">Mississippi <option value="MO">Missouri <option value="MT">Montana <option value="NE">Nebraska <option value="NV">Nevada <option value="NH">New Hampshire <option value="NJ">New Jersey <option value="NM">New Mexico <option value="NY">New York <option value="MC">North Carolina <option value="ND">North Dakota <option value="OH">Ohio <option value="OK">Oklahoma <option value="OR">Oregon <option value="PA">Pennsylvania <option value="RI">Rhode Island <option value="SC">South Carolina <option value="SD">South Dakota <option value="TN">Tennessee <option value="TX">Texas <option value="UT">Utah <option value="VT">Vermont <option value="VA">Virginia <option value="WA">Washington <option value="WV">West Virginia <option value="WI">Wisconsin <option value="WY">Wyoming </select> </td> </tr> <tr> <td> <br> </td> </tr> <tr> <td></td> <td></td> <td><span id="error"></span></td> </tr> <tr> <td valign="top">*Anti-Spam Verification</td> <td></td> <td id="reCaptcha"></td> </tr> </table> </td> <td valign="top"> <table cellspacing="5"> <tr> <td align="left">*Affiliation</td> <td align="right"><span id="valid_five"></span></td> <td><input type="text" style="width: 320px;" id="affl" name="affl" onBlur="validate_five();"></td> </tr> <tr> <td align="left">*Research Area:</td> <td align="right"><span id="valid_six"></span></td> <td><input type="text" style="width: 320px;" id="ra" name="ra" onBlur="validate_six();"></td> </tr> <tr> <td valign="top" align="left">*Research Overview</td> <td align="right"><span id="valid_seven"></span></td> <td><textarea cols="38" rows="6" id="ro" name="ro" onKeyDown="limitText(this.form.ro,this.form.countdown,500)" onKeyUp="limitText(this.form.ro,this.form.countdown,500)" onBlur="validate_seven();"></textarea></td> </tr> <tr> <td></td> <td></td> <td><font size="1">You have <input readonly type="text" name="countdown" size="1" value="500"> characters remaining.</font></td> </tr> <tr> <td align="left">*Talk Availability</td> <td></td> <td> <input type="radio" name="ta" value="In person">In person <input type="radio" name="ta" value="Online">Online <input type="radio" name="ta" value="Both" checked>Both </td> </tr> <tr> <td align="left" valign="top">Links</td> <td></td> <td> <table id="linkTable" border="0"> <td><input type="text" style="width: 320px;" name="link"></td> <td><div id="result"></div></td> </table> </td> <td align="left" valign="top"><input type="button" value="Add Link" onclick="addLink('linkTable')"></td> </tr> <tr> <td></td> <td><span style="color: red;"></span></td> </tr> </table> </td> </tr> </table> <br /> <input type="submit" id="submit" name="submit" value="Submit Form"> </form> Javascript file: Code: /* * script.js - ajax and table functions */ var xmlHttp; // global instance of XMLHttpRequest var xmlHttp2; // second for captcha functions var validAjax = new Boolean(); var validCaptcha = new Boolean(); var valid_one = new Boolean(); var valid_two = new Boolean(); var valid_three = new Boolean(); var valid_four = new Boolean(); var valid_five = new Boolean(); var valid_six = new Boolean(); var valid_seven = new Boolean(); function init() { showRecaptcha('reCaptcha'); // Separate booleans for AJAX funcs validAjax = false; validCaptcha = false; // Booleanse for fields that don't require servlet validation valid_one = false; valid_two = false; valid_three = false; valid_four = false; valid_five = false; valid_six = false; valid_seven = false; } function showRecaptcha(element) { Recaptcha.create("6Le1a8ESAAAAAGtxX0miZ2bMg0Wymltnth7IG-Mj", element, {theme: "red", callback: Recaptcha.focus_response_field}); } function validate_form() { if (valid_one && valid_two && valid_three && valid_four && validEmail) { startCaptchaRequest(); if (validCaptcha) { return true; } } else { alert("Submission contains errors. Please fill out all required fields before submitting."); return false; } } function validate_one() { if (document.getElementById("fn").value == 0) { valid_one = false; document.getElementById("valid_one").innerHTML = "No"; } else { valid_one = true; document.getElementById("valid_one").innerHTML = ""; } } function validate_two() { if (document.getElementById("ln").value == 0) { valid_two = false; document.getElementById("valid_two").innerHTML = "No"; } else { valid_two = true; document.getElementById("valid_two").innerHTML = ""; } } function validate_three() { if (document.getElementById("pn").value == 0) { valid_three = false; document.getElementById("valid_three").innerHTML = "No"; } else { valid_three = true; document.getElementById("valid_three").innerHTML = ""; } } function validate_four() { if (document.getElementById("c").value == 0) { valid_four = false; document.getElementById("valid_four").innerHTML = "No"; } else { valid_four = true; document.getElementById("valid_four").innerHTML = ""; } } function validate_five() { if (document.getElementById("affl").value == 0) { valid_five = false; document.getElementById("valid_five").innerHTML = "No"; } else { valid_five = true; document.getElementById("valid_five").innerHTML = ""; } } // //function validate_six() { // if (document.getElementById("ra").value == 0) { // valid_six = false; // document.getElementById("valid_six").innerHTML = "No"; // } // else { // valid_six = true; // document.getElementById("valid_six").innerHTML = ""; // } //} // //function validate_seven() { // if (document.getElementById("ro").value == 0) { // valid_seven = false; // document.getElementById("valid_seven").innerHTML = "No"; // } // else { // valid_seven = true; // document.getElementById("valid_seven").innerHTML = ""; // } //} function addLink(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = "link" + rowCount; element1.style.width = "320px"; cell.appendChild(element1); } function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } function createXmlHttpRequest() { if(window.ActiveXObject) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } } function startRequest() { createXmlHttpRequest(); var param1 = document.getElementById('mailfield').value; if (param1 == "") { validEmail = false; document.getElementById("result").innerHTML = "Blank"; } else { xmlHttp.open("GET", "http://localhost:1979/PolarSpeakers/servlet/mailCheck.do?e=" + param1, true) xmlHttp.onreadystatechange = handleStateChange; xmlHttp.send(null); } } function handleStateChange() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var message = xmlHttp.responseXML .getElementsByTagName("valid")[0] .childNodes[0].nodeValue; if (message == "Unregistered") { validEmail = true; document.getElementById("result").style.color = "green"; } else { validEmail = false; document.getElementById("result").style.color = "red"; } document.getElementById("result").innerHTML = message; } else { alert("Error checking e-mail address - " + xmlHttp.status + " : " + xmlHttp.statusText); } } } function createCaptchaRequest() { if(window.ActiveXObject) { xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp2=new XMLHttpRequest(); } } function startCaptchaRequest() { alert('made it to captcha requeswt'); createCaptchaRequest(); var param1 = Recaptcha.get_challenge(); var param2 = Recaptcha.get_response(); xmlHttp2.open("POST", "http://localhost:1979/PolarSpeakers/servlet/captchaCheck.do?c=" + param1 + "&r=" + param2, true) xmlHttp2.onreadystatechange = handleStateChangeCaptcha; xmlHttp2.send(null); } function handleStateChangeCaptcha() { if(xmlHttp2.readyState==4) { if(xmlHttp2.status==200) { var message = xmlHttp2.responseXML .getElementsByTagName("result")[0] .childNodes[0].nodeValue; if (message == "Valid") { alert("captcha valid"); validCaptcha = true; } else { document.getElementById("error").innerHTML = message; validCaptcha = false; } } else { alert("Error checking captcha validity - " + xmlHttp2.status + " : " + xmlHttp2.statusText); } } } Hi guys, Been stuck for a few days with this scenario. Any help? The alert box appears on an error. But the submitting won't stop. The details are submitted and the form is processed. Any help is greatly appreciated... Code: <html> <head> <script type="text/javascript" src="email_helper/jscripts/tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "textareas", theme : "simple" }); </script> <script language="javascript"> function MM_openBrWindow(theURL,winName,features) { window.open(theURL,winName,features); } function err_check(){ var email = document.getElementById('to_email').value; if(email.length==0){ alert('Please Enter Email Address'); return false; } var AtPos = email.indexOf("@") var StopPos = email.lastIndexOf(".") if (AtPos == -1 || StopPos == -1) { alert("Please Enter Valid Email Address"); document.getElementById('email').focus(); return false; } email = document.getElementById('cc_email').value; if(email.length != 0){ var AtPos = email.indexOf("@") var StopPos = email.lastIndexOf(".") if (AtPos == -1 || StopPos == -1) { alert("Please Enter Valid Email Address"); document.getElementById('email').focus(); return false; } } var answer = confirm ("Send E-Mail?"); if (!answer){ return false; } } </script> <!-- /TinyMCE --> <style type="text/css"> body, table, td, th{ background-color:#CCCCCC; font-family: Arial; font-size:14px; } .que{ font-weight:bold; } </style> </head> <body> <form method="post" enctype="multipart/form-data"> <?php include 'library/database.php'; include 'library/opendb.php'; $query = mysql_query("SELECT email,contact,mobile FROM users WHERE user_id='$uid'") or die(mysql_error()); $row = mysql_fetch_row($query); $from_email = $row[0]; $from_person = $row[1]; $from_mobile = $row[2]; $query = mysql_query("SELECT customer_id FROM campaign_summary WHERE camp_id='$camp_id'") or die(mysql_error()); $row = mysql_fetch_row($query); $cusid = $row[0]; $query = mysql_query("SELECT email FROM client_info WHERE comp_id='$cusid'") or die(mysql_error()); $row = mysql_fetch_row($query); $toer = $row[0]; include 'library/closedb.php'; ?> <table width="100%" border="0"> <tr><td rowspan="4"><input type="submit" name="send_email" id="send_email" style="height:50px; width:100px;" value="SEND" onClick="return err_check();" /></td><td><span class="que">From : </span></td><td colspan="3"><?php echo $from_email; ?><input type="hidden" name="from_mail" id="from_mail" /><input type="hidden" name="camp_id" id="camp_id" value="<?php echo $camp_id;?>"/></td></tr> <tr><td><span class="que">To : </span></td><td colspan="3"><input name="to_email" id="to_email" style="width:250px;" value="<?php echo $toer;?>"/></td></tr> <tr><td><span class="que">CC : </span></td><td colspan="3"><input name="cc_email" id="cc_email" style="width:250px;"/></td></tr> <tr><td><span class="que">Subject : </span></td><td colspan="3"><input style="width:300px;" name="subject" id="subject" /></td></tr> <tr><td rowspan="1" colspan="2"> </td><td><input type="checkbox" name="ori_pdf" id="ori_pdf" checked /> PDF Quotation</td><td> </td><td> </td></tr><tr><td colspan="2"><span class="que">Credit Application</span></td><td><input type="checkbox" name="corporate" id="corporate"/>Corporate</td><td><input type="checkbox" name="individual" id="individual" />Individual</td><td><input type="checkbox" name="cash" id="cash" />Cash Account</td> </tr> <tr> <td colspan="2" rowspan="3"></td><td><input type="checkbox" name="tabloid" id="tabloid" />Tabloid Example</td> <td><input type="checkbox" name="broadsheet" id="broadsheet" />Broadsheet Example</td></tr> <tr><td><input type="checkbox" name="colmt" id="colmt" />Column Sizes Tabloid</td> <td><input type="checkbox" name="colmb" id="colmb" />Column Sizes Broadsheet</td></tr> <tr><td><input type="checkbox" name="maps" id="maps" />Maps / Distribution</td><td colspan="2" align="right">External Attachments <input id="upload_file" name="upload_file" type="file"/> </td></tr> <tr><td colspan="2"><span class="que">Message :</span></td><td colspan="3"> <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 100%"> <?php echo "<br><br><br>" . $from_person . "<br>" . $from_mobile; ?> </textarea> </td></tr> </table> </form> </body> </html> I'm a long time lurker on here just barely created an account to ask this question. I work at a call center, and we use different webapps to fill out tickets. One I've used for a long time allows dynamically updating forms with javascript. I have a whole bunch of bookmarked javascript injections like: Code: javascript:if((top.detail.findObj('X31').value="Inquiry")!=""); That code will fill out most everything in that ticket, leaving me to fill in the details. I have one of those for all of the most common tickets, and can create and finish a ticket in less than 30 seconds when it takes others 3-4 minutes. I recently switched to a different system and I'm having trouble with my code. I'm a noob at javascript for sure, but I'm not new to programming. Anyway any pointers would be nice. The system we use doesn't allow me to see the source... I'm not sure how to explain it. It loads everything in a frame. In chrome I can right click then inspect element and get the ID but it the above javascript doesn't work. Examples: Old app source ex: Code: <label for="X31">Category:</label> was all i needed new app(before the body code is just code for the login form, etc): Code: <body onLoad="startit()" onUnload="stopit()"> </body> <div align="center" valign="center" id="LoadMessageID" style="position: relative; top:40%; color:#0069A5; font-size:100% ;"> <img src="/arsys/shared/images/Progress_NonModal-circle.gif" alt="wait image"/> Loading... </div> </html> formloader: Code: <form name="form1" action="/arsys/forms/bmcitsm/HPD:Incident+Management+Console/Default+User+View+(Support)/?cacheid=a22a36a8" method="post"> example of inspect element in chrome (something i want to change with javascript injection): Code: <input id="arid301602600" type="text" class="text " style="top:0; left:0; width:225; height:21;" readonly=""> I have the following form function goto(form) { var index=form.select.selectedIndex if (form.select.options[index].value != "0") { location=form.select.options[index].value;}} //--> </script> </p> <form name="form1"> <p><select onchange="goto(this.form)" name="select" style="font-size: 10pt;"> <option>----- Choose Wholesaler ------ </option><option value="travl.com.au/social-passport-profiles.html">A1 Classic Holidays </option><option value="web_development.htm">AAT Kings </option><option value="html_codes.htm">Abercrombie & Kent </option><option value="html_codes_chart.htm">Adventure Associates </option><option value="javascript_codes.htm">Adventure Destinations </option><option value="index.htm">Adventure World </option><option value="web_development.htm">African Wildlife Safaris </option><option value="html_codes.htm">Albatross Travel Group </option><option value="html_codes_chart.htm">Amazing Vacations </option><option value="javascript_codes.htm">Asiaquest Tours </option><option value="216_color_chart.htm">ATI Tours </option><option value="index.htm">Australian Pacific Tours </option><option value="web_development.htm">Beachcomber Tours </option><option value="html_codes.htm">Bench International </option><option value="html_codes_chart.htm">Bentours </option><option value="javascript_codes.htm">Beyond Travel Group </option><option value="216_color_chart.htm">Broome & The Kimberley Holidays </option><option value="index.htm">Bunnik Tours </option><option value="web_development.htm">Cathay Pacific Holidays </option><option value="html_codes.htm">CBT Holidays </option><option value="html_codes_chart.htm">Chat Tours </option><option value="javascript_codes.htm">CIT Holidays </option><option value="216_color_chart.htm">Club Med Australia </option><option value="216_color_chart.htm">Contiki Holidays for 18-35's </option><option value="216_color_chart.htm">Contours Travel </option><option value="index.htm">Cosmos </option><option value="web_development.htm">Creative Holidays </option><option value="html_codes.htm">Destination Canada </option><option value="html_codes_chart.htm">Eastern Europe Travel </option><option value="javascript_codes.htm">Elegant Resorts & Villas </option><option value="216_color_chart.htm">Explore Holidays </option><option value="index.htm">Freestyle Holidays </option><option value="web_development.htm">French Travel Connection </option><option value="html_codes.htm">Garuda Orient Holidays </option><option value="html_codes_chart.htm">Global Getaway </option><option value="javascript_codes.htm">Globus </option><option value="216_color_chart.htm">Go See Touring </option><option value="216_color_chart.htm">Greece & Mediterranean Travel </option><option value="216_color_chart.htm">Handpicked Holidays </option><option value="index.htm">Helen Wong's Tours </option><option value="web_development.htm">HIS Travel </option><option value="html_codes.htm">Holidays On Location </option><option value="html_codes_chart.htm">Honeymoon Worldwide Holidays </option><option value="javascript_codes.htm">Ibertours </option><option value="216_color_chart.htm">Icon Holidays </option><option value="index.htm">Inca Tours </option><option value="web_development.htm">Insight Vacations </option><option value="html_codes.htm">Intrepid Travel </option><option value="html_codes_chart.htm">Japan Experience Tours </option><option value="javascript_codes.htm">JTB Australia </option><option value="216_color_chart.htm">Kumuka Worldwide </option><option value="216_color_chart.htm">Made Easy Tours </option><option value="216_color_chart.htm">Nordic Travel </option><option value="index.htm">Northern Gateway </option><option value="web_development.htm">Orient Pacific Holidays </option><option value="html_codes.htm">Peregrine Adventures </option><option value="html_codes_chart.htm">Qantas Holidays </option><option value="javascript_codes.htm">Rosie Holidays </option><option value="216_color_chart.htm">Royal Orchid Holidays </option><option value="index.htm">Sachi Tours </option><option value="web_development.htm">Scenic Tours </option><option value="html_codes.htm">Selective Tours </option><option value="html_codes_chart.htm">Singapore Airlines Holidays </option><option value="javascript_codes.htm">Southern Italian Tours </option><option value="216_color_chart.htm">Sportsnet Holidays </option><option value="216_color_chart.htm">Sun Island Tours </option><option value="216_color_chart.htm">Sundowners Overland </option><option value="index.htm">Talpacific Holidays </option><option value="web_development.htm">Tasmania's Temptation Holidays </option><option value="html_codes.htm">Tempo Holidays </option><option value="html_codes_chart.htm">Temptation Tours </option><option value="javascript_codes.htm">Territory Discoveries </option><option value="216_color_chart.htm">The Imaginative Traveller </option><option value="index.htm">Trafalgar Tours </option><option value="web_development.htm">Travel IndoChina </option><option value="html_codes.htm">Travel Makers </option><option value="html_codes_chart.htm">United Vacations </option><option value="javascript_codes.htm">Venture Holidays </option><option value="216_color_chart.htm">Wendy Wu Tours </option><option value="216_color_chart.htm">Wildlife Safari Australia </option></select> </p></form> and i would like to make some of the option values auto redirect to an external website address. It seems this form code I have only allows for page redirects within my own website. I would be grateful if anybody could assist with how I can make some changes to this form to allow me to do this. Thank you in advance. Is there a way to make it so JavaScript can pre-set a FORM value? Something like this: Code: <?php $country = $_SESSION['country']; ?> <SCRIPT type="text/javascript"> function SomeFunctionForm() { document.forms["form"]["country"].value=="<?php echo $country; ?>) { } } </SCRIPT> <FORM> <SELECT name="country"> <OPTION>Afghanistan</OPTION> <OPTION>Albania</OPTION> <OPTION>Algeria</OPTION> </SELECT> </FORM> I can't just drop the PHP Code: <?php $country = $_SESSION['country']; ?> into the SELECT value because it will brake the alphabetical listing, which is why I am wondering if JavaScript can do it this way, as this way wouldn't brake the alphabetical listing? Hi there I have created a php form (which i inserted into wordpress site) www.lookinside.co.za/wp - under "Conferences" tab... This form is working well, I just have a couple of changes which I would like to make, and am not sure how. if someone could perhaps maybe even help with one of the items on here I would be extremely grateful please :-) Changes: 1. is it possible to have a "print" button to appear on the page that comes up after submitting the quote? 2. Can we insert a "date" field possibly with a calendar popup to select a date for the conference? 3. Can images and other text appear on the "after submission" page? that will then also print, ie: info about the conference rooms, images? 4. Can the no. of people box be shorter in length? (the outline of the box) 5. when the submitted form is emailed through / and viewed, is it possible to include the title of the duration? ie at the moment it shows as: "Duration: R200", can we make it "Duration: Full Day - R200" or something? THe same for the "menu selection" php: PHP Code: <?php if(isset($_POST['action']) && $_POST['action'] == "submit_post"): ?> <?php $string = "Customer Name: ". $_POST['name']. "\n"; $string .= "Company: ". $_POST['company']. "\n"; $string .= "Conference Name: ". $_POST['field-36b58f8c5142ff3']. "\n"; $string .= "Telephone Number: ". $_POST['field-7c496d0fb21abfd']. "\n"; $string .= "Duration: ". $_POST['field-385963a5c9a4ef9']. "\n"; $string .= "Number of People: ". $_POST['field-5af722f60ee2f9b']. "\n"; $string .= "Menu: ". $_POST['menu']. "\n"; $string .= "Overhead Projector: ". $_POST['field-73cf21adf8b52d5']. "\n"; $string .= "Email: ". $_POST['field-3f92f5a7876cd50']. "\n"; $string .= "Sub Total: ". $_POST['totalcost']. "\n"; print "<p>". nl2br($string) ."</p>"; $to = $_POST['field-3f92f5a7876cd50'] . ", "; //This is the users email address $to .= "melissafleetwood@yahoo.com" . ", "; //Put your first email here $to .= "melissa@run-time.co.za"; //Put your second email here $subject = "Reciept confirmation"; $headers = "From: melissa@lookinside.co.za"; mail($to, $subject, $string, $headers); ?> <?php else: ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Contact Form Test</title> </head> <body> <form action="" method="post"> <div> <input type="hidden" name="action" id="acctid" value="submit_post" /> </div> <table cellspacing="5" cellpadding="5" border="0"> <td valign="top"> <strong>Name of Contact Person:</strong> </td> <td valign="top"> <input type="text" name="name" id="name" size="40" value="" /> </td> </tr> <tr> <td valign="top"> <strong>Company:</strong> </td> <td valign="top"> <input type="text" name="company" id="company" size="40" value="" /> </td> </tr> <tr> <td valign="top"> <strong>Official Name Of Conference</strong> </td> <td valign="top"> <input type="text" name="field-36b58f8c5142ff3" id="field-36b58f8c5142ff3" size="40" value="" /> </td> </tr> <tr> <td valign="top"> <strong>Tel No Of Contact Person:</strong> </td> <td valign="top"> <input type="text" name="field-7c496d0fb21abfd" id="field-7c496d0fb21abfd" size="40" value="" /> </td> </tr> <tr> <td valign="top"> <strong>Duration:</strong> </td> <td valign="top"> <input type="radio" name="field-385963a5c9a4ef9" id="game4" value="220.00" onclick="UpdateCost()"> Full Day R220.00<br/> <input type="radio" name="field-385963a5c9a4ef9" id="game5" value="200.00" onclick="UpdateCost()"> Half Day R200.00<br/> </td> </tr> <tr> <td valign="top"> <strong>No Of People</strong> </td> <td valign="top"> <input type="text" name="field-5af722f60ee2f9b" id="field-5af722f60ee2f9b" size="40" value="" onchange="UpdateCost()"/> </td> </tr> <tr> <td valign="top"> <strong>Please select a menu:</strong> </td> <td valign="top"> <input type="radio" name="menu" id='game0' value="60.00" onclick="UpdateCost()">Menu A (60.00)<br> <input type="radio" name="menu" id='game1' value="90.00" onclick="UpdateCost()">Menu B (90.00)<br> <input type="radio" name="menu" id='game2' value="120.00" onclick="UpdateCost()">Menu C (120.00)<br> <input type="radio" name="menu" id='game3' value="150.00" onclick="UpdateCost()">Braai/Barbeque (150.00)<br> </td> </tr> <tr> <td valign="top"> <strong>Overhead Projector</strong> </td> <td valign="top"> <input type="checkbox" name="field-73cf21adf8b52d5" id="game6" value="650.00" onclick="UpdateCost()">R650.00 <br/> </td> </tr> <tr> <td valign="top"> <strong>Email of Contact Person: </strong> </td> <td valign="top"> <input type="text" name="field-3f92f5a7876cd50" id="field-3f92f5a7876cd50" size="40" value="" /> </td> <tr> <td valign="top"> <strong>Sub Total: </strong> </td> <td valigh="top"> <input type="text" id="totalcost" name="totalcost" size="40" value=""> </td> <tr> <td colspan="2" align="center"> <input type="submit" value=" Submit Form " /> </td> </tr> </form> JAVASCRIPT Code: <script type="text/javascript"> function UpdateCost() { var sum = 0; var gn, elem, totalAmmount, peopleNum; for (i=0; i<7; i++) { gn = 'game'+i; if(gn != 'game6'){ elem = document.getElementById(gn); if (elem.checked == true) { sum += Number(elem.value); } } peopleNum = document.getElementById('field-5af722f60ee2f9b').value; if(isNaN(peopleNum ) || peopleNum==''){ totalAmmount = sum; } else{ totalAmmount = sum * peopleNum; } } if(document.getElementById('game6').checked == true) { totalAmmount += Number(document.getElementById('game6').value); } document.getElementById('totalcost').value = totalAmmount.toFixed(2); } </script> <script type="text/javascript"> var value=""; var numPeople=document.getElementById("field-5af722f60ee2f9b") numPeople.onkeydown=function(e){ value = this.value + e; } numPeople.onkeyup=function(e) { this.value=this.value.replace(/[^\d]/,''); if(this.value != value) { UpdateCost(); } } </script> </body> </html> <?php endif; ?> Javascript: /* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com Created by: Jay Rumsey | http://www.nova.edu/~rumsey/ */ function UpdateCost() { var sum = 0; var gn, elem, totalAmmount, peopleNum; for (i=0; i<7; i++) { gn = 'game'+i; if(gn != 'game6'){ elem = document.getElementById(gn); if (elem.checked == true) { sum += Number(elem.value); } } peopleNum = document.getElementById('field-5af722f60ee2f9b').value; if(isNaN(peopleNum ) || peopleNum==''){ totalAmmount = sum; } else{ totalAmmount = sum * peopleNum; } } if(document.getElementById('game6').checked == true) { totalAmmount += Number(document.getElementById('game6').value); } document.getElementById('totalcost').value = totalAmmount.toFixed(2); } Thank you so much Hello, I've used the concept from this website to build a form. http://www.enviromark.ca/english/quoteform.html Notice how the second drop down options change depending on what option is selected in the first drop down. Here's the Javascript Code: var Option1_Array = new Array("Choose a version", "1", "2"); var Option2_Array = new Array("Choose a version", "3", "4"); function program(objProgram) { var objVersion = objProgram.form.Version; var selectedArray = window[objProgram.options[objProgram.selectedIndex].value.replace(/\s/g,'') + "_Array"]; objVersion.options.length = 0; for (var i=0; i < selectedArray.length; i++) { objVersion.options[i]=new Option(selectedArray[i], selectedArray[i].replace(/->\s/g, "")); } } Here's the HTML Code: <form> <select name="Program" onChange="program(this)"> <option value="Start">Please choose a program</option> <option value=Null>---------------------------------------></option> <option value="Option1">1</option> <option value="Option2">2</option> </select> <select name="Version" onChange=""> </select> </form> Now, this code works perfectly, and does exactly what I want it to. BUT I'd like to add more fields that accomplish the same thing. For example choose option1 --> version 2 --> type 3 --> thing 5 Now, in order to do this I believe you need to generate a 'value = "a_value"' in the generated html option and select fields. That way, all you need to do is make separate functions for each level and the function can call the 'value' html attribute to handle each <select> depending on its declared value. If this is the best way (it sounds a little sketchy to me) then any help would be great. Or, if you can add on more child selection options within one function. Thanks, -Matthew how do i write a javascript code for a form that compromises of 3 text boxes and 2 buttons.the text boxes ask the user for: -a start number -an end number -and the number to multiply by -the 1st button "times table" ,which when clicked calls a function to calculate the times table and outputs the result in the textarea provided. -the second button is a "reset" button which when clicked clears the form restoring its original state. I have problem with my javascript form validation... Validation works only on last question and I can't understand why it doesn't work on other questions.. Html code : 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> <script type="text/javascript" src="script.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Questionaire</title> <link href="oneColLiqCtrHdr19.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- body { background-color: #FFF; background-image: url(images/aa.jpg); } --> </style></head> <body class="oneColLiqCtrHdr"> <div id="container"> <div id="header"> <h1> </h1></div> <!-- forms --> <form action="http://projects.knord.dk/interaction/saveforminfo.aspx" method="post" onsubmit="return checkform(this);" > <input type="hidden" name="surveyid" value="knjuku2" /> <input type="hidden" name="usecookie" value="true" /> <input type="hidden" name="landingpage" value="h---.html" /> <p align="center"><b>This survey was made for Business Academy Copenhagen North project not for FDIM.</b></p> <p> <b>Please enter your personal information</b> </p> <p><b>Your Occupation:</b> <input type="text" name="occupation" /> </p> <p><b>Age Group:</b> <select name="age"> <option value="under 18">less then 18</option> <option value="18-25">18-25</option> <option value="26-35">26-35</option> <option value="over 35">more then 35</option> </select> </p> <p><b>Status:</b> <select name="status"> <option value="single">Single</option> <option value="single with children">Single with children</option> <option value="in relationship">In relationship</option> <option value="married">Married</option> <option value="divorced">Divorced</option> </select> </p> <p><b>Gender:</b> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="female" /> Female </p> <p><b>Do you have a job?</b> <input type="radio" name="job" value="yes" />Yes <input type="radio" name="job" value="no" />No </p> <p> </p> <p> <!-- 1 vopros --> </p> <p><b>1. Why do You use online social media?</b> </p> <p> <input type="radio" name="bla" value="To chat with friends" /> To chat with friends<br></br> <input type="radio" name="bla" value="To read news" /> To read news<br></br> <input type="radio" name="bla" value="To write blogs" /> To write blogs<br></br> <input type="radio" name="bla" value="Other" /> Other<br></br> </p> <p> <!-- 2 vopros --> <b>2. What online social media do You use more often?</b> </p> <p> </p> <p> <select name="more"> <option value="MySpace">MySpace</option> <option value="Twitter">Twitter</option> <option value="Facebook">Facebook</option> <option value="LinkedIn">LinkedIn</option> </select> </p> <p> </p> <!-- 3 vopros --> <b>3. When do You use it?</b> <p> <input type="radio" name="use" value="1" /> At home<br></br> <input type="radio" name="use" value="2" /> At work<br></br> <input type="radio" name="use" value="3" /> At school<br></br> <input type="radio" name="iuse" value="4" /> In the bus/train<br></br> <input type="radio" name="use" value="5" /> Other<br></br> </p> <p><b>4. How much hours approximately do You spend on social media?</b> </p> <select name="hours"> <option value="less than 2 hours">less than 2 hours a day</option> <option value="2-4 hours">2-4 hours a day</option> <option value="4-8 hours">4-8 hours a day</option> <option value="8-12 hours">8-12 hours a day</option> <option value="more than 12 hours">more than 12 hours a day</option> </select> <p> </p> <p> <!-- 5 vopros --> <b>5. Do You use social media often?</b></p> <p> <input type="radio" name="often" value="Yes" /> Yes <input type="radio" name="often" value="No" /> No <!-- 6 vopros --> </p> <p><b>6. Social Media website to which You usually upload</b></p> <p> <input type="radio" name="upload" value="Youtube" /> Youtube<br></br> <input type="radio" name="upload" value="Flickr" /> Flickr<br></br> <input type="radio" name="upload" value="Photobucket" /> Photobucket<br></br> <input type="radio" name="upload" value="Slideshare" /> Slideshare<br></br> <input type="radio" name="upload" value="Other" /> Other </p> <!-- 7 vopros --> <b>7. Where do You chat with Your friends</b> <select name="chatting"> <option value="Msn">Msn</option> <option value="Skype">Skype</option> <option value="Yahoo!">Yahoo!</option> <option value="Other">Other</option> </select> <p> </p> <!-- 8 vopros --> <b>8. You use social media for</b> <select name="using"> <option value="Personal reasons">Personal reasons</option> <option value="Professional reasons">Professional reasons</option> <option value="Don't use it">Don't use it</option> </select> <p> </p> <p> <!-- 9 vopros --> <b>9. You prefer to obtain the information You need at</b> <select name="information"> <option value="Yahoo!">Yahoo!</option> <option value="Google">Google</option> <option value="Wikipedia">Wikipedia</option> <option value="Ask">Ask</option> <option value="Other">Other</option> </select> </p> <!-- 10 vopros --> <b>10. What do You prefer to do being online</b>? <select id="drop" name="online"> <option value="Read blogs">Read blogs</option> <option value="Chat with friends">Chat with friends</option> <option value="Watch videos">Watch videos</option> <option value="Read news">Read news</option> <option value="Other">Other</option> </select> <!-- konec voprosov --> <!-- button-submit --> <p align="center"> <input type="submit" value="Submit" /> </p> </form> <!-- end #container --> </div> </body> </html> Javascript validation Code: //Javascript Document function checkform ( form ) { if (form.occupation.value == "") { alert( "Please enter your occupation." ); form.occupation.focus(); return false ; } return true ; } function checkform(f) { for (var i=0; i<f.elements("gender").length; i++) { var radio = f.elements("gender")[i]; if (radio.checked) { return true; } } // no checked radio button found window.alert("Choose your gender!"); f.elements("gender")[0].focus(); return false; } function checkform(f) { for (var i=0; i<f.elements("job").length; i++) { var radio = f.elements("job")[i]; if (radio.checked) { return true; } } // no checked radio button found window.alert("Choose if you have a job!"); f.elements("job")[0].focus(); return false; } function checkform(f) { for (var i=0; i<f.elements("bla").length; i++) { var radio = f.elements("bla")[i]; if (radio.checked) { return true; } } // no checked radio button found window.alert("Answer question number 1"); f.elements("bla")[0].focus(); return false; } function checkform(f) { for (var i=0; i<f.elements("use").length; i++) { var radio = f.elements("use")[i]; if (radio.checked) { return true; } } // no checked radio button found window.alert("Answer question number 3!"); f.elements("use")[0].focus(); return false; } function checkform(f) { for (var i=0; i<f.elements("often").length; i++) { var radio = f.elements("often")[i]; if (radio.checked) { return true; } } // no checked radio button found window.alert("Answer question number 5!"); f.elements("often")[0].focus(); return false; } function checkform(f) { for (var i=0; i<f.elements("upload").length; i++) { var radio = f.elements("upload")[i]; if (radio.checked) { return true; } } // no checked radio button found window.alert("Answer question number 6!"); f.elements("upload")[0].focus(); return false; } Where is my mistake? And how to solve it to make javascript validation work properly? Hi guys I am trying to make my first xhtml form using javascript but am having some problems. I have 4 text boxes on the form and two buttons: Car Year Password Re-enter Password *Buttons* Reset and Submit query I want an alert to pop up when the submit button is pressed if any of the fields are not filled in. I have written the javascript for the events but for some reason it is not picking up the car or year fields. When the submit button is pressed it only prompts for a password (if not filled in). I have looked over the code but I cant see where i'm going wrong. I have added the xhtml code with the external javascript pages at the bottom. Any help would be much appreciated. Fatbot Code: <?xml version="1.0" encoding="UTF-8"?> <!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>Test</title> <!--Scripts for submit button event handlers--> <script type="text/javascript" src="submit_car.js"></script> <script type="text/javascript" src="submit_year.js"></script> <script type="text/javascript" src="submit_pass.js"></script> </head> <body> <form id="myForm" action=""> <p> <!--Input car name--> <label>Car<br /> <input type="text" id="car" size="30" /> </label> <br /> <br /> <!--Register car name event handlers--> <script type="text/javascript" src="car_check.js"></script> <!--Input year--> <label>Year<br /> <input type="text" id="year" size="4" /> </label> <br /> <br /> <!--Register year event handlers--> <script type="text/javascript" src="year_check.js"></script> <!-- Password entry and re-entry --> <label>Password<br /> <input type="password" id="first" size="10" /> </label> <br /> <br /> <label>Re-enter Password<br /> <input type="password" id="second" size="10" /> </label> <br /> <br /> <!--Register password event handlers--> <script type="text/javascript" src="password_check.js"></script> <input type="reset" name="reset" /> <input type="submit" name="submit" /> </p> </form> </body> </html> //submit_car.js //Event handler function for entering car name function carCheck() { var car = document.getElementById("car"); if (car.value== "") { alert ("Please enter a car name"); return false; } else return true; } //car_check.js //Registers the event handlers for submit_car.js document.getElementById("car").onsubmit = carCheck; document.getElementById("myForm").onsubmit = carCheck; //submit_year.js //Event handler function for entering year function yearCheck() { var year = document.getElementById("year"); if (year.value== "") { alert ("Please enter a year"); return false; } else return true; } //year_check.js //Registers the event handlers for submit_year.js document.getElementById("year").onsubmit = yearCheck; document.getElementById("myForm").onsubmit = yearCheck; //Submit_pass.js //Event handler function for ensuring password entry is correct function passwordCheck() { var first = document.getElementById("first"); var second = document.getElementById("second"); if (first.value== "") { alert ("Please enter a password"); return false; } if (first.value !== second.value) { alert ("The two passwords you entered did not match. \n" + "Please ensure both passwords are identical."); return false; } else return true; } //password_check.js //Registers the event handlers for submit_pass.js document.getElementById("second").onblur = passwordCheck; document.getElementById("myForm").onsubmit = passwordCheck; Okay this is part of an ajax driven shopping cart. the problem is i need to check for 2 different selections that would be for the same payment method. here is the code as it sits now Code: if ( typeof document.checkout.payment[3] != 'undefined'){ if (document.checkout.payment[3].checked == true) { if (document.checkout.cc_owner.value == "" ) {errMsg += 'Please complete or verify the information in the Name on the card field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_number.value == "") { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_cvv2.value == "") { errMsg += 'Please complete or verify the information in the CVC/CVV code field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_phone.value == "") { errMsg += 'Please complete or verify the information in the Card company\'s telephone number field in the \'Payment Method\' section.' + "\n"; } else { myCardNo = document.checkout.cc_number.value; myCardType = document.checkout.surcharge.value; if (!checkCreditCard (myCardNo,myCardType)) { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } } } } } }} } the problem is in the first 2 lines i basically need it to do this, but when i do it like how i need it to be it will not work. it looks like i am doing it incorrectly maybe. firebug gives me an undefined error on the first checked value because it does not exist when i need it to check for the 2 value. Code: if ( typeof document.checkout.payment[3] != 'undefined' || typeof document.checkout.payment[2] != 'undefined'){ if (document.checkout.payment[3].checked == true || document.checkout.payment[2].checked == true) { if (document.checkout.cc_owner.value == "" ) {errMsg += 'Please complete or verify the information in the Name on the card field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_number.value == "") { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_cvv2.value == "") { errMsg += 'Please complete or verify the information in the CVC/CVV code field in the \'Payment Method\' section.' + "\n"; } else { if(document.checkout.cc_phone.value == "") { errMsg += 'Please complete or verify the information in the Card company\'s telephone number field in the \'Payment Method\' section.' + "\n"; } else { myCardNo = document.checkout.cc_number.value; myCardType = document.checkout.surcharge.value; if (!checkCreditCard (myCardNo,myCardType)) { errMsg += 'Please complete or verify the information in the Card Number field in the \'Payment Method\' section.' + "\n"; } } } } } }} } I'm just learning javascript and am editing a calculator form that will calculate square footage and write to a form text field. I have another form filed that I would like to display a number based a series of if else statements. ex: if square footage > 2761 then display 5.0., if square footage > 2521 then display 4.5. etc. Any help would be appreciated. I have posted my the code below. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<HTML> <HEAD> <TITLE>Size Calculator</TITLE> <SCRIPT LANGUAGE="JavaScript"> function CalculateSum(Atext, Btext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); form.Footage.value = A * B; form.Size.value = 21; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.Footage.value = ""; form.Size.value = ""; } // end of JavaScript functions --> </SCRIPT> </HEAD> <BODY> <P><FONT SIZE="+2">Sizing Calculator</FONT></P> <FORM NAME="Calculator" METHOD="post"> <P>House width (ft): <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P> <P>House length (ft): <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P> <P><INPUT TYPE="button" VALUE="Calculate" name="Calculate" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form)"></P> <P><INPUT TYPE="button" VALUE="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></P> <P>Square footage = <INPUT TYPE=TEXT NAME="Footage" SIZE=12></P> <P>Size = <INPUT TYPE=TEXT NAME="Size" SIZE=12></P> </FORM> </BODY> </HTML> I have a form validation script that runs perfect. Now i want to add one more field to the form and want to make some fields "required" but i dont know how to do this. Please help me. I am also attaching the relevant files. Thanks in advance. Fields to add: 1. Social Security Number (Same as Home Telephone but allows 3 digits in 1st field, 2 in 2nd and 4in 3rd field (123)-(12)-(1234)) Fields to make "required" : Social Security Number First Name Last Name The Script Code: var phoneRegEx = /^(?:(?:\(?(?:(?:[246-8](?:(?:[02-8][0-9])|(?:1[02-9])))|(?:3(?:(?:[02-68][0-9])|(?:1[02-9])))|(?:5(?:(?:[02-46-8][0-9])|(?:5[0-46-9])|(?:1[02-9])))|(?:9(?:(?:[02-578][0-9])|(?:1[02-9]))))\)?)(?:[\- ]?)(?:(?:700(?:[\- ]?)(?:(?:[0-35-9][0-9]{3})|(?:4[02-9][0-9]{2})|(?:41[0-35-9][0-9])|(?:414[02-9])))|(?:(?:(?:[23468][02-9][0-9])|(?:[2-9]1[02-9])|(?:5(?:(?:5[0-46-9])|(?:[02346-9][0-9])|(?:1[02-9])))|(?:7(?:(?:[2-9][0-9])|(?:0[1-9])|(?:1[02-9])))|(?:9(?:(?:[0234689][0-9])|(?:1[02-9])|(?:5[1-7])|(?:7[0-5789]))))(?:[\- ]?)(?:[0-9]{4}))))$/; var error // used to store RowNames for errored elements. var isOptRequired = false; function ValidateQuoteRequest(frm) { if(isBrowserCompatible()) { error = new Array(); CheckDropDown('state', 'row_state', frm); CheckDropDown('Month', 'row_date', frm); CheckDropDown('Day', 'row_date', frm); CheckDropDown('Year', 'row_date', frm); CheckDate('Month', 'Day','Year', 'row_date', frm, 'True'); CheckDropDown('Sex', 'row_sex', frm); CheckDropDown('Height_Feet', 'row_Height', frm); CheckDropDown('Height_Inches', 'row_Height', frm); CheckIntegerField('Weight', 'row_Height', frm, 'True'); CheckDropDown('Tobacco', 'row_tobacco', frm); CheckFrequency('Frequency', 'row_tobaccotype', frm, 'True'); CheckPhone('workphone,homephone', 'row_workphone,row_homephone', frm, 'False'); CheckEmail('email', 'row_email', frm, 'False'); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateRequestApplication(frm) { if(isBrowserCompatible()) { error = new Array(); CheckTextField('firstname', 'row_firstname', frm,); CheckTextField('lastname', 'row_lastname', frm); CheckTextField('address', 'row_address', frm); CheckTextField('city', 'row_city', frm); CheckTextField('state', 'row_state', frm); CheckZip('zip', 'row_state', frm, 'True'); CheckPhone('work_phone_number_,home_phone_number_,cell_phone_number_', 'row_work_phone_number_,row_home_phone_number_,row_cell_phone_number_', frm, 'True'); CheckNumericField('work_phone_number_4', 'row_work_phone_number_', frm, 'False'); CheckEmail('email', 'row_email', frm, 'True'); CheckDropDown('premium_quoted', 'row_premium_quoted', frm); CheckRadioButton('Residency', 'row_Residency', frm); CheckRadioButton('spouse_policy', 'row_spouse_policy', frm); CheckSpouseTextField('spouse_first_name', 'row_spouse_first_name', frm); CheckSpouseTextField('spouse_last_name', 'row_spouse_last_name', frm); CheckDropDown('AgentID', 'row_AgentID', frm); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateRBCRequestApplication(frm) { if(isBrowserCompatible()) { error = new Array(); CheckTextField('firstname', 'row_firstname', frm); CheckTextField('lastname', 'row_lastname', frm); CheckTextField('address', 'row_address', frm); CheckTextField('city', 'row_city', frm); CheckTextField('state', 'row_state', frm); CheckZip('zip', 'row_state', frm, 'True'); CheckPhone('work_phone_number_', 'row_work_phone_number_', frm, 'True'); CheckEmail('email', 'row_email', frm, 'True'); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateRBCQuoteRequest(frm) { if(isBrowserCompatible()) { error = new Array(); CheckDropDown('state', 'row_state', frm); CheckDropDown('Sex', 'row_Sex', frm); CheckDate('Month', 'Day','Year', 'row_date', frm, 'True'); CheckDropDown('Amount', 'row_Amount', frm); CheckRadioButton('coverageTerm', 'row_coverageTerm', frm); CheckRadioButton('tobacco', 'row_tobacco', frm); CheckTextField('firstname', 'row_firstname', frm); CheckTextField('lastname', 'row_lastname', frm); CheckPhone('home_phone_number_', 'row_home_phone_number_', frm, 'True'); CheckEmail('email', 'row_email', frm, 'True'); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateHealth(frm) { if(isBrowserCompatible()) { error = new Array(); CheckEmail('Email', 'row_Email', frm, 'True'); CheckZip('ZipCode', 'row_ZipCode', frm, 'True'); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateHome(frm) { if(isBrowserCompatible()) { error = new Array(); CheckEmail('Email', 'row_Email', frm, 'True'); CheckZip('ZipCode', 'row_ZipCode', frm, 'True'); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateLTC(frm) { if(isBrowserCompatible()) { error = new Array(); CheckDropDown('state', 'row_state', frm); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } function ValidateAuto(frm) { if(isBrowserCompatible()) { error = new Array(); CheckZip('zipcode', 'row_zipcode', frm, 'True'); if (error.length > 0) { //turn on error header and scroll page to error header document.getElementById("contentError").style.display = ""; location = '#contentError'; return false; } else { document.getElementById("contentError").style.display = "none"; return true; } } else //browser not compatible { return true; } } //------- function CheckAnnualIncome (ElmtName, RowName, frm,isReq) { if(!frm.elements[ElmtName + '_decline'].checked) CheckNumericField (ElmtName,RowName, frm, isReq); else removeErrorFormatting(ElmtName, RowName, frm); } //------- function CheckTextField (ElmtName, RowName, frm) { if (!frm.elements[ElmtName]) return; if(trim(frm.elements[ElmtName].value) == '') ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } //---- function CheckSpouseTextField (ElmtName, RowName, frm) { if (!frm.elements[ElmtName]) return; for(var i=0;i < frm.spouse_policy.length; i++) { if(frm.spouse_policy[i].checked && frm.spouse_policy[i].value == 'yes') { CheckTextField (ElmtName, RowName, frm); }else{ removeErrorFormatting(ElmtName, RowName, frm); } } } //------ function CheckNumericField(ElmtName, RowName, frm, isReq) { if (frm.elements[ElmtName].value != '' || isReq.toLowerCase() == 'true') { var val = frm.elements[ElmtName].value.replace(/,/g,''); val = val.replace('$', ''); if(parseFloat(val)!=(val*1) || val == '') ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } else { removeErrorFormatting(ElmtName, RowName, frm); } } function CheckIntegerField(ElmtName, RowName, frm, isReq) { if (frm.elements[ElmtName].value != '' || isReq.toLowerCase() == 'true') { if(frm.elements[ElmtName].value.indexOf('.') != -1 || (frm.elements[ElmtName].value % 1) != 0 || frm.elements[ElmtName].value == '') ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } else { removeErrorFormatting(ElmtName, RowName, frm); } } //----- function CheckEmail (ElmtName, RowName, frm, isReq) { //add for optimost required field testing. if(isOptRequired) isReq = 'true'; var regEx; regEx = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/; if(!regEx.test(frm.elements[ElmtName].value) && (frm.elements[ElmtName].value != '' || isReq != 'False')) ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } //------- function CheckDate(ElmtMonth, ElmtDay, ElmtYear, RowName, frm, isReq) { var Day = frm.elements[ElmtDay].options[frm.elements[ElmtDay].selectedIndex].value; var Month = frm.elements[ElmtMonth].options[frm.elements[ElmtMonth].selectedIndex].value - 1; var Year = frm.elements[ElmtYear].options[frm.elements[ElmtYear].selectedIndex].value; var DateObj = new Date(Year,Month,Day); if ( DateObj.getMonth() != Month) { ThrowError(RowName, RowName, frm); } else { removeErrorFormatting(RowName, RowName, frm); } } //------- function CheckZip(ElmtName, RowName, frm, isReq) { var regEx regEx = /^\d{5}$|^\d{5}-\d{4}$/; if(!regEx.test(frm.elements[ElmtName].value) && (frm.elements[ElmtName].value != '' || isReq != 'False')) ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } //------ function CheckDropDown(ElmtName, RowName, frm) { if (!frm.elements[ElmtName]) return; if(frm.elements[ElmtName].options.selectedIndex == 0) ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } //------- function CheckRadioButton(ElmtName, RowName, frm) { if (!frm.elements[ElmtName]) return; var radioChecked = false; for(var i=0;i < frm.elements[ElmtName].length; i++) { if(frm.elements[ElmtName][i].checked) { radioChecked = true; break; } } if(!radioChecked) ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } //------- function CheckCheckboxes(ElmtName, RowName, frm) { if (!frm.elements[ElmtName]) return; var checkboxChecked = false; for(var i=0;i < frm.elements[ElmtName].length; i++) { if(frm.elements[ElmtName][i].checked) { checkboxChecked = true; break; } } if(!checkboxChecked) ThrowError(ElmtName, RowName, frm); else removeErrorFormatting(ElmtName, RowName, frm); } //------- function CheckPhone(ElmtNames, RowNames, frm, isReq) { //add for optimost required field testing. if(isOptRequired) isReq = 'true'; checkPhoneNumbers(ElmtNames, RowNames, frm, isReq) } //------ function CheckFrequency(ElmtName, RowName, frm) { var Tobacco = new Array(3,4,5,6,7,8); var ThrowErrorFlag = false; for(i = 0; i < Tobacco.length; i++) { if(Tobacco[i] == frm.elements["Tobacco"].options[frm.elements["Tobacco"].selectedIndex].value && frm.elements["Frequency"].options.selectedIndex == 0) { ThrowError("Frequency", RowName, frm); ThrowErrorFlag = true; break; } } if(!ThrowErrorFlag) removeErrorFormatting(ElmtName, RowName, frm); } function CheckTextArea(field, maxlen) { if (field.value.length > maxlen) { field.value = field.value.substring(0, maxlen); alert('Only 1000 characters allowed. Your input has been truncated to 1000 characters'); } } //------ function ThrowError(ElmtName, RowName, frm) { if(!eval("document.getElementById('" + RowName + "')")) return; applyErrorFormatting(ElmtName, RowName,frm) error[error.length] = RowName; } //------ function applyErrorFormatting(fldName, RowName,frm) { tableRow = eval("document.getElementById('" + RowName + "')"); tableRow.className = "error2"; } //----- function removeErrorFormatting(fldName, RowName,frm) { var isSharedRow = CheckForSharedRow(RowName) // call function to handle fields that share the same row if(isSharedRow) return true; tableRow = eval("document.getElementById('" + RowName + "')"); if(tableRow) tableRow.className = "quoter"; } function CheckForSharedRow(RowName) { for(var i=0;i<error.length;i++) { if(error[i] == RowName) return true; } return false; } function isBrowserCompatible() { if(document.getElementById) return true; else return false; } function trim(str) { return str.replace(/^\s*|\s*$/g,""); } //------ function OpenWindow(name,filename,height,width,parameters) { var hwin = window.open(filename,name,"height=" + height + ",width=" + width + "," + parameters); hwin.focus(); } //----- function StandardPopup(pagePath) { OpenWindow("", pagePath, 450, 300, ""); } //------ Code for the form: Code: <form action="#" method="get" onsubmit="return ValidateQuoteRequest(this);" name="FrontPage_Form"> <tr class="quoter" id="row_state"> <td align="right" nowrap=""><a href="javascript:popUp('state')" title="">State</a></td> <td colspan="2"> <select name="state" size="1" tabindex="12"> <option value="-1">Select state...</option> <option value="AK">Alaska</option> </select> </td> </tr> <tr class="quoter" id="row_date"> <td align="right"><a href="javascript:popUp('dob');" title="">Date of Birth</a></td> <td colspan="2"><select name="Month"> <option value="-1">Month</option> <option value="01">Jan</option> </select> <select name="Day"> <option value="-1">Day</option> <option value="01">01</option> </select> <select name="Year" size="1"> <option value="-1">Year</option> <option value="1921">1921</option> </select> </td> </tr> <tr class="quoter" id="row_sex"> <td align="right"><a href="javascript:popUp('gender')" title="">Gender</a></td> <td colspan="2"><select name="Sex" size="1"> <option value="-1">Select...</option> <option value="1">Male</option> </select> </td> </tr> <tr class="quoter" id="row_Height"> <td align="right">Height</td> <td nowrap="" colspan="2"><select name="Height_Feet" size="1"> <option value="-1"></option> </select> ft <select name="Height_Inches" size="1"> <option value="-1"></option> </select> in Weight <input name="Weight" size="3" maxlength="3" value=""> lbs </td> </tr> <tr class="quoter" id="row_tobacco"> <td align="right"><a href="javascript:popUp('tobacco')" title="">Tobacco/ Nicotine Use</a></td> <td colspan="2"><select name="Tobacco" onchange="toggleRow(this,'4,5,6,7,8','row_tobaccotype',document.FrontPage_Form.Frequency)"> <option value="-1">Select...</option> <option value="1">Never used</option> <option value="7">Current user</option> </select></td> </tr> <tr class="quoter" style="display: none; " id="row_tobaccotype"> <td align="right">Type of Tobacco or Nicotine and frequency of use</td> <td colspan="2"><select name="Frequency"> <option value="0" selected="">Please select...</option> <option value="10">Cigarettes, less than 1/2 pack a day</option> </select></td> </tr> <tr class="quoter" id="row_coverage"> <td align="right" class="quoter"><a href="javascript:popUp('calculator','https');" title="">Coverage Amount</a></td> <td><select name="Amount" size="1"> <option value="750000">$750,000</option> </select> <a href="javascript:popUp('calculator');" title="" class="nav-sub" ;=""><img src="./Insurance_files/help.gif" width="16" height="17" alt="" border="0" align="bottom"></a></td><td class="quoter"><a href="javascript:popUp('calculator');" title="">How much life<br>insurance do I need?</a></td> </tr> <tr class="quoter"> <td align="right"><a href="javascript:popUp('term');" title="">Guaranteed Term</a></td> <td class="quoter" colspan="2" id="ProductType"><select name="ProductType" size="1"> <option value="8">10 Years</option> </select></td> </tr> <tr class="quoter" id="row_PreClass"> <td align="right"><a href="javascript:popUp('healthclass');" title="">Health Class</a></td> <td><select name="PreClass" size="1"> <option value="0" selected="">Best Class</option> <option value="2">Preferred</option> </select> <a href="javascript:popUp('healthclass');" title=""><img src="./Insurance_files/help.gif" width="16" height="17" alt="" border="0" align="bottom"></a></td> <td><a href="javascript:popUp('healthclass');" title="">How do I determine<br>my health class?</a><a href="#">*</a></td> </tr> <tr class="quoter" id="row_firstname"> <td align="right"> First Name</td> <td class="quoter" colspan="2"><input name="firstname" size="30" maxlength="50" value=""></td> </tr> <tr class="quoter" id="row_lastname"> <td align="right"> Last Name</td> <td colspan="2"><input name="lastname" size="30" maxlength="50" value=""></td> </tr> <tr class="quoter" id="row_workphone"> <td align="right">Social Security Number</td> <td colspan="2">(<input maxlength="3" name="ssn1" size="3" value="">)-<input maxlength="2" name="ssn2" size="2" value="">-<input name="ssn3" size="4" maxlength="4" value=""></td> </tr> <tr class="quoter" id="row_workphone"> <td align="right">Work Phone</td> <td colspan="2">(<input maxlength="3" name="workphone1" size="3" value="">)-<input maxlength="3" name="workphone2" size="3" value="">-<input name="workphone3" size="4" maxlength="4" value=""></td> </tr> <tr class="quoter" id="row_homephone"> <td align="right">Home Phone</td> <td colspan="2">(<input maxlength="3" name="homephone1" size="3" value="">)-<input maxlength="3" name="homephone2" size="3" value="">-<input name="homephone3" size="4" maxlength="4" value=""></td> </tr> <tr class="quoter" id="row_email"> <td align="right"><a href="javascript:popUp('email','https');">E-mail</a></td> <td colspan="2"><input name="email" size="30" maxlength="80" value=""></td> </tr> <tr> <td colspan="3" align="center" nowrap=""> <input type="image" title="Please click only once." name="Submit" src="./Insurance_files/compare_rates.gif" width="172" height="28" value="Compare Rates Now!" alt="Get Your Life Insurance Quote Now"> </form> Any suggestions on how the javascript below should be changed so it will work with checkboxes that have brackets in the name? (I'm using foreach in php, and can't seem to get the php to work/work correctly without using them.) Thanks! Code: function chktotal(j) { var total=0; for (var i=0; i < document.form1.ckbx.length; i++){ if(document.form1.ckbx[i].checked){ total=total+1; } if(total>8){ alert("Please only select 8"); document.form1.ckbx[i].checked = false; total = total -1; return false; } } document.form1.totalval.value = total; } <input onclick="chktotal(2)" value ="Sample Item 1" type="checkbox" name="ckbx[]"> could anyone tell me how to do this? i don't know anything about javascript, but it is the most elegant way to validate a form. i have 2 questions asked in a form (name=questions). First question are radio buttons with 3 answers (name=answer). Second is a questions with a numeric value as answer with max 10 characters (name=questionb). Could anyone tell me where to start? Thanks, Walter Hi guys, I'm having an issue with a my form total, I'm getting the same result no matter what positive number I enter. Every other aspect of the code seems to be working ok apart from this. eg. If I enter the number 4, the factorial number should read 24 but it's reading 1, its reading 1 no matter what number goes in there. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type= "text/javascript"> function calcFactorial(factorialNumber) { var factorialResult = 1; for (; factorialNumber > 0; factorialNumber --){ factorialNumber = factorialResult * factorialNumber; } return factorialResult; } </script> </head> <frameset cols="100%,*"> <frame name = "fraCalcFactorial" src="calcFactorial.htm" /> <frame src="UntitledFrame-4"></frameset><noframes></noframes> </html> I believe the issue is in here somewhere but I'm not sure where. Ironically I'm learning from a book and this is from the Error handling/Debugging chapter. I'm going well on this book so far and really don't want to have to move forward without fully understanding whats going on. Any help/comments would be greatly received. Sara |