JavaScript - Validate Html Form (multiple Selections)
Good day. This form is working, but I want to make the "What AIS services are you interested in?" multiple selection a "required field". The other required fields are working, but I can't figure out how to make this field "required".
Code: <blockquote><h2>Request More Information:</h2> <script type="text/javascript"> function MM_validateForm() { //v4.0 if (document.getElementById){ var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } } </script> <form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" onsubmit="MM_validateForm('first_name','','R','last_name','','R','email','','RisEmail','company','','R','phone','','RisNum');return document.MM_returnValue"><input type="hidden" name="oid" value="00Dd0000000cnUc" /> <input type="hidden" name="retURL" value="http://aissolutions.ca/thank-you" /> <p style="float:left;width:350px"><label for="first_name">First Name <span style="color:#f00">(required)</span></label><input id="first_name" type="text" name="first_name" size="50" maxlength="40" /></p> <p style="float:left;width:350px"><label for="last_name">Last Name <span style="color:#f00">(required)</span></label><input id="last_name" type="text" name="last_name" size="50" maxlength="80" /></p> <p style="float:left;width:350px"><label for="email">Email <span style="color:#f00">(required)</span></label><input id="email" type="text" name="email" size="50" maxlength="80" /></p> <p style="float:left;width:350px"><label for="company">Company <span style="color:#f00">(required)</span></label><input id="company" type="text" name="company" size="50" maxlength="40" /></p> <p style="float:left;width:350px"><label for="phone">Phone <span style="color:#f00">(required)</span></label><input id="phone" type="text" name="phone" size="50" maxlength="40" /></p> <p style="float:left;width:350px">Best Time To Call:<select style="width:325px" id="00Nd0000004F2Mb" name="00Nd0000004F2Mb" title="Best Time To Call"><option value="">--None--</option><option value="9:00am to 12:00pm">9:00am to 12:00pm</option> <option value="1:00pm to 5:00pm">1:00pm to 5:00pm</option> <option value="6:00pm to 9:00pm">6:00pm to 9:00pm</option> </select></p> <p style="clear:left;float:left;width:350px"><label for="street">Address</label><br> <textarea name="street" cols="47"></textarea></p> <p style="float:left;width:350px">What AIS services are you interested in?:<select style="width:325px" id="00Nd00000043aHr" multiple="multiple" name="00Nd00000043aHr" title="What AIS services are you interested in?"><option value="Bookkeeping">Bookkeeping</option> <option value="Business Incorporation">Business Incorporation</option> <option value="Catch Up/Clean Up Records">Catch Up/Clean Up Records</option> <option value="Job Costing">Job Costing</option> <option value="Part Time CFO">Part Time CFO</option> <option value="Software Conversion">Software Conversion</option> <option value="Software Customization">Software Customization</option> <option value="Software Training">Software Training</option> <option value="Tax Services">Tax Services</option> </select></p> <p style="float:left;width:350px">Anything else you think we should know:<br> <textarea id="00Nd0000004E2rs" name="00Nd0000004E2rs" cols="47"></textarea></p> <p style="clear:left;float:left"><input type="submit" name="submit" /></p> Thanks. Similar Tutorialshello guys! I need help setting up a form, I want to do some pretty neat things: It will say: What countries do you want to visit? [FIELD] Part 1: I want that when a user starts typing into the field, it will suggest under things that match what you have typed so far, sort of like facebook search does. So I would need a list of recognized country names. Now for example imagine I was using this, and I typed in M, it would list under a max of 5 valid entries begining with M, if I typed in Me, it would list the ones begining with Me, if I typed in Mex, it would show Mexico. Now the user would have to click this drop down suggestion to choose it. Part2: I want once a user clicks on a suggestion, it will "pop under" the input box or somewhere, with a "x" beside it to remove it. The user can now type in another country, and when it is clicked it too appears as a sort of "icon" under the input box or somewhere, with an "x" beside it. Clicking the x removes the country from the current list of countries. Once he is done, he goes on to other fields and the selected countries remain visible. Once a user submits the form, I want to get only the countries that were visible to him. **An alternative idea, if this one is too complicated, would be to have a drop list with all countries in it, and once a person clicks one, it will remain and a "+" sign will appear under it. When pressed, another dropdown menu will appear so the person can choose another country from the second drop down, etc. OFC all selected countries can have an X to remove them. Idk how to do this either.. I need help guys I have no clue how to do something like this, where do you recommend I start? Any ideas? I tried searching but I'm not sure what to call this so I couldn't find anything in the search. Thanks for your help so much!! Hello all, I have a form that submits a POST request when data is submitted. A Servlet then processes this POST request and a JavaBean is used to make some calculations. The HTML response is not generated within the Servlet but instead I forward the request to a JSP to generate the response. - This all works fine, thankfully. However, I am stupidly suck trying to validate the form on the client side with a JavaScript function before the form is submitted. Here is my index.jps: Code: <%-- Document : index Created on : 19-Nov-2009, 13:41:30 Author : lk00043 --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/JavaScript"> <!-- Start hiding JavaScript Statements function validateForm() { var student; var score1, score2, score3, score4; student = document.getElementById('student'); s1 = document.getElementById('score1'); s2 = document.getElementById('score2'); s3 = document.getElementById('score3'); s4 = document.getElementById('score4'); score1 = parseInt(s1.value); score2 = parseInt(s2.value); score3 = parseInt(s3.value); score4 = parseInt(s4.value); if(student.value.length == 0) { document.getElementById('StudentError1').innerHTML = " Enter a student name!"; return false; } if ((isNaN(score1)) || (score1 < 0) || (score1 > 100)) { document.getElementById('Error1').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score2)) || (score2 < 0) || (score2 > 100)) { document.getElementById('Error2').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score3)) || (score3 < 0) || (score3 > 100)) { document.getElementById('Error3').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score4)) || (score4 < 0) || (score4 > 100)) { document.getElementById('Error4').innerHTML = " Enter a number between 0 and 100!"; return false; } } // End hiding JavaScript Statements --> </script> <title>Lab Class 7 - Task 2</title> </head> <body> <h1>Lab Class 7</h1> <form name="collectgrades" action="AssessGrades" method="POST" onSubmit="validateForm()" > Name of Student: <input type="text" name="student" id="student"/><span id="StudentError1"> </span><br /> Presentation: <input type="text" name="score" id="score1"/><span id="Error1"> </span><br /> Writing style: <input type="text" name="score" id="score2"/><span id="Error2"> </span><br /> Technical content: <input type="text" name="score" id="score3"/><span id="Error3"> </span><br /> Depth of analysis: <input type="text" name="score" id="score4"/><span id="Error4"> </span><br /> Feedback:<select name="feedback" size="4" multiple="multiple"> <option>"Could be better structured."</option> <option>"Depth of analysis is good."</option> <option>"Very advanced material."</option> <option>"Very well structured."</option> </select><br /> <input type="submit" value="Submit" /> </form> </body> </html> Regardless of whether incorrect input is given, the data is still POSTed to the server and calculated on or a Server Side error is given. Am I correct in calling the function onClick? The validation essentially needs to be so that: - Student field contains a string - Score1, Score2, Score3 and Score 4 contain a number between 0 and 100 Any help is most appreciated, Cheers, Beetle. Please see my Booking Form here http://www.n-v-m.co.uk/Booking.html The form is very nearly finished but I have no experience with JavaScript at all so I am hoping somebody can tell me how to do the finishing touches. All I require is: 1- On clicking the 'Submit order' button I would like the browser to check to see if the 'Is Vehicle roadworthy with full M.O.T.:' List/Menu is set to 'Yes' and if not it needs to return an alert stating it must be set to 'Yes' to proceed... Somebody kindly helped show me how to do the alert before so this is working, but, the problem at the moment is after clicking 'OK' to close the alert, the form is still submitted. At this point instead of the form being submitted I would just like the browser to return to the form. 2- There is a checkbox on the bottom of the form that states 'I agree with the Terms and Conditions'... To be able to proceed with a booking I need the customer to check the box... On clicking 'Submit order' if the box isn't checked I would like an alert to appear and the form not to be submitted. 3. When both the above criteria have been met and the form is ready to submit... I would like the browser to re-direct to http://www.n-v-m.co.uk/Thankyou.html which is a page I have already created on my server. Thanks for taking your time to read this... If it helps I have posted both my HTML and PHP codes below: Booking.html 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>National Vehicle Movements - Booking Form</title> <style type="text/css"> <!-- body { background-color: #1d255f; margin: 0px; padding: 0px; } #apDiv1 { position:absolute; width:487px; height:706px; z-index:auto; left: 50%; top: 433px; font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; text-align: center; textarea-align: center; background-position: center; margin-left: -244px; } --> </style> <script type='text/javascript'> function isValid() { var box = document.getElementById('Is Vehicle Roadworthy with Full M.O.T.'); if(box.value = 'no') { alert('The vehicle must be roadworthy with full M.O.T'); return false; } } </script> </head> <body> <div align="left"> <div id="apDiv1"> <form id="form1" name="form1" method="post" action="sendform.php" onsubmit='validatethis()'> <table width="400" border="0" align="center"> <tr> <td width="193" align="right">Company:</td> <td width="197" align="left"><input type="text" name="company" id="Company" /></td> </tr> <tr> <td align="right">Name:</td> <td align="left"><input type="text" name="name" id="Name" /></td> </tr> <tr> <td align="right">Phone Number:</td> <td align="left"><input type="text" name="phonenum" id="Phone Number" /></td> </tr> <tr> <td align="right">Email Address:</td> <td align="left"><input type="text" name="email" id="Email" /></td> </tr> <tr> <td align="right">Vehicle Make and Model:</td> <td align="left"><input type="text" name="vmam" id="Vehicle Make and Model" /></td> </tr> <tr> <td align="right">Vehicle Reg./Ref. No.:</td> <td align="left"><input type="text" name="vreg" id="Vehicle Reg." /></td> </tr> <tr> <td align="right">Collection Address including Postcode:</td> <td align="left"><textarea name="colladd" rows="4" id="Collection Address"></textarea></td> </tr> <tr> <td align="right">Collection Contact Name:</td> <td align="left"><input type="text" name="collconname" id="Collection Contact Name" /></td> </tr> <tr> <td align="right">Collection Contact Number:</td> <td align="left"><input type="text" name="collconnum" id="Collection Contact Number" /></td> </tr> <tr> <td align="right">Delivery Address including Postcode:</td> <td align="left"><textarea name="deladd" rows="4" id="Delivery Address"></textarea></td> </tr> <tr> <td align="right">Delivery Contact Name:</td> <td align="left"><input type="text" name="delconname" id="Delivery Contact Name" /></td> </tr> <tr> <td align="right">Delivery Contact Number:</td> <td align="left"><input type="text" name="delconnum" id="Delivery Contact Number" /></td> </tr> <tr> <td align="right">Collection Date/Time:</td> <td align="left"><input type="text" name="collectiondt" id="Collection Date/Time" /></td> </tr> <tr align="center"> <td colspan="2" valign="top"><em>(if possible please give a time window eg. '7th - 9th August' and we will arrange collection for you)</em></td> </tr> <tr> <td align="right">Delivery Date/Time:</td> <td align="left"><input type="text" name="deliverydt" id="Delivery Date/Time" /></td> </tr> <tr align="center"> <td colspan="2" valign="top"><em>(if possible please give a time window eg. '7th - 9th August' and we will arrange delivery for you)</em></td> </tr> <tr> <td align="right">Is Vehicle Taxed:</td> <td align="left"><select name="Taxed" id="Is Vehicle Taxed"> <option>Yes</option> <option selected="selected">No</option> </select></td> </tr> <tr> <td align="right">Is Vehicle roadworthy with full M.O.T.:</td> <td align="left"><select name="mot" id="Is Vehicle Roadworthy with Full M.O.T."> <option>Yes</option> <option selected="selected">No</option> </select></td> </tr> <tr> <td align="right">Billing Address:</td> <td align="left"><textarea name="billadd" rows="3" id="Billing Address"></textarea></td> </tr> <tr align="center"> <td colspan="2" valign="top"><em>(if same as collection or delivery address please enter 'collection' or 'delivery')</em></td> </tr> <tr> <td align="right">Your Ref./Order No. (if any):</td> <td align="left"><input type="text" name="custordnum" id="Customer Ref./Order No." /></td> </tr> <tr> <td align="right">Any additional comments:</td> <td align="left"><textarea name="addcom" rows="3" id="Any additional comments"></textarea></td> </tr> <tr align="center" valign="middle"> <td colspan="2"> <p> <input type="checkbox" name="checkbox" id="checkbox" /> I agree with the <u><a href="Terms.html">Terms and Conditions</a></u></strong></p> <p> </p></td> </tr> <tr align="center"> <td colspan="2"><input type="submit" name="button" id="button" value="Submit order" onclick="isValid()" /> <input type="reset" name="button2" id="button2" value="Reset form" /></td> </tr> </table> </form> </div> </div> <div align="center"><img src="images/Booking_03.jpg" width="680" height="1352" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="36,155,158,173" href="index.html" alt="Home" /> <area shape="rect" coords="29,174,151,189" href="Prices.html" alt="Prices" /> <area shape="rect" coords="475,191,578,206" href="mailto:info@n-v-m.co.uk" alt="Email us" /> </map> </div> </body> </html> sendform.php Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <BODY> <?php $Name = $_POST['name']; //senders name $to = "info@n-v-m.co.uk"; //recipient $subject = "Order from ".$_POST['company']." (".$_POST['name'].")"; //subject $message = $_POST['company']."|".$_POST['name']."|".$_POST['phonenum']."|".$_POST['email']."|".$_POST['vmam']."|".$_POST['vreg']."|".$_POST['colladd']."|".$_POST['collconname']."|".$_POST['collconnum']."|".$_POST['deladd']."|".$_POST['delconname']."|".$_POST['delconnum']."|".$_POST['collectiondt']."|".$_POST['deliverydt']."|".$_POST['Taxed']."|".$_POST['billadd']."|".$_POST['custordnum']."|".$_POST['addcom']; //mail body $from = "NVM Booking Form"; // $headers = "From: ".$from."\r\n"; //optional headerfields mail($to, $subject, $message, $headers); //mail command :) you can add any variable here... I know you have so many, but it is possible... if(mail) echo "Booking confirmed. Thank You!"; else echo "Sorry We Can't Proceed, Please Try After Some Time!"; ?> </BODY> </HTML> I am trying to make validation for a form but the bit I am stuck on now is: Code: <input class="submit" type="submit" value="Submit" id="submit" name="submit" onclick="return validate();" /> Do I have to add 'verify' instead of the 'validate' I mean is this a set thing in JS as I want it to go to the JavaScript code which is validate.js I should add that the form is XHTML and there is also a captcha with it. So I would not know how to add the onsubmit to the beginning of the form. hello i am trying to do a validation form but i ended up with one that only works for chrome, not on IE not on Firefox! don't know why!!! and another problem it looks like that the return false doesn't even work, it proceeds to the next page anyway [HTML]function validate_required(field,alerttxt) { with (field) { if (value==null||value=="-1") { alert(alerttxt); return false; } else { return true; } } } /*function alertt(thisform) {alert(thisform);}*/ function validate_form(thisform) { //alert('hi'); with (thisform) { if (validate_required(i_am_a,"i_am_a must be filled out!")=="-1") {i_am_a.focus(); return false;} } [/HTML] [HTML]<form method="post" action="index.php?page=step2" onsubmit="return validate_form(i_am_a.options[i_am_a.selectedIndex].value);"> <table class="text"> <tr> <td class="text">أنا</td> <td> <select name="i_am_a" id="i_am_a"> <!--onchange="validate_form(i_am_a.options[i_am_a.selectedIndex].value);">--> <option selected value="-1">الرجاء التحديد</option> <option value="MSW">رجل يبحث عن إمرأة</option> <option value="WSM">إمرأة تبحث عن رجل</option> </select> </td> </tr><tr class="submit"> <td> </td> <td> <input type="submit" value="إنضمم الآن مجانا" /> </td> </tr> </table> </form>[/HTML] Hello in "validateField" function radio is not exists and I don't know how can I add a validation rule for radio buttons. please help me . my code is attached. thank you This is what I have so far, it is a template I copied from my working E-mail validation. I'm assuming I have to make it so it's just an array of numbers but I really don't know Java too well. Essentially I just want numbers only to be accepted into the phone field. Code: else if(fieldType == 'phone') { if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_phone(fieldObj.value))) { fieldObj.setAttribute("class","mainFormError"); fieldObj.setAttribute("className","mainFormError"); fieldObj.focus(); return false; } } function validate_phone(phoneStr) { apos=phoneStr.indexOf("@"); if (apos<1||dotpos-apos<2) { return false; } else { return true; } } hello cant get my head around this..i had a form posting data to my sql database but it would show the thank you using {if} ect so created java vaildation script what points it to ?action=registered showing thank you message but it not submitting to sql or sending notification email?? can any one help me? thanks dan thanks alright so i am trying to validate this form and if you do not fill out the Day of the week then it does not submit the form to email.... 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>Guest List Signup</title> <style type="text/css"> <!-- body,td,th { color: #FFF; } body { background-color: #000; } --> </style></head> <script type='text/javascript'> function madeSelection(elem, helperMsg){ if(elem.value == "Select"){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } </script> <body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> <form name="halo-gl" form method="POST" action="contactgl.php"> <p>If you want to have your name on the HALO guest list please fill out the form below before 9pm and you and your guests will be on the list at the door. <p>This will get you free entry* until 11:30pm (this means at 11:31pm the list is over) also on select events there will not be a list and we might not have it posted on the website. <p>Guest list does not guarantee entry. It is to the discression of Halo on wether someone is permitted or not. <p> <p>Your Name:<br> <input type="text" name="MyName"> (First and Last) <p>How Many People I Will Have:<br> <select name="HowManyPeopleIWillHave"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <p>What day to be on the list:<br> <select id='selection'> <option value="Select">Please Select</option> <option value="Wednesday">Wednesday</option> <option value="Thursday">Thursday</option> <option value="Friday">Friday</option> <option value="Saturday">Saturday</option> </select> <p><input type="submit" name="submit" value='Submit' onclick="madeSelection(document.getElementById('selection'), 'Please Choose Something')" > </form> <p> </body> </html> you can see this currently in action at http://www.haloclt.com/guestlist.html any help would be appreciated thank you I created a form and validation to ensure that it is fully filled out, then once it is filled out properly, it should automatically go to the confirmation page. The way it works right now is that it does work properly, except if the error alert pops up it will then navigate to the confirmation page anyways, and that page will be blank. I have it setup with this in the form: Code: <form name = "orderForm" action="confirmOrder.html" onsubmit= "validateOrder()"> I need it to stop on error, and not let you continue to confirmOrder.html unless filled out right. Hi! I would like to show you guys the JavaScript that i using for my contact form /*----- Code goes here by clicking the link -----*/ http://web.ezenne.com/js/completeValid.js The above code was copied from a Youtube tutorial about JavaScript. I would like to ask, what additional code should be added in the existing code in order to validate the numbers only and an email format before the form to be submitted? Thanks! Regards, Ezenne I am Gururaj. I have written a form in HTML which contains username,lastname,email,password and submit. I have written a javascript to validate this form [validate(username,lastname,email,password)]. On submit this javascript function will be called and hence form get validated. I am passing all the arguements(username,lastname,email and password) to the javascript function.. Is it possible to make me a code such that it should call an individual function for each field in the form.for ex:if i have not entered username, last name in the form and attempt to submit, only username arguement should be passed to the function as it comes first in the form. In other sense i want to validate individual text field validation of my form. So can anybody help me.It will be very needful to me. I have a vertical menu in which the sub menu is a box that pops out to the right and the user can click boxes to make selections (input check boxes). I would like some way to indicate to the user after they have left the sub menu, that they have made selections within that sub menu. Perhaps a number after the menu item name, in which the number of sub menu selections are indicated in parenthesis? Is this possible? Dear all, Below the html and java code. After viewing using Internet Explorer, I did a selection from the autodropdown. Then I click on Click here to go to other page . You will see a quite different webpage. Then I click on the back button, in the left upper corner of IE window, so I see the previous webpage but.... the autodropdown does not remember my selection . How can we solve this? <html> <Head> <Script Language=JavaScript> Level1 = new Array("Ceramics","Chemicals") Ceramics = new Array("ELECTRONICS","ENVIRONMENTAL") Chemicals = new Array("METALLIC_SOAPS","OLEOCHEMICAL_DERIVATIVES") ELECTRONICS = new Array("Solder mask") ENVIRONMENTAL = new Array("Catalysts") METALLIC_SOAPS = new Array("Soap","Translucent soaps","Liquid soa[") OLEOCHEMICAL_DERIVATIVES = new Array("FA-pos","FA polfaideriv") function fillSelect(isValue,isNext){ isNext.style.display = ""; isNext.length = 1; curr = eval(isValue); for (each in curr) { isData = new Option(curr[each],curr[each]); isNext.add(isData,isNext.options.length); } } function getValue(isValue){ } </Script> </Head> <body> <center> <h4>Dependent Select List, within a form</h4> <Form name='Categories'> <p>Segment <Select name='List1' onChange="fillSelect(this.value,Categories.List2)"> <option selected>Make a selection</option> </Select> </p> <Select name='List2' onChange="fillSelect(this.value,Categories.List3)"> <option selected>Make a selection</option> </Select> <p></p> <Select name='List3' onChange="getValue(this.value)"> <option selected >Make a selection</option> </Select> </Form> </center> <Script> fillSelect('Level1',Categories.List1) Categories.List2.style.display = "none"; Categories.List3.style.display = "none"; </Script> <p>Click <a href="http://www.hetnet.nl">here</a> to go to other page</p> </body> </html> Hi all, I am in the process of developing a calculator for some of my colleagues to use. One of the variables within the calculations is called PMH. I want to determine the value of PMH based on which checkboxes are ticked. Each checkbox has a different value. If the checkbox is not ticked, then the value of each option is 1 and obviously more than one checkbox may be ticked. I have created the checbox code: Code: <td><input type="checkbox" name="PMH" value="1.6" /> Smoker<br /> <input type="checkbox" name="PMH" value="0.4" /> CCF<br /> <input type="checkbox" name="PMH" value="0.5" /> Pulmonary Oedema / Cirrhosis<br /> <input type="checkbox" name="PMH" value="0.8" /> COAD<br /></td> but I have no idea on how to calculate what I need for var PMH. Can someone guide me as to what I need to do please? Cheers, mads Hello, I need some help! I have some code that has a comments box and 2 radio buttons that ask if you want to be contacted about your comments. If you select "Yes", you get another set of radio buttons that ask you to choose a method of contact. When you choose a method, that selected methods value is parsed to the top of the textarea field, placing the comment below. I pretty much have it working, however, if I enter a comment in the "Comments" field, select "Yes", then select "email" and change to "Phone Morning", it concatnates the values in the textarea box instead of replacing the contact method value while still retaining the comment entered below. Also, if at all possible, I wanted to clear only the contact method value out of the textarea field and leave only the comment when you go back and click the "No" radio button. Can anyone please help? Thanks in advance! Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type='text/javascript'> function showContactType(obj){ if(document.storeCodeFeedbackForm.contact[1].checked == true){ document.getElementById("contactType").style.display = 'inline'; }else if(document.storeCodeFeedbackForm.contact[0].checked == true){ for(i=0;i<document.storeCodeFeedbackForm.contactType.length;i++){ document.storeCodeFeedbackForm.contactType[i].checked = false; } document.getElementById("contactType").style.display = 'none'; } } function printContactType(src) { if(src.checked) document.storeCodeFeedbackForm.customerMessage.value = src.value + "\n" + "------------------------" + "\n\n" + document.storeCodeFeedbackForm.customerMessage.value; document.storeCodeFeedbackForm.customerMessage.focus(); } </script> </head> <body> <form name="storeCodeFeedbackForm"> <table> <tr> <td>Comments:<br /> <textarea id='textArea' name="customerMessage" cols="30" rows="10"></textarea> <br /> </td> </tr> <tr> <td> Would you like to be contacted about your comments? <span style="color:#990000; font-weight:normal">*</span> <input type="radio" name="contact" value="no" onclick="showContactType(this);disableField(this);"> No <input type="radio" name="contact" value="yes" onclick="showContactType(this)"> Yes </td> </tr> <tr> <td><table cellpadding="0" cellspacing="0" border="0" width="100%" id="contactType" style="display:none"> <tr> <td class="tir" style="border-top:1px dashed #cccccc; padding-top:5px;">(Choose One)<span style="color:#990000">*</span> <input type="radio" name="contactType" value="Contact me by: e-Mail" onClick='printContactType(this);'> e-Mail <input type="radio" name="contactType" value="Contact me by: phone in the morning" onClick='printContactType(this);'> Phone Morning <input type="radio" name="contactType" value="Contact me by: phone in the afternoon" onClick='printContactType(this);'> Phone Afternoon <input type="radio" name="contactType" value="Contact me by: phone in the evening" onClick='printContactType(this);'> Phone Evening</td> </tr> </table></td> </tr> </table> </form> </body> </html> I had a different question that no one seemed to be able to answer here, so I found a different way of approaching the situation. I need to make an element in JS, then display it in a place (preferably in a position right after the selected text on the page using getSelection) or, in a fixed position. For some reason, this code won't work in FF3.5 (Win7) or Chrome although the basic stuff was taken straight from Mozilla's website: Code: function showSelectBox(){ var textlength = text.length; var element = document.createElement('div'); element.setAttribute('id','select'); element.innerHTML = textlength+"/140<div id=\"t-icon\"><a href=\"#\" onclick=\"emptySelection();\"><img src=\"imgs/t-icon.gif\" /></a></div>"; } Hi, I'm learning javascript and not sure what the script language is capable of. Is there a way to make radio button selections appear in a second popup window? Example: user selects various options from a page then clicks button to open a second window with select options showing up in list. Thanks for reading this. Hullo again, CF.com, So, now I have a curious question on arrays, selections, options and the like. My current project is available for perusal in order to assist me at: http://www.projectvoid.co.uk/ As you can see, I make it so that once the product type is selected, you can then select a wattage. This dependent drop-down works, however I want it so that when I select a value in the left-hand side (wattage), then the one on the right will offer a pre-defined value that replaces the wattage I have. For example, a GU-10 in 'Type of Lamp' offers a 50, 35 and 20 watt bulb in 'Current Lighting Products'. In 'Energy Efficient Products', it offers 5 and 3. I wish to make a statement somewhere so that if they select 50 on the left, it selects 5 on the right. If they select 35 on the left, it select 3 on the right. I would also like it to do multiple offers, so that if they select say, a 35 of the MR-16, I want the right hand side to offer both 5 and 3. The only way I can think of doing this is via a lot of 'IF' statements. Is there a quicker way to do this? Please assist and, if it's not too much to ask, could you comment the code? Thank you! |