JavaScript - Parsing Radio Selections In Textarea Box
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> Similar TutorialsHi, 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. This script works great for populating predefined lists of data into a textarea as selected by the user using a radio button: Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Populate Textarea Based on Radio Button Selection</title> <script> text = new Array() text[0] = Array('Hotel', 'Motel'); text[1] = Array('Couch', 'Bed', 'Chair'); function populate(r,f){ t=-1; for(var i=0;i<f.elements[r].length;i++){ if (f.elements[r][i].checked){ var t=i; } } if(t>-1){ f.thefirsttextarea.value= text[t].toString().replace(/,/gi,"\n"); } } </script> </head> <body> <form name="frm"> <input type="radio" name="test" value="0" onClick="populate(this.name,this.form)"> <input type="radio" name="test" value="1" onClick="populate(this.name,this.form)"> <textarea name="thefirsttextarea"></textarea> <input type="submit" value="submit" /> </form> </body> </html> However, I've coded all night only to come across an issue. I have an inline page style which calls/includes multiple pages. Two of these pages require this feature. It seems one is canceling out the other. Here's an example: 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>Populate Multiple Textareas Based on Radio Button Selection</title> <script> text = new Array() text[0] = Array('Hotel', 'Motel'); text[1] = Array('Couch', 'Bed', 'Chair'); function populate(r,f){ t=-1; for(var i=0;i<f.elements[r].length;i++){ if (f.elements[r][i].checked){ var t=i; } } if(t>-1){ f.thefirsttextarea.value= text[t].toString().replace(/,/gi,"\n"); } } </script> <script> textt = new Array() <!--default--> text[0] = Array('Ham', 'Turkey', 'Chicken'); <!--all--> text[1] = Array('Beer', 'Soda', 'Water'); <!--johnny havana--> text[2] = Array('Milk', 'Cheese', 'Butter'); function populate(r,f){ t=-1; for(var i=0;i<f.elements[r].length;i++){ if (f.elements[r][i].checked){ var t=i; } } if(t>-1){ f.SECONDFORM.value= text[t].toString().replace(/,/gi,"\n"); } } </script> </head> <body> <form name="form"> <input type="radio" name="test" value="0" onClick="populate(this.name,this.form)"> <input type="radio" name="test" value="1" onClick="populate(this.name,this.form)"> <textarea name="thefirsttextarea"></textarea> <input type="submit" value="submit" /> </form> <form name="anotherform"> <input type="radio" name="anothertest" value="0" onClick="populate(this.name,this.form)"> <input type="radio" name="anothertest" value="1" onClick="populate(this.name,this.form)"> <textarea name="SECONDFORM"></textarea> <input type="submit" value="submit" /> </form> </body> </html> With the above code only the second set of radio buttons work. What I need help with is a way to have two independent sets of arrays the correspond correctly with the textareas - One set that populates textarea 1 and the other that populates textarea 2. 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 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>"; } 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! hello 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!! I have the below code i been trying to figure out how to reset the font changes made without having to refresh the website (f5). Currently I have created a button that onClick uses history.go(0) which refreshes the page removing the font changes. I would like help with figuring out a solution to reset (remove font) step1-5 without having to refresh the page. Thanks. Preview of Code Code: <html> <head> <title>My Title Page</title> <script type="text/javascript"> function selectTextArea() { document.FormTextArea.TextAreaBox.select(); document.FormTextArea.TextAreaBox.focus(); } function changeStepColor(id) { document.getElementById(id).style.font="italic bold 15px arial,serif"; } function inputPrompt(String , msg) { String=prompt(msg, ""); if (String!=null && String!="") { document.FormTextArea.TextAreaBox.value=document.FormTextArea.TextAreaBox.value + msg + ' ' + String + '\r' + '----------------------------------' + '\r' } else { document.FormTextArea.TextAreaBox.value=document.FormTextArea.TextAreaBox.value + msg + ' N/A' + '\r' + '----------------------------------' + '\r' } } </script> </head> <body> <table border="1" cellpadding="2" cellspacing="2" width="100%"> <tr> <td width="50%" align="center" valign="top"> <form name="FormTextArea"> <textarea name="TextAreaBox" cols="40" rows="12" wrap="virtual"></textarea> </form> </td> <td width="50%" valign="top"> <font size="2" id="step1">1. Step One</font> <input type="button" value="Input" onclick="inputPrompt('a', 'Step 1:'); changeStepColor('step1');" /><br /> <font size="2" id="step2">2. Step Two</font> <input type="button" value="Input" onclick="inputPrompt('a', 'Step 2:'); changeStepColor('step2');" /><br /> <font size="2" id="step3">3. Step Three</font> <input type="button" value="Input" onclick="inputPrompt('a', 'Step 3:'); changeStepColor('step3');" /><br /> <font size="2" id="step4">4. Step Four</font> <input type="button" value="Input" onclick="inputPrompt('a', 'Step 4:'); changeStepColor('step4');" /><br /> <font size="2" id="step5">5. Step Five</font> <input type="button" value="Input" onclick="inputPrompt('a', 'Step 5:'); changeStepColor('step5');" /> </td> </tr> <tr> <td width="50%" align="center" valign="top"> <input type="button" value="Select Text Area" onClick="selectTextArea()" /> <input type="button" value="Clear Text Area" onClick="document.FormTextArea.TextAreaBox.value=''; history.go(0)" /> </td> <td width="50%" align="center" valign="top">   </td> </tr> </table> </body> </html> 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. Hi everyone, I'm new here, I actually found this site by searching for the code I have a question for. I'm trying to show/hide different drop down selectors, depending on what is chosen in another drop down selector. I modified a script (I found he http://www.codingforums.com/showthread.php?t=98406) in a way that I thought would work, but its not. Can anyone help me with what I'm doing wrong? Here is my page: http://www.leatherexpressonline.com/...er/testing.php Here is my javascript: http://pastie.org/3344253 And my drop downs: http://pastie.org/3344258 Also, I don't want the drop downs (ids: grade1000color, grade1500color, grade2000color, grade2500color, grade3000color, grade5000color) to be shown when the page is first loaded. Only when the correct option is chosen on the drop down. So I'm guessing I should add a display:none style to those drop downs, then have them shown on the javascript? Thanks so much for the help Hi i have a problem, i've been trying to fix this for the whole day pls see my code below Code: for ($o = 0; $o <= $totalclass; $o++) { for($i = 1; $i <= 45; $i++) { if ($_SESSION['classification'][$o] == $i) { $sql2="SELECT ClassDesc FROM tblclass WHERE ClassID = '$i'"; $result2=mysql_query($sql2); // If successfully queried if($result2) { while ($row2 = mysql_fetch_assoc($result2)) { $ClassDesc2 = $row2['ClassDesc']; } } //echo $ClassDesc2; ?> <tr> <td bgcolor="FAFAF6" class="small" valign="top">Class <? echo $i; ?></td> <input type="hidden" name="<? echo "classid[]"; ?>" value="<? echo $i; ?>"> <td bgcolor="FAFAF6"> <textarea name="<? echo "specification[]"; ?>" COLS="50" ROWS="6" class="small" wrap="virtual" tabindex="<? echo $i; ?>"><? echo $ClassDesc2;?></textarea> <input type="button" value="Reset" onclick="window.reset();" name="reset"> </td> </tr> <? } } } i've trying to create a button or image to reset one textarea (from whole array) and so far i've been unsuccessful. i've seen this on other website and i know it is possible to do this, pls help! I have 4 rows in a table. Each row consist of 4 radio buttons. Each radio button per row has different values in it but has the same name (group) ex: <input type="radio" name="a" value="1"> <input type="radio" name="a" value="2"> <input type="radio" name="a" value="3"> <input type="radio" name="a" value="4"> <input type="radio" name="b" value="1"> <input type="radio" name="b" value="2"> <input type="radio" name="b" value="3"> <input type="radio" name="b" value="4"> and so on.. If I click radio button A with value 2, I want to output the total at the bottom as "2".. Also, if I click radio button B with value 3, I want to output the total of A and B as 5 and so on.. How can I automatically calculate the answer based on which radio button was click? update: I got my answer from this site: http://stackoverflow.com/questions/1...s-using-jquery Anyone that can help on this one it would be greatly appreciated... I need to make a form parses a result from column 1 of txt/csv file that has 7 columns. Column 1 is pay, column 2-7 are how many and the associated rows are the answers. In short 1 2 3 4 5 6 700 50 55 62 75 80 99 so if the customer enters i make 700 and i need 2 the result would be 55 as the output. Any idea on how to make that work with javascript? if (pay <=700 && widgets = 2) { document.write(55) elseif (pay <=700 && widgets = 1) document.write(50) is this doable and is it the easiest way to accomplish this? Hi All I have a xml string located in a hidden textbox that i need to parse how do i get it into a xml object I thought nievly i could xmlDoc = document.getElementById("XML").value alert(xmlDoc.getElementsByTagName("SupplMets")[0]); document.write("<table border='1'>"); but obviously i need to do some more work to get it into an xml object ...any ideas the end goal here is to get the data in the xml into a table here is what the xml string looks like <SupplMets TumorSupplementalId="272341"><SupplMet TumorSupplMetsId="109130" SiteOfMetastasis="C020" DateOfMetastasis="20010101" MetastasisIdType="" MetastasisEliminated="" MetastasisSD="02-003710" /></SupplMets> I'm trying to work with XML DOM for the first time as I need to grab a value from a SOAP request. I've been following this: http://www.w3schools.com/xml/xml_parser.asp, which says modern browsers won't parse xml files from another server for security reasons. How would I got about doing this then? I've been using the price of crude oil as an example (http://www.google.com/ig/api?stock=OIL) and want code portable enough to put on something like Tumblr, so I don't think I can actually save the file locally first. Any ideas? Thanks, Zach Hey, Im fairly new to javascript but I am an experianced php programmer. I have been parsing XML information using php, but my CPU usage has been too high recently due to this. I am trying to convert my scripts to javascript, but I am unsure how I can do this using javascript. I think that if I get started off, the rest will be easy. One of my XML files is located at Code: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=bbcradio1&api_key=c910b0bc1e2d4e64964ebcd2d69c255c&limit=500 Basically I have been trying to grab the Name, Artist and large image of the most recent <track>. Any help would be greatly appreciated and linked too on my website . Tim hi, I am a newbie. Using Java script, I need to open and read CSV file. I need to read the third column values and store in an array. Please help me regarding this. Thanks, Hanumanth. I'm trying to parse out location data from XML that is passed back from Google. It currently parses the data correctly, the problem is that it grabs all of the matching tags, instead of just the first results set. Here's an example of the output. Here's the code I'm using to achieve this: Code: function(){ var url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=NewBrunswick,NJ&sensor=false'; $.ajax({url: 'proxy2.php?url='+url, type: "GET", dataType: "text", success: function ($data) {$data = $($data); lat = ($data.find('geometry').find('location').find('lat').text()); long = ($data.find('geometry').find('location').find('lng').text()); }});}); How would I change it so that it only grabs the data from the first set of results? |