JavaScript - Randomizing Quiz Question & Code Needed
Hey folks,
Forgive me in advance if this is not the correct place to post this thread. I am a new member to this forum and need a little assistance. I have some script to create a quiz but need a little more detail. Does anyone know some code I can insert, and where to randomize the questions. Secondly if I have a test bank of 100 questions but want to limit the test to 20 questions what code would I need to insert that as well. Any assistance is very much appreciated. thank you. kenster Similar TutorialsHi, im trying to make a quiz. Now, what I have realized is that I can make a random number coincide with a question. But then I'd have to do a huge amount of if statements. Is there a MUCH simpler way of doing this? And also the questions CAN NOT repeat. Please try and keep it simple, as I'm trying to learn. There's 10 questions by the way. Thanks in advance! Hey guys, basically Im creating a webpage for my univeristy degree, and I've decided to script a quiz, basically there will be several multi choice questions, and these will add to one answer, heres an example: Whats your favourite genre of music? (choice1) (choice2) (choice3) Whats your favourite favourite musical instrument? (choice1) (choice2) (choice3) etc answer = blahblahblah Heres my questions code here, as you can see im using values, im trying to create the answers by adding the values up, for example answer 1=5 2=10 3=100 <div id="quiz"> <h4> 1) What is your favourite genre of music?</div> <div class="qselections"> <input type="radio" value="1" name="question1">a)Rock<br> <input type="radio" value="2" name="question1">b) Punk<br> <input type="radio" value="3" name="question1">c) Metal<br> <input type="radio" value="4" name="question1">d)Electronica/Dance/Club<br> </div> <br> <div class="qheader"> 2) What is your favourite decade of music></div> <div class="qselections"> <input type="radio" value="1" name="question2">a) 60's<br> <input type="radio" value="2" name="question2">b) 70's<br> <input type="radio" value="3" name="question2">c) 80's<br> <input type="radio" value="4" name="question2">d) 90's<br> <input type="radio" value="5" name="question2">d) 00's<br> </div> <br> <div class="qheader"> 3) Which is your favourite instrument?</div> <div class="qselections"> <input type="radio" value="1" name="question3">a) Guitar<br> <input type="radio" value="2" name="question3">b) Drums<br> <input type="radio" value="3" name="question3">c) DJ Decks<br> <input type="radio" value="4" name="question3">d) Piano<br> </div> <br> <div class="qheader"> 4) Do you prefer handheld or console?</div> <div class="qselections"> <input type="radio" value="1" name="question4">a) Handheld<br> <input type="radio" value="100" name="question4">b) Console<br> <h4> </div> Im just curious how to script this? I havent done anything this difficult before, Im wondering how I would code this.. The only quiz I have done before is via prompts, any help will be much apprieciated! P.s feel free to ask any questions if it is to help! I need to comment on my code. I did what i can but i have been told that it is still not enough. can anybody help me with this one ? < Code: <HTML> <HEAD> <TITLE>SIMPLE QUIZ ON ANIMAL ZOO</TITLE> <STYLE TYPE="text/css"> <!-- CSS code for my header --> BODY {text-align:center} </style> <script language="JavaScript"> // An Array is a special type of variable var x; // The letter x is used to hold a value and also expressions x = 0; //This states that variable x has value of 0. var Pictures = new Array(4); //It declares a variable to an array var Questions = new Array(4);//It declares a variable to an array var answers1 = new Array (); // It declares a varibale to an array var answers2 = new Array (); // It declares a varibale to an array var answers3 = new Array (); // It declares a varibale to an array var answers4 = new Array (); // It declares a varibale to an array var correctanswers = new Array(4); var score = 0; // It keeps the pathway of the score var userans = new Array (4);//The variable is declaring new array var incorr = 0; var isChecked = false; //The variable is defined as boolean by giving an initial value of false Pictures[0] = "Pic/1.jpg"; // These are the pictures for the quiz Pictures[1] = "Pic/2.jpg"; Pictures[2] = "Pic/3.jpg"; Pictures[3] = "Pic/4.jpg"; Pictures[4] = "Pic/5.jpg"; Questions[0] = "Which is the biggest shark?"; // These are the questions Questions[1] = "How much can tiger weighs?"; Questions[2] = "What colour are skunks?"; Questions[3] = "Why do red-eyed tree frogs have big red eyes? "; Questions[4] = "Which family of animals does the chimp belong to?"; answers1[0] = "Tiger shark"; // These are the answers for text box1 answers1[1] = "200 kilos"; answers1[2] = "Red and white"; answers1[3] = "To look like plants"; answers1[4] = "Apes"; answers2[0] = "Great white Shark"; // These are the answers for text box2 answers2[1] = "300 kilos"; answers2[2] = "Blue and Yellow"; answers2[3] = "To have better view at their food"; answers2[4] = "Monkey"; answers3[0] = "Grey reef shark"; // These are the answers for text box3 answers3[1] = "360 kilos"; answers3[2] = "Black and white"; answers3[3] = "To look far"; answers3[4] = "Gorilla"; answers4[0] = "Hammerhead shark"; // These are the answers for text box4 answers4[1] = "420 kilos"; answers4[2] = "Green"; answers4[3] = "To scare the predators"; answers4[4] = "Chimpanzee"; correctanswers[1] = 2; // These are the correct answers for the questions. correctanswers[2] = 3; correctanswers[3] = 3; correctanswers[4] = 4; correctanswers[5] = 1; function Next(){ //It calls the function "Next" for (i=0; i<document.Form.answer.length; i++) { if (document.Form.answer[i].checked==true) isChecked = true; } if (isChecked==false) alert ("Please Select an Answer"); else { for (var i=0; i<document.Form.answer.length; i++) { if (document.Form.answer[i].checked==true){ userans[x]= i + 1; //document.Form.answer[i].checked = false; } } if (userans[x]==correctanswers[x]) alert ("This is the correct answer"); else alert ("This is not the correct answer"); //alert (document.Form.answer[i].value); //alert (userans[x]); Picture(); } } /* The code below calls the function Picture. The code below does the following: Adds score if the answer is right */ function Picture() { if (x==5){ for (var k=0; k<5; k++) { if (userans[k]==correctanswers[k]) { score = score + 1 } else { incorr = incorr + 1 } } alert("The score is " + score + " \n \n Correct Answers a \n \n 1. Great white shark \n 2. 360 Kilos \n 3. Black and white \n 4. To scare the predators \n 5. Apes" ); } else{ //The code will display the pictures, questions and answers in the browser document.Pic.src=Pictures[x]; Form.questions.value = Questions[x]; // It shows the questions inside the form in text Form.text1.value=answers1[x]; // It shows the answers1 inside the form in text1 Form.text2.value=answers2[x]; // It shows the answers2 inside the form in text2 Form.text3.value=answers3[x]; // It shows the answers3 inside the form in text3 Form.text4.value=answers4[x]; // It shows the answers4 inside the form in text4 x = x + 1; } isChecked = false for (i=0; i<document.Form.answer.length; i++) { document.Form.answer[i].checked=false; } } function Restart() //This code is used for "Restart" button which will restart the quiz to the beginning. { location.reload(true); } // When the page loads this code will dispaly the first Questions and Pictures and it will carry on. </script> </HEAD> <BODY> <BODY BODY BGCOLOR="Maroon"> <FONT FACE="ARIAL" Size="+3" COLOR="GOLD"> <CENTER><B><U> SIMPLE QUIZ ON ANIMAL ZOO </U></B></CENTER> <br> </FONT> <BLOCKQUOTE> <FONT FACE="ARIAL" Size="+1" COLOR="BEIGE"> <body onload="Picture()"> <form name="Form"><br> <img name="Pic" src="Pic/1.jpg" width="130" height="140" /> <br> <br> <input type="text" size="90" height="250" name="questions" /><br /><br /> <input type="radio" name="answer" value="1" /><input name = "text1" size="45 height ="250"/><br /> <br /> <input type="radio" name="answer" value="2" /><input name = "text2" size="45 height ="250"/><br /><br> <input type="radio" name="answer" value="3" /><input name = "text3" size="45 height ="250"/> <br> <br /> <input type="radio" name="answer" value="4" /><input name = "text4" size="45 height ="250"/> <br><br> <input name="return" Type=Button Value=" Restart " onclick="Restart()"> <input name="Submit" Type=Button Value=" Next " onClick="Next()"> </form> </body> </html> JavaScript code responsive quiz I live in turkey. Can you write me such a code for my site? I have five DIV tags that contain a photo and brief bio for partners of an accounting firm. I need to randomize these DIV tags (id="d1" - "d5") to display only one of the tags on each page load. Normally, I would do this with ColdFusion but the client isn't willing to purchase the language support for their hosting system. A sample of one of the DIVs is below. Code: <div id='d1'> <div class="subhead1">Shareholder Spotlight</div> <img style="float:left;margin:12px 10px 0px 0px" src="images/leonard_summer_photo.jpg"> <div class="subhead2">Leonard M. Sommer, CPA</div> <div class="subhead3">Managing Shareholder</div> <div class="body">Leonard has more than 30 years experience in providing tax, business and succession planning advice for family-owned and closely-held businesses. <a href="leonardsommer.html" style="color:#3d3d3d; text-decoration:underline">Learn more</a>.</div> </div> If someone could let me know how to do this in javascript I would appreciate it. You'll have to be very clear in your instructions as I don't know javascript very well. Thank you in advance for your response! hello, can anyone suggest a solution to get the following: there are 3 folders each containing own set of images. clicking on the button you get a random combination of 3 images, each coming from different folder. that wont be a problem to find a javascript using xml list of images. but if I'm going to add some images later, php will be the better solution, if i don't want to update xml each time. there are plenty of examples using pure php to get and random images as well. but i need php solely to check all three folders on page load, grab them in three arrays an pass these 3 arrays to javascript, so it can random them on demand. i wonder if there is a simple solution for that, that would be understandable for a beginner in js and php? thanx, A single letter is taken from each word in the sentence. Unlike before, either the first or last letter is taken. The letter taken is decided by which of the first or last is "greater" (e.g. "b" > "a", "c" > "b", etc.) Here are some examples based on the above rules: "hello" translates to "o" because "o" is greater than "h". "goodbye" translates to "g" because "g" is greater than "e". Full sentence example: "wazdee apple love bic nooo more end" This sentence will decrypt to "welcome". Complete the decryptB function so that it decrypts messages with the new scheme. Here are some examples: var decryptB = function(message) { // Your code here } var result1 = decryptB("wazdee apple love bic nooo more end") console.log(result1) // This should be "welcome" var result2 = decryptB("bria loud fuzu antidote") console.log(result2) // This should be "blue" Reply With Quote 01-20-2015, 09:41 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts See the page http://www.codingforums.com/rules.htm See rule 1.5 We helped you way way too much the last time you asked the first variant of this homework problem. This is really a very simple variation on that. And you don't even include the final version of the code you used last time, so somebody who didn't see the last answers would have to start all over again. Not very friendly to potential responders. What have you *TRIED*? If you came running here without even trying to solve this, shame on you. At least show what you have tried and explain what results you get and, if you can, what you think is going wrong. By the way: How is the user supposed to output an "a" character? You need an answer to that question, methinks. I have a vendor delivered java script code that I am currently customizing. The original code involves a user when selects a "check box" option value , a small function is called titled "VerifyAcctType". Currently when a user selects the check box some values are defaulted into the form. Now to this function code below i have to add logic when user selects the same check box option FIRST a small pop up window should appear which lists two radio buttons"I Agree to terms" and "I do not agree to terms" options , user need to select one of the options in the pop up to proceed. If the user agrees to terms then the control should go back to the "VerifyAcctType" function and proceed with remaining steps like before else if the user selects "I do not agree" the logic should not proceed further in "VerifyAcctType" function. Here is the current code tied to VerifyAcctType function ============================================== function VerifyAcctType(win,type) { var AcctType var ThisWindow var ThisForm if (win == "ADD") { ThisWindow = AddAccountWind ThisForm = AddAccountWind.document.addform } else if (win == "CHG") { ThisWindow = ChangeAccountWind ThisForm = ChangeAccountWind.document.chgform } if (type == "P") { <<I NEED NEW CODE HERE FOR THE POPUP>> Maccttype = type ThisForm.description.value = "My Company" ThisForm.comp_id.value = "1234567" ThisForm.comp_id.disabled = true } else { Maccttype = type ThisForm.description.value = "" ThisForm.comp_id.value = "" ThisForm.comp_id.disabled = false } } I am a java script beginner , any help is appreciated. Hi I am new to programming and I am trying to write a piece of code, I need the output to be a whole random number, this is what I have up to now : <SCRIPT language = "JavaScript"> //generate a random number greater than or equal to 0.0 and less than 50.0 //and display it in an alert dialogue window.alert("getRoundedRandomNumber: " Math.round + Math.random()*50); </SCRIPT> </HEAD> <BODY> <STRONG>A test of the random number functions <BR></STRONG> <FORM NAME = "randomForm"> <INPUT TYPE = "button" NAME = "randomButton" VALUE ="Display Random Number" ONCLICK = "window.alert(getRoundedRandomNumber(50));"> </FORM> can anyone advise me where I would put the Math.round function and how to make it work ? Thanks in advance I am still learning javascript so forgive me if this question is a bad one, I am making scripts for Greasemonkey for a website I am a part of. One of the developers recently commented out (in the source code) a feature that was available before. It is a Football MMORPG game and it used to show college players 40 times but over the past month he commented out the tag that held the script function. I want to know if i can either A) write a js code that can remove the comment tag in the source code or B) write a code that will just add another tag under that and have that js function that was commented out valid. I tried something but ended up just having that function pasted onto the page instead of having it put into the source to have it read by the rest of the data.. here is what im talking about <TABLE width=800 cellspacing=0> <tr> <td colspan=3 style="FONT-SIZE: 11pt"> <b>Hometown:</b>Fort Hunt, VA<br> <b>Height:</b>6-0<br> <b>Weight:</b>206<br> <!--b>40 Time:</b><if rs("team_id")>0 or bRated then><=formatnumber(rs("forty"),2)><br><end if --> i just want to see if there was any way to just delete the comment out of it so i can get this feature again is all. Any help would be awesome... and sorry for the long post Hello everyone. I have been trying 2 days straight to figure out how to make this script work. Basically I am trying to have a hidden checkbox with a drop down menu. I want the user to be able to choose 0-9 where 0 the check box will not be checked and 1-9 if picked from the dropdown menu it will automatically check the hidden box. Here is the closest string of code I could find out there to help me figure it out but I am having no luck. The closest I got was....well I never really figured out how to make it work. Can someone please help me? Thanks. <script type="text/javascript"> function checkUncheck (selected) { var checkBox = document.getElementById("box"); if ((selected == 2) || (selected == 3)) { checkBox.checked = "checked"; } if ((selected == 0) || (selected == 1)) { checkBox.checked = "false"; } } </script> <form id="frm"> <table> <tr> <td><input type="checkbox" id="box" checked="false"/></td> <td> <select id="sel0" onchange="checkUncheck(this.selectedIndex)"> <option value="zero">zero</option> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> </select> </td> </tr> </table> </form> Can someone please suggest a good (and simple) code for password protecting one page on a site? I have a plan room for blueprints on my site. There will be multiple jobs at a given time and I need a page where we can give out a password to get the plans. Once the person logs in with user name and password for that day, he would then see file folders with the name of each job next to it. When he chooses a job, he clicks the folder to display a list of plans. If you can help with this or point me in a good direction, it would be greatly appreciated. Thanks for your help! hey guys. i need a js code that redirects to a flash page or to a non flash page after detecting the browsers plugin abilities and if it has flash or not. any help would be appriciated. cheers Hi everyone, im no expert in coding but i manage to get this bit of code together using some free source stuff and put in the links to my images ect, the problem now is i need each picture to be different sizes and each one to have a clickable link but i am completely stumped heres the code Code: <html> <head> <script type="text/javascript"> <!-- var image1=new Image() image1.src="http://gohelp.org.uk/wp-content/uploads/2011/05/Charity-Rallies-World.png" var image2=new Image() image2.src="http://gohelp.org.uk/wp-content/uploads/2011/05/ROTW-logo.jpg" var image3=new Image() image3.src="http://gohelp.org.uk/wp-content/uploads/2011/05/Mongolia-Charity-Rally-Logo-Transparent.png" //--> </script> </head> <body> <center><img src="http://gohelp.org.uk/wp-content/uploads/2011/05/Charity-Rallies-World.png" name="slide" width="150" height="68" /></center> <script> <!-- //variable that will increment through the images var step=1 function slideit(){ //if browser does not support the image object, exit. if (!document.images) return document.images.slide.src=eval("image"+step+".src") if (step<3) step++ else step=1 //call function "slideit()" every 2.5 seconds setTimeout("slideit()",2500) } slideit() //--> </script> </body> </html> I want to insert a link into an email that opens a new window of a specific size. All of the scripts I find require some code to be inserted into the <head> tag of the page. Obviously this will not work since I am inserting the link into an email. Is there a JavaScript code for opening a popup window that's not dependent on <head> code?
This is the code that I'm presently using: Code: <script language="JavaScript" type="text/javascript"> <!-- function Cal(obj){ var total=0; var ticked=0; for (var zxc0=1;zxc0<obj['B'].length;zxc0++){ if (obj['B'][zxc0].checked){ total+=obj['B'].length-1; ticked+=zxc0; } } for (var zxc1=1;zxc1<obj['C'].length;zxc1++){ if (obj['C'][zxc1].checked){ total+=obj['C'].length-1; ticked+=zxc1; } } for (var zxc2=1;zxc2<obj['D'].length;zxc2++){ if (obj['D'][zxc2].checked){ total+=obj['D'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['E'].length;zxc2++){ if (obj['E'][zxc2].checked){ total+=obj['E'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['F'].length;zxc2++){ if (obj['F'][zxc2].checked){ total+=obj['F'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['G'].length;zxc2++){ if (obj['G'][zxc2].checked){ total+=obj['G'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['H'].length;zxc2++){ if (obj['H'][zxc2].checked){ total+=obj['H'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['I'].length;zxc2++){ if (obj['I'][zxc2].checked){ total+=obj['I'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['J'].length;zxc2++){ if (obj['J'][zxc2].checked){ total+=obj['J'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['K'].length;zxc2++){ if (obj['K'][zxc2].checked){ total+=obj['K'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['L'].length;zxc2++){ if (obj['L'][zxc2].checked){ total+=obj['L'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['M'].length;zxc2++){ if (obj['M'][zxc2].checked){ total+=obj['M'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['N'].length;zxc2++){ if (obj['N'][zxc2].checked){ total+=obj['N'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['O'].length;zxc2++){ if (obj['O'][zxc2].checked){ total+=obj['O'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['P'].length;zxc2++){ if (obj['P'][zxc2].checked){ total+=obj['P'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['Q'].length;zxc2++){ if (obj['Q'][zxc2].checked){ total+=obj['Q'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['R'].length;zxc2++){ if (obj['R'][zxc2].checked){ total+=obj['R'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['S'].length;zxc2++){ if (obj['S'][zxc2].checked){ total+=obj['S'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['T'].length;zxc2++){ if (obj['T'][zxc2].checked){ total+=obj['T'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['U'].length;zxc2++){ if (obj['U'][zxc2].checked){ total+=obj['U'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['V'].length;zxc2++){ if (obj['V'][zxc2].checked){ total+=obj['V'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['W'].length;zxc2++){ if (obj['W'][zxc2].checked){ total+=obj['W'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['X'].length;zxc2++){ if (obj['X'][zxc2].checked){ total+=obj['X'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['W'].length;zxc2++){ if (obj['W'][zxc2].checked){ total+=obj['W'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['X'].length;zxc2++){ if (obj['X'][zxc2].checked){ total+=obj['X'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['Y'].length;zxc2++){ if (obj['Y'][zxc2].checked){ total+=obj['Y'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['Z'].length;zxc2++){ if (obj['Z'][zxc2].checked){ total+=obj['Z'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AA'].length;zxc2++){ if (obj['AA'][zxc2].checked){ total+=obj['AA'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AB'].length;zxc2++){ if (obj['AB'][zxc2].checked){ total+=obj['AB'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AC'].length;zxc2++){ if (obj['AC'][zxc2].checked){ total+=obj['AC'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AD'].length;zxc2++){ if (obj['AD'][zxc2].checked){ total+=obj['AD'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AE'].length;zxc2++){ if (obj['AE'][zxc2].checked){ total+=obj['AE'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AF'].length;zxc2++){ if (obj['AF'][zxc2].checked){ total+=obj['AF'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AG'].length;zxc2++){ if (obj['AG'][zxc2].checked){ total+=obj['AG'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AH'].length;zxc2++){ if (obj['AH'][zxc2].checked){ total+=obj['AH'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AI'].length;zxc2++){ if (obj['AI'][zxc2].checked){ total+=obj['AI'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AJ'].length;zxc2++){ if (obj['AJ'][zxc2].checked){ total+=obj['AJ'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AK'].length;zxc2++){ if (obj['AK'][zxc2].checked){ total+=obj['AK'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AL'].length;zxc2++){ if (obj['AL'][zxc2].checked){ total+=obj['AL'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AM'].length;zxc2++){ if (obj['AM'][zxc2].checked){ total+=obj['AM'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AN'].length;zxc2++){ if (obj['AN'][zxc2].checked){ total+=obj['AN'].length-1; ticked+=zxc2; } } for (var zxc2=1;zxc2<obj['AO'].length;zxc2++){ if (obj['AO'][zxc2].checked){ total+=obj['AO'].length-1; ticked+=zxc2; } } obj['Score'].value='Sco '+ticked+'/'+total; } //--> </script> However, what this piece of code does is that, every radio button gets only 1 point. What I intended is that every subsequent radio button in each <td> garners incremental points by 1. Eg: Q1, 1st radio button gets 0pt, 2nd radio button gets 1pt, 3rd radio button gets 2pt. Does anyone have any idea how to implement that, all help are greatly appreciated! I am looking for a javascript code for this idea under this message ---------------------------------------------------------------------------------------------------------------------------------------------------- I want to create a kind of shopping website so when you click on a image or text it will add some text to a textarea,, it will include the name of item and price of an item here is the html code that i have PHP Code: <td valign="middle" valign="middle"> <input type="radio" name="gender" id="genderM" value="Male" /> Male <input type="radio" name="gender" id="genderFM" value="Female" /> Female </td> and here is the js funtion PHP Code: var $j = jQuery.noConflict(); function isValidEmail(str) { return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); } function validateForm(){ var firstName; var lastName; var email; var mobile; var comment; var error; firstName = $j('#firstName').val(); lastName = $j('#lastName').val(); email = $j('#email').val(); mobile = $j('#mobile').val(); comment = $j('#comment').val(); if(firstName=='' || firstName.length < 3){ error = 'Please Enter Your First Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(lastName=='' || lastName.length < 3){ error = 'Please Enter Your Second Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } //mob //$jmob_pattern = '^\d{10}$j'; if(mobile.length != 10 || isNaN(mobile)){ error = 'Please Enter Your Mobile Number'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(email=='' || !isValidEmail(email)){ error = 'Please Enter Your Email Address'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(comment.length < 5){ error = 'Please Enter A Comment'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } return true; } Does anybody know how i check to see if the radio button is select and also can anybody tell me how i can check for an email in the correct format the function isValidEmail in the above alows emails to pass through if they are in this format aaa@aaa. i only want them to go through if they are aaa@aaa.com Thanks for your help if you give it |