JavaScript - Please Check This Code !!!!!
I am trying to add values from 6 text boxes and display its sum automatically in 7th text box. This is not working. Please help.
function calculate_a() { var a = document.getElementById('Para_A_A1_score').value ; var b = document.getElementById('Para_A_A2_score').value ; var c = document.getElementById('Para_A_A3_score').value ; var d = document.getElementById('Para_A_A4_score').value ; var e = document.getElementById('Para_A_A5_score').value ; var f = document.getElementById('Para_A_A6_score').value ; var g = (a+b+c+d+e+f) ; document.audit_billing_IE.product_name4.value = g ; } Quote: Below is the html form code that should automatically display the total value without clicking on any submit or send button <tr> <td> Parameter A </td> <td colspan='3'> <input type="text" name="product_name4" id="product_name4" onchange="calculate_a(this);" /> </td> </tr> Similar TutorialsHi I am completely new to javascript, in fact just started loooking at it on w3 this week, anyhow thought I would do my first script. The script creates three random numbers between 1 and 10 but makes sure that they are completely different. It works, which is great as I have set out to achieve what was desired, however could somebody have a look and tell me if I have gone about it the right way. Code: <script type="text/javascript"> var one = (Math.floor(Math.random()*10+1)); document.write("1. " + one + "<br />"); do { var two = (Math.floor(Math.random()*10+1)); } while (two == one) document.write("2. " + two + "<br />"); do { var three = (Math.floor(Math.random()*10+1)); } while (three == two || three == one) document.write("3. " + three + "<br />" + "<br />"); </script> Thanks in advance. Joel I'll be the first to admit, I am not skilled with javascript, but I can do a little work here and there. I remember learning there is a way to detect a user's/viewer's browser. Is there a possible javascript that allows me to detect a viewer's browser, the based on the browser, selects css/html to use so that the website is viewed correctly?
Hi all, I am new to CodingForums.com as well as new to javascript. I am currently trying to create a small calculator for a friend which is to do with calculating a dose. The calculator itself works but I am now fine tweaking the text that appears with the calculated values. This is my code: Code: <script type="text/javascript"> function calculate() { var IBW = 1; var IBW2 = 1; var dose2 = 1; var CrCl = 1; var hgtft = document.getElementById("height_feet").value - 0; var hgtinches = document.getElementById("height_inches").value - 0; var weight = document.getElementById("weight").value - 0; var sex = document.getElementById("sex").value; var age = document.getElementById("age").value - 0; var creatinine = document.getElementById("creatinine").value - 0; if (age < 16) { alert("This tool is only for use in adult patients i.e. 16 years or older"); return; //process no further } if (sex == "M") { if (hgtft < 5) { IBW = 50; IBW2 = 50; } else { IBW = 50 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); IBW2 = 50 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); } if (IBW > weight) { IBW = weight } CrCl = ((140 - age) * IBW * 1.23) / creatinine; } else { if (hgtft < 5) { IBW = 45; IBW2 = 45; } else { IBW = 45 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); IBW2 = 45 + (2.3 * ((hgtft - 5) * 12 + hgtinches)); } if (IBW > weight) { IBW = weight } CrCl = ((140 - age) * IBW * 1.04) / creatinine; } var dose = Math.round((5 * IBW) / 40.0) * 40.0 var IBW = Math.round(IBW, 1) var IBW2 = Math.round(IBW2,1) var CrCl = Math.round(CrCl, 0) if (CrCl < 40) { dose2 = "As GFR < 40mL/min Extended Interval Gentamicin is not indicated. Contact microbiology for an alternative agent"; } else { dose2 = dose "mg - Note: This dose has been calculated using a weight of " IBW "kg and rounded to the nearest 40mg to aid administration"; } document.getElementById('IBW2').innerHTML = IBW2 + "kg"; document.getElementById('CrCl').innerHTML = CrCl + "mL/min"; document.getElementById('dose2').innerHTML = dose2; } </script> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <table> <tr> <td>Height</td><td class="style17"><input id='height_feet' value=""/> feet</td><td><input id='height_inches' value=""/> inches</td> </tr> <tr> <td>Weight</td><td class="style17"><input id='weight' value=""/> kg</td> </tr> <tr> <td>Age</td><td class="style17"><input id='age'value=""/> years</td> </tr> <tr> <td>Creatinine</td><td class="style17"><input id='creatinine'/> mmol/L</td> </tr> <tr> <td>Sex</td><td class="style1"><select id='sex'> <option value="M">Male</option><option value="F">Female</option></select></td> </tr> </table><br /> <input type="button" onclick="calculate()" value="Calculate!"/><input id="Reset" type="reset" value="Reset" /> <br /> <br /> <br /> <br /> <table> <tr><td class="style16">Ideal Body Weight: </td><td id='IBW2' /></td></tr> <tr><td class="style16">Calculated GFR: </td><td id='CrCl' /></td></tr> <tr><td class="style16">Calculated Gentamicin Dose: </td><td id='dose2' /></td></tr> </table> What I am trying to do is have the dose displayed as: xxdose mg - Note: This dose has been calculated using a weight of IBWkg and rounded to the nearest 40mg to aid administration but if the CrCl is less than 40 then the dose message should be: As GFR < 40mL/min Extended Interval Gentamicin is not indicated. Contact microbiology for an alternative agent can anyone help me with this please? I am in a Mobile App Dev class. Our current project is to create a webapp that allows a user to search for zip,city,etc and get back weather and news. I am having some issues in that my code is not working. Anyone have a moment to check it out? Quote: <!-- --> <!DOCTYPE html> <html lang="en-us"> <head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script type="text/javascript"> function geo() { navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude);}); } function top_stories(o) { var items = o.query.results.item; var output = ''; var no_items=items.length; for(var i=0;i<no_items;i++) { var title = items[i].title; var link = items[i].link; var desc = items[i].description; output += "<h3><a href='" + link + "'>"+title+"</a></h3>";// + desc + "<hr/>"; } // Place news stories in div tag document.getElementById('results').innerHTML = output; } function cb_weather(yql) { var temp = yql.query.results.channel.item.description; var region = yql.query.results.channel.location.city +", "+ yql.query.results.channel.location.region; document.write("<H3>"+ region +"</H3>" +temp); } function save(zipcode) { localStorage.zipcode = zipcode.value; alert("Zip code is " + localStorage.zipcode); } </script> <title>Mobile Local</title> </head> <body> <div data-role="page" id="menu"> <div data-role="header" data-theme="b"> <h1>Mobile Local</h1> <a data-role="button" class="ui-btn-left" onclick="geo();">Locate Me!</a> </div> <div data-role="fieldcontain" data-inline="true"> <label for="name">Enter your location:</label> <input type="text" name="zipcode" id="zipcode" value="" /> <a data-role="button" onclick="save(zipcode); return false;" value="Save Data" />Search</a> </div> <div data-role="content" id='weather'> <script id="weather" src='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D02446&format=json&callback=cb_weathe r'></script> </div> <div data-role="content" id='results' onload="geo()"> <script src='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%20%3D%20"http%3A%2F%2Fnews.google.com%2Fnews%3Fgeo%3D024 46%26output%3Drss"&format=json&diagnostics=true&callback=top_stories'></script> </div> </div> </body> </html> Hello, i wrote this code to open a page if doesn't exist a cookie but it doesn't open the page do you know where I wrong? Thank you ! 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> <title> HTML </title> </head> <body> <script type="text/javascript"> function CookieLeggi(CookieNome) { if (CookieNome.length==0) return null; var PosizioneIniziale = document.cookie.indexOf(CookieNome+"="); if (PosizioneIniziale == -1) return null; PosizioneIniziale += CookieNome.length+1; var PosizioneFinale = document.cookie.indexOf(";",PosizioneIniziale); if (PosizioneFinale == -1) PosizioneFinale = document.cookie.length; return unescape(document.cookie.substring(PosizioneIniziale,PosizioneFinale)); } function CookieScrivi(name,value,expiresUdM,expires,path,domain,secure) { if (!name || !value) { return false } if ((expiresUdM && expires) && (expiresUdM!='GMT')) { var ExpiresMillisec = ExpiresDate = Oggi = new Date(); switch (expiresUdM) { // calcola i JS-millisecondi del momento di scadenza case "anni": ExpiresMillisec=Oggi.getTime()+expires*365*24*60*60*1000; break; case "mesi": ExpiresMillisec=Oggi.getTime()+expires*31*24*60*60*1000; break; case "giorni": ExpiresMillisec=Oggi.getTime()+expires*24*60*60*1000; break; case "ore": ExpiresMillisec=Oggi.getTime()+expires*60*60*1000; break; case "minuti": ExpiresMillisec=Oggi.getTime()+expires*60*1000; break; case "secondi": ExpiresMillisec=Oggi.getTime()+expires*1000; break; default: ExpiresMillisec=Oggi.getTime()+expires; } ExpiresDate.setTime(ExpiresMillisec); expires = ExpiresDate.toGMTString(); } secure = (secure=="1" || secure==1 || secure=="secure") ? 1 : ""; document.cookie = name + "=" +escape(value) + ( (expiresUdM && expires) ? "; expires=" + expires : "") + ( (path) ? "; path=" + path : "") + ( (domain) ? "; domain=" + domain : "") + ( (secure) ? "; secure" : ""); if (CookieLeggi(name)==null && secure!=1) { return false; } else { return true; } } </script> <script type="text/javascript"> if (CookieLeggi(liveads) == "null") { window.open("http://www.google.com", "Google"); CookieScrivi(liveads, adsm, ore, 12, /, .localhost, 1); } else { break; } </script> </body> </html> Hello, I need help. I'm testing aps.net controls. I have add Repeater with some content. Repeater is inside of Panel which has Vertical ScrollBars. Timer1 is updating Repeater. As I need scrollbar on PageLoad on the bottom of Panel control, I have add javascript. But, now problem is each time when try to move scrollbar up, Timer push it down. But, I would like somehow to keep in position if move it. I have try it with javascript code OnMouseOver with _StopTimer, but it effect only when mouse is over asp.net cotrol, not it's scrollbar. Any idea? Note: I have been Googling, Yahooing many ours, and try different codes, but none was working. So, really need some new approach. Note: MaintainScrollPositionOnPostback="true" is already added on page. Thank you in advance for help. Code: <asp:ScriptManager ID="ScriptManager1" runat="server"/> <script type="text/javascript"> if (Sys != null) { var instance = Sys.WebForms.PageRequestManager.getInstance(); if (instance != null) { instance.add_endRequest(function (sender, args) { SetScroll() }); } } function pageLoad() { window.onload = SetScroll; } function SetScroll() { var objDiv = document.getElementById("<%=Panel1.ClientID%>"); objDiv.scrollTop = objDiv.scrollHeight; } </script> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="1000"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> <asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Height="193px" Width="467px" BorderColor="#66CCFF" BorderStyle="Solid" BorderWidth="1px"> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <div style="font-family: calibri; color: #000099;"> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> TEST </BR> </asp:Repeater> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> </asp:Panel> I am very new to coding, trying to teach myself some javascript. I know this is a very simple code, I just can't seem to nail down what is going wrong. Feeling really stupid right now. Heres the code: Code: <html> <head> <script language="JavaScript"> var choice=confirm("Press ok for black. Press cancel for red."); if (choice==true){ document.bgColor="yellow"; document.fgColor="black"; } else { document.bgColor="red"; document.fgColor="white"; } </script> <body> <p>words</p> </body> </html> If someone could take a second to set me straight, I would really appreciate it. btw: hope I posted all this according to the "rules". I tried On this webpage http://www.corkdiscos.com/testimonials.html i have a like button. when a user clicks like a comment box appears. when i unlike the button the comment box disappears this is ok but when a user has already liked the facebook page and comes to my webpage the comment box does not show. so im looking for a piece of javascript to check if a user has like the button on my page and if so to show the comment box. please check my source code of the website http://www.corkdiscos.com/testimonials.html to see what i have so far. any help would be greatly appreciated Hi guys. I'm working a bunch of pre existing code on a CMS. Just after a quick fix. Doing a show/hide thing on a particular div somewhere on the page depending if a checkbox is ticked or not. Currently there is 3 checkboxes that are dynamically added through the CMS. Here's simplified version of the form: Code: <form id="simplesearch" name="simplesearch"> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="5" class="input-checkboxes" /> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="4" class="input-checkboxes" /> </form> And here's the javascript I was playing with. Code: function showhidefield(id) { if(document.simplesearch.meta_data_array_search_criteria[custom_profile_type][''].checked) { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "visible"; } else { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "hidden"; } } Problem I'm having is how do i do a check to see if those checkboxes are checked in the javascript with those name arrays? How do i separate them? 'm guessing I have to loop through them or something?Hopefully that make senses - it's late here and I'm losing the plot Any pointers would be gratefully welcomed This post will contain a few guidelines for what you can do to get better help from us. Let's start with the obvious ones: - Use regular language. A spelling mistake or two isn't anything I'd complain about, but 1337-speak, all-lower-case-with-no-punctuation or huge amounts of run-in text in a single paragraph doesn't make it easier for us to help you. - Be verbose. We can't look in our crystal bowl and see the problem you have, so describe it in as much detail as possible. - Cut-and-paste the problem code. Don't retype it into the post, do a cut-and-paste of the actual production code. It's hard to debug code if we can't see it, and this way you make sure any spelling errors or such are caught and no new ones are introduced. - Post code within code tags, like this [code]your code here[/code]. This will display like so: Code: alert("This is some JavaScript code!") - Please, post the relevant code. If the code is large and complex, give us a link so we can see it in action, and just post snippets of it on the boards. - If the code is on an intranet or otherwise is not openly accessible, put it somewhere where we can access it. - Tell us any error messages from the JavaScript console in Firefox or Opera. (If you haven't tested it in those browsers, please do!) - If the code has both HTML/XML and JavaScript components, please show us both and not just part of it. - If the code has frames, iframes, objects, embeds, popups, XMLHttpRequest or similar components, tell us if you are trying it locally or from a server, and if the code is on the same or different servers. - We don't want to see the server side code in the form of PHP, PERL, ASP, JSP, ColdFusion or any other server side format. Show us the same code you send the browser. That is, show us the generated code, after the server has done it's thing. Generally, this is the code you see on a view-source in the browser, and specifically NOT the .php or .asp (or whatever) source code. I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files F:\Textbooks.html F:\eBooks.txt F:\FirstBook.txt F:\SecondBook.txt F:\ThirdBook.txt textbooks.html is my DHTML app eBooks.txt is the Library file with a listing of all of my eBooks. Inside of eBooks.txt is the following data: ----------------- FirstBook.txt, SecondBook.txt, ThirdBook.txt, ----------------- FirstBook.txt to ThirdBook.txt are my actual ebooks. The problem that i'm having is that When i try to click on any buttons other than the FirstBook button, i get the following error: ---------------------------------- Error: unterminated string literal Source File: file:///F:/Textbooks.html Line: 1, Column: 10 Source Code: LoadEbook(' ---------------------------------- So, unlike clicking on the FirstBook button, these other buttons do not load the eBook data into the DIV for displaying the eBook data. I use the DOM insepector to checkout the DOM of the button code, and it seems like whitespace maybe is the problem. However, i have removed whitespace from the HTMLdata string, and that's not fixing the problem. did i forget something silly? LOL i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers. here is my HTML code: <html> <head> <script language="JavaScript"> var eBookLibrary = "eBooks.txt"; var SystemPath = "f:" + String.fromCharCode(92) function Init() { // Initialize the eBook reader document.getElementById("EbookCanvas").style.visibility = "hidden"; document.getElementById("EbookToolbar").style.visibility = "visible"; document.getElementById("FileManager").style.visibility = "visible"; // Load the List of eBooks in the Library LoadBookList(); } function UpdateEbookList() { // Update the Library of Ebooks alert("Updating eBook Library"); // Go back to the File Manager, and Reload the List of Ebooks LoadBookList(); } function LoadBookList() { // This will load the list of books that are available var EbookList = LoadFromDisk(SystemPath + eBookLibrary); var EbookListArray = EbookList.split(","); for(var x = 0; x < EbookListArray.length -1; x++) { // Strip the Filename Extension off of the eBook File Name // The Name of the Book is always the first Index in the Array var BookName = EbookListArray[x].split("."); // Remove the weird whitespace - it screws things up...i think... BookName[0] = BookName[0].replace(/(^\s*|\s*$)/g, ""); var HTMLdata = HTMLdata + "<input type='button' value='" + "FirstBook" + "'" + " onClick=LoadEbook('" + EbookListArray[x] + "');><br>"; } // For some ****ed up reason the first string always generates an 'undefined' even though it's nonsense // So just delete that from the HTMLdata string, because it's just ugly - LOL HTMLdata = HTMLdata.replace("undefined", ""); HTMLdata = HTMLdata.replace("", " "); // Write the HTML data to the DIV document.getElementById("FileManager").innerHTML = HTMLdata; } function LoadEbook(EbookName) { // Hide the File Manager and Show the Ebook Canvas document.getElementById("FileManager").style.visibility = "hidden"; document.getElementById("EbookCanvas").style.visibility = "visible"; document.getElementById("EbookToolbar").style.visibility = "visible"; // Load the Ebook content into the Ebook Reader Pannel var EbookContent = LoadFromDisk(SystemPath + EbookName); document.getElementById("EbookCanvas").innerHTML = EbookContent; } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } </script> </head> <body onLoad="Init();"> <div id="FileManager" style="position: absolute; top: 0px; left: 0px; visibility: visible;"> The eBook Library's List of Books will be listed here. Click on one to open it in the eBook Reader </div> <br> <div id="EbookCanvas" style="position: absolute; top: 0px; left: 0px; visibility: hidden;"> </div> <br> <div id="EbookToolbar" style="position: absolute; top: 100px; left: 0px;"> <input type="button" value="Open" OnClick="Init();"> <input type="button" value="Update" OnClick="UpdateEbookList();"> <input type="button" value="Exit" OnClick="MainMenu();"> </div> </body> </html> Hi all, I hope someone can advise whether such a script exists for what am wanting to do. From time to time, I need to send password information or login details and password information to some users. At the moment, am doing it via email with a subject named FYI and the body of the email basically just contain the login and the password or in some case, just the password. What am wanting to know is whether I can put these information into a HTML file which contains an obfuscated Javascript with a button that a user will click that will prompt for his login information and then will display the password. In its simplest form, I guess I am looking for a Javascript that will obfuscate a HTML file that contains the password. Anyway, hopefully someone understand what am looking for. I found some website that offers such service as obfuscating a HTML file but am hoping it can be done via a Javascript so it is at least "portable" and I do not have to be online. Any advice will be much appreciated. Thanks in advance. I have a text input box that resets to blank when the user enters an alpha character, it also checks for the number 0 as it has to be greater than 0 too... when I submit the form it is blank the variable changes to blank (as I use parseInt to convert it to an integer at a later stage) What can I do to check and see if it is NaN value? (I've tried isNaN() and it did not do what I wanted it to) this code is supposed to ask the users name and say how many letters in it get 2 random numbers ask user to add them if right say Well Done! if wrong say Sorry, you are wrong. when i run this nothing comes up whats wrong? thanx Code: <script> var firstName = ""; var numLetters = 0; firstName = prompt("Hi, what's your first name?", ""); numLetters = firstName.length; alert ("Did you know there are " + numLetters + " letters in your name?"); var num1 = Math.floor(Math.random()*9) + 1; var num2 = Math.floor(Math.random()*9) + 1; var answer; var useranswer; answer = num1+num2; useranswer = promt("What is" + num1 + "+" + num2 + "?"); If (answer = useranswer) { alert("Well done!"); } else { alert("Sorry, you are wrong."); } </script> plz check bold part of function is not working. what is wrong with it.? Code: function onesizecheck(chk_id,siz) { alert(chk_id); if(document.getElementById('siz_check').value=='') { document.getElementById('siz_check').value=siz; }//end if if(document.getElementById('siz_check').value==siz) { document.getElementById('siz_check').value=siz; } else { alert('Multi size are not allowed.'); for(var i = 0; i < document.delet['checkbox[]'].length; i++){ var cb = document.getElementById('checkbox'); alert(cb[i].value); } } }//end function Dear all, The code below puts a link in mydiv when the page loads if myvar equals 1. Great till here, but if myvar changes its value and it does not equal 1 any more I have to reload the page in order not to see the link. What do I have to do to avoid that reload? what do I have to do to check myvar's value for changes constantly? Thanks in advance! Code: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script> <script> var myvar=1; function func1() { if (myvar==1){ var putit=""; putit +="<a href='#'>Put this link</a>"; $("#mydiv").html(putit); } } function addLoadEvent(func) { $(window).load(func); } addLoadEvent(func1); </script> </head> <body> <div id="mydiv"></div> Hi, I'm trying to create a test using Javascript. Actually, I did this in PHP, but we need to put it a server that does nor run it, I think I can convert it to Javascript. I hope it'll be work as in PHP somehow. Test will be composed of 15 questions and each question has either "Yes" or "No" as answer. And, I use radio buttons here for answers. By the way, there will be more than one radio groups. Now, I want to check the value of clicked radio button in each group and use an if-statement to determine if it's correct. And, if it's correct, I want to increment a variable by 1. Finally, by the resulted variable incremented for each question in the test, I want to use another if-statement to show specific result message for and interval of that variable. I tried this for one radio button like this: Code: <script language="JavaScript"> function get(form) { var ans1 = document.form.q1; var score = 0; for( i = 0; i < ans1.length; i++ ) { if( ans1[i].checked && ans1[i].value == no ) { score++; alert(score); } else {alert(score);} break; } } </script> <form name="form" method="get"> <input type="radio" name="q1" value="yes">Yes <input type="radio" name="q1" value="no">No* <input type="button" name="button" value="button" onclick="get(this.form)" /> </form> By the code above, it should alert 1 if "No" is checked and button is clicked and alert 0 if "Yes". This was a preliminary job for me to understand. And I couldn't do even this. Thank you. I am trying to get a link that when clicked it will check all the checkboxes in my form. My problem is that my values are stored in an array: <INPUT TYPE=\"checkbox\" name=\"emailArray[]\" value=\"$email\"> print"<br><a href=\"#\" onClick=\"checkAll()\">check all</a><br>"; Here is my javascript function : function checkAll(){ alert('hi'); var df = document.selectEmailForm.elements; for (var i = 0; i < df.length; i++) { if (df[i].name == "emailArray[]" ) { document.selectEmailForm.emailArray[i].checked=true; } } } Any ideas? Any help is greatly appreciated. Thanks for your time! Hi, I am not familiar with javascript, I am using a check box validation tool that I copied from this site: http://mediazeal.com/checkbox-validator.htm This is my webpage: http://rbhlc.weebly.com/discover-hea...n-jyutsu.html# Right now when you click the buy now button (when the checkbox is checked) i does not go to the hyperlink. How can I get the button to go to my link when the checkbox is validated? Here is my code: (the authorize.net account it a Test Account.. so it won't link to anything sensitive) <form name="form" method="post" action="#" onSubmit="return checkme();"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td colspan="2" align="center"><input type="checkbox" name="agree" value="agree_terms"> I agree to the terms</td> </tr> <tr> <td colspan="2" align="center"> <form name="PrePage" method = "post" action = "https://scotest.authorize.net/payment/CatalogPayment.aspx"> <input type = "hidden" name = "LinkId" value ="3569f626-b8a8-4974-8ceb-35ca08a63087" /> <input type = "image" src ="//testcontent.authorize.net/images/buy-now-gold.gif" /> </form> </td> </tr> Thank you for your support. i have an assignment to solve in which i have given two checkboxes one is enabled and another one is disabled n m required that if we select enable checkbox the disabled checkbox may also be selected automatically can any one help out for its coding please Thanks |