JavaScript - Reading Cookies To Display Survey
I'm sorry I'm not to good at javascript. I know VB.net, but I have not learned javascript yet, and I need some help.
I am working on a project to get a survey to pop up for new visitors on the index page of our site. What I need to do: on load look for a cookie, if that cookie is not found run a script telling the site to pull up another page in lightview using its own "on load" command. If the cookie is there the site will not open this other page. What I've done: I already found a way to do most of this, but I can only use a hyper link as a trigger for the site to load the other page in lightview. Here is a link of what I have so far: http://naomi-dr.com/template2.html Please let me know if you have any questions or need more information. Similar TutorialsI've looked on several websites and several threads here regarding writing and reading cookies with javascript, and I just can't seem to get it to work. All I want is a simple text box with 2 buttons: Save and Recall. Text entered into box is saved to a cookie when "Save" is pressed, and at a later date when "Recall" is pressed the saved text will show up in the box. Can you help please? Hello guys, I'm trying to basically build a survey that validates gender and age, and with those variables display the correct products for them. The problem is that the variables are not passing to the functions and not displaying nothing. Please help in this, here's my code: <iframe> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head><!-- Localized --> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="robots" content="noindex,nofollow"> <title>Visitor Survey - Please Take A Minute...</title> <link href="survey_files/style.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="survey_files/jquery.js"></script> <script> var genero = null; var edad = null; function q1() { $('#q1').hide(); $('#q2').show(); } function q2() { $('#q2').hide(); $('#q2').show(); } function q2() { $('#q2').hide(); $('#loader').show(); setTimeout(showProducts, 1500); } function setgender(g) { if (g == 'f') { genero = 'f'; } if (g == 'm') { genero = 'm'; } function setage (a) { if (a == '1017') { edad = '1017'; } if (a == '1825') { edad = '1825'; } if (a == '2639') { edad = '2639'; } if (a == '40') { edad = '40'; } } function showProducts() { $('#loader').hide(); $('#products').show(); if ( genero == 'f' && edad == '1017') { document.getElementById('fgift').style.display = 'block'; } if ( genero == 'm' && edad == '1017') { document.getElementById('mgift').style.display = 'block'; } } } </script> <style> .hoverspan { background-color:transparent; color:#000000; } .hoverspan:hover { background-color:#D9D9D9; color:#000000; } .btn { cursorointer; } .clear{clear:both;} html, body { height:100%; padding:0; margin:0; background-color:#D8D8D8; } #wrapper { min-height: 100%; height: auto !important; height: 100%; } .footer, .push { height: 4em; font-size:10px; width:90%; line-height:14px; padding:20px; text-align:center; } </style> </head><body> <div id="wrapper" style="margin: 0pt auto;"> <div id="content"> <div id="header" style="margin-left: 50px; padding-top: 12px;"> <img src="survey_files/thankyou.png" alt="Thank You" title="Thank You" border="0"> </div> <div id="leftbox" style="width: 306px; height: 336px;"> <p class="header">Dear Visitor,</p> <p>You've been selected to take part in our anonymous survey. Complete this 30 second questionnaire, and to say "thank you", we'll offer you a few exclusive prizes including a WalMart or Best Buy Gift Card. </p><p><br>This offer is available today only: <strong><script language="Javascript"> // Array of day names var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); // Array of month Names var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","Novem ber","December"); var now = new Date(); now.setDate(now.getDate()); document.write(dayNames[now.getDay()] + ", " + monthNames[now.getMonth()] + " " + (now.getDate()) + ", " + now.getFullYear()); // --> </script>Wednesday, January 26, 2011 </strong></p> </div> <div id="rightbox"> <form name=""> <div id="q1"> <p> </p> Question 1 of 3:<br> Are you male or female?<br> <div class="hoverspan" onclick="javascript:setgender('m'); javascript:q1();" style="padding: 2px; margin: 2px;"> <input id="q1_a1" onclick="javascript:setgender('m'); q1();" type="radio"><label id="male">Male</label> </div> <div class="hoverspan" onclick="javascript:setgender('f'); javascript:q1();" style="padding: 2px; margin: 2px;"> <input id="q1_a2" onclick="javascript:setgender('f'); q1();" type="radio"><label id="female">Female</label> </div> </div> <div id="q2" style="display: none;"> <p> </p> Question 2 of 3:<br> How old are you?<br> <div class="hoverspan" onclick="javascript:setage('1017'); javascript:q2();" style="padding: 2px; margin: 2px;"> <input id="q2_a1" onclick=" javascript:setage('1017'); q2();" type="radio"><label id="age">10-17</label> </div> <div class="hoverspan" onclick="javascript:setage('1825'); javascript:q2();" style="padding: 2px; margin: 2px;"> <input id="q2_a2" onclick="javascript:setage('1825'); q2();" type="radio"><label id="age">18-25</label> </div> <div class="hoverspan" onclick="javascript:setage('2639'); javascript:q2();" style="padding: 2px; margin: 2px;"> <input id="q2_a3" onclick=" javascript:setage('2639'); q2();" type="radio"><label id="age">26-39</label> </div> <div class="hoverspan" onclick="javascript:setage('40'); javascript:q2();" style="padding: 2px; margin: 2px;"> <input id="q2_a4" onclick="javascript:setage('40'); q2();" type="radio"><label id="age">40+</label> </div> </div> <div id="loader" style="display: none; text-align: center;"> <p> </p> <p>Thank you for your responses!</p> <p><img src="survey_files/loader.gif" alt="loading..." title="loading..."></p> <p>Submitting your answers...</p> </div> </form> <div id="products" style="display: none;"> <p>Thank you for participating in our survey! Please select your prize!</p> <div> <table id="fgift" style="display: none;" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr id="gift2" class="hoverspan" onclick="PreventExitSplash=true; location.href='victorias.php';" style="cursor: pointer;"> <td style="padding: 0pt 5px 5px 0pt;"><img src="survey_files/vs2.jpg" id="vs"></td> <td class="mid"><p><b> $1,000 Victoria's Secret Gift Card</b></p> Quantity Left: 3</td> <td class="right" align="right"><form method="post" action="victorias.php"><input value="Choose Victoria's" class="btn" onclick="PreventExitSplash=true;" type="submit"></form></td> </tr></tbody></table> <table id="mgift" style="display: none;" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr id="gift2" class="hoverspan" onclick="PreventExitSplash=true; location.href='walmart.php';" style="cursor: pointer;"> <td style="padding: 0pt 5px 5px 0pt;"><img src="survey_files/walmart.jpg" id="walmart"></td> <td class="mid"><p><b> $1,000 WalMart Gift Card</b></p> Quantity Left: 2</td> <td class="right" align="right"><form method="post" action="walmart.php"><input value="Choose WalMart" class="btn" onclick="PreventExitSplash=true;" type="submit"></form></td> </tr> </tbody></table> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr id="gift2" class="hoverspan" onclick="PreventExitSplash=true; location.href='bestbuy.php';" style="cursor: pointer;"> <td style="padding: 0pt 5px 5px 0pt;"><img src="survey_files/bestbuy.jpg" id="bestbuy"></td> <td class="mid"><p><b> $1,000 Best Buy Gift Card</b></p>Quantity Left: 4</td> <td class="right" align="right"><form method="post" action="bestbuy.php"><input value="Choose Best Buy" class="btn" onclick="PreventExitSplash=true;" type="submit"></form></td> </tr> </tbody></table> </div> </div> </div> <div class="clear"></div> <div class="push"></div> </div> <div id="footer" class="footer" style="margin: -100px auto 0pt; text-align: center;"> </div> <embed src="survey_files/nifty.swf" quality="high" bgcolor="#FFFFFF" name="niftyPlayer1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="1" width="1"> </div></body></html> </iframe> Hi im wondering if someone could be of some help please, im a newbie to javascript and after some help and advice if possible please. Ive used a template from the web which was a quiz template. Im just trying to get my javascript script to work. I want it to populate my html question/advice box so people can input what there answer to the question and it will give them advice. It's for a data classification advice for a work project. I just dont know where im going wrong or what im missing out - ive read loads of help sections on the web and still cant get the javascript to populate my html boxes. Any help or advice would be really appreciated. Thanks Lee Heres my html code which seems to work ok... the box etc is displayed just doesnt have any content. ----------------------------------------------------------------------- Code: <form method="POST"> <div align="center"><center><table BORDER="1"> <tr> <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="+3" COLOR="#FFFFFF">Data Classification </font></td> </tr> <tr> <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="-1" COLOR="#FFFFFF">2010 <a HREF="Data Governance</font> </p> </center></div><div align="center"><center><p><font COLOR="#FFFFFF">Click on "Next Question" to start advice. Be sure to use small letters (no caps) when entering your letter choice.</font> </td> </tr> <tr> <td><b>Question #:</b></td> <td ALIGN="LEFT"><input TYPE="TEXT" NAME="questNo" SIZE="4"></td> </tr> <tr> <td><b>Question:</b></td> <td><div align="center"><center><p><textarea COLS="70" ROWS="2" name="question" wrap="virtual"></textarea></td> </tr> <tr> <td ALIGN="RIGHT"><b>a)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceA" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>b)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceB" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>c)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceC" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>d)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceD" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>Your choice:</b></td> <td><input TYPE="TEXT" NAME="yourChoice" SIZE="4"></td> </tr> <tr> <td COLSPAN="2"><div align="center"><center><p><input TYPE="button" VALUE="Check Current Advice" onClick="checkAnswer(this.form)"><input TYPE="button" VALUE="Next Question" onClick="nextQuestion(this.form)"> <input TYPE="reset" VALUE="Start Over" onClick="clearForm(this.form)"></td> </tr> <tr> <td ALIGN="RIGHT"><b>Results:</b></td> <td><div align="center"><center><p><textarea COLS="70" ROWS="3" name="Advice" wrap="virtual"></textarea></td> </tr> <tr> </form> -------------------------------------------------------------------------- Now heres my javascript which i just cant seem to get to work or integrate with the html question/advice box. There will be some text in there that was originally part of the template that i was going to remove at a later stage once id got a better underatnding of where i was going wrong. Code: <html> <head> <script LANGUAGE="JavaScript"> <!-- hide this script tag's contents from old browsers ---> function jumpBox(list) { location.href = list.options[list.selectedIndex].value } //Lee Quinn 2010 All Rights Reserved function init() { questions = new Array() questions[1] = "Is the information you are collecting or creating any of the following?" questions[2] = "Is the information you are collecting or creating any of the following?" questions[3] = "Is the information you are collecting or creating any of the following?" questions[4] = "Is the information you are collecting or creating any of the following?" answerA = new Array() answerA[1] = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases" answerA[2] = "Employee Handbook,Telephone Directory,Organization Charts,Policies and Standards,Training Manuals" answerA[3] = "Customer records, Correspondence containing customer information, Credit card listings,Personnel records/Employee performance reviews,Unit business plans,Proprietary/custom software,Budget information,Internal audit reports,Business reports on strategy, exposures etc" answerA[4] = "Strategic Plans,Encryption keys,Details of mergers or acquisitions,Financial results prior to publication,Online access codes such as passwords or pin" answerB = new Array() answerB[1] = "None of the above" answerB[2] = "None of the above" answerB[3] = "None of the above" answerB[4] = "None of the above" rightAns = new Array rightAns[1] = "A" rightAns[2] = "b" rightAns[3] = "c" rightAns[4] = "d" reference = new Array() reference[1] = "You have indicated yes to question 1, therefore the information you are collecting/creating will be classified as PUBLIC information. It is information that can be disclosed to anyone without violating an individual?s right to privacy. Knowledge of this information does not expose CFS to financial loss, embarrassment, or jeopardize the security of assets." reference[2] = "You have indicated yes to question 2, therefore the information you are collecting/creating will be classified as INTERNAL USE information. It is information that, due to technical or business sensitivity, is limited to employees and contractors who work on-site. It is intended for use only within CFS. Unauthorized disclosure, compromise, or destruction would not have a significant impact on CFS or its employees." reference[3] = "You have indicated yes to question 3, therefore the information you are collecting/creating will be classified as CONFIDENTIAL information. It is information that CFS and its employees have a legal, regulatory, or social obligation to protect. It is intended for use solely within defined groups in CFS. Unauthorized disclosure, compromise, or destruction would adversely impact CFS its customers or its employees. Unless otherwise stated all data should be treated as CONFIDENTIAL.Sensitive data = Confidential or Highly Confidential data." reference[4] = "You have indicated yes to question 4, therefore the information you are collecting/creating will be classified as HIGHLY CONFIDENTIAL information, It is the highest level of classification and is information whose unauthorized disclosure, compromise, or destruction could result in severe damage, provide significant advantage to a competitor, or incur serious financial impact to CFS or its employees. It is intended for restricted use by a very small number of people (possibly 0 or 1) with an explicit, predetermined need to know." } function nextQuestion(form) //set the total number of questions equal to quizend { var quizEnd = eval(4 * 1); if(form.questNo.value =5= quizEnd) { form.question.value = "1"; form.choiceA.value = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases"; form.choiceB.value = "None of the above"; form.choiceC.value = "Unsure"; form.yourChoice.value = "a,b,c,d"; form.results.value = "End of Advice. Your final results are listed below."; } else { if(form.questNo.value == "") {form.questNo.value = 1} else { form.questNo.value = eval(form.questNo.value) + 1; } form.question.value = questions[form.questNo.value]; form.choiceA.value = answerA[form.questNo.value]; form.choiceB.value = answerB[form.questNo.value]; form.choiceC.value = answerC[form.questNo.value]; form.choiceD.value = answerD[form.questNo.value]; form.yourChoice.value = ""; form.results.value = ""; if(form.myScore.value == "") {form.myScore.value = 0; } else { form.myScore.value = form.myScore.value; } } } function checkcurrentadvice(form) { var myScore = 0; var curve = 0; if(form.results.value != "") {form.results.value = "Sorry, no guessing allowed. In order to retry this question you will have to start the quiz over. Click on ''Next Question'' to continue."; } else if(form.yourChoice.value == rightAns[form.questNo.value]) { form.myScore.value = eval(form.myScore.value) + eval(1); form.results.value = "Conratulations! You are correct. That brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ". Click on ''Next Question'' to continue."; } else { form.results.value = "Sorry, you are incorrect. Please refer to " + reference[form.questNo.value] + " before retaking the quiz. This brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ". Click on ''Next Question'' to continue." } function clearForm(form) { form.questNo.value = ""; form.question.value = ""; form.choiceA.value = ""; form.choiceB.value = ""; form.choiceC.value = ""; form.choiceD.value = ""; form.yourChoice.value = ""; form.results.value = ""; form.myScore.value = ""; form.percent.value = ""; form.grade.value = ""; } </script> </head> </html> can anyone help me validate a survey page i have? it has many questions and each question has 5 radio buttons. i followed many guides and none of them worked for me. I refered to http://www.dynamicdrive.com/forums/s...00&postcount=9 guide and http://javascript.about.com/library/blradio4.htm but for somereason it doesn't seem to work. So can u guys plz look over my simplified version of the survey and see whats is wrong. Sorry if i sound like a noob, I am new here. 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>Untitled Document</title> <script type="text/javascript"> var btn = valButton(form.q1); if (btn == null) alert('No radio button selected'); else alert('Button value ' + btn + ' selected'); function valButton(btn) { var cnt = -1; for (var i=btn.length-1; i > -1; i--) { if (btn[i].checked) {cnt = i; i = -1;} } if (cnt > -1) return btn[cnt].value; else return null; } </script> </head> <body> <table width="800" border="1" cellspacing="0" cellpadding="20"> <form name="science" method="post" action="ad.html" onsubmit="return valButton(btn);"> <tr> <td width="475"><h3> <center> Reasons for organizing Science Olympiad </center> </h3></td> <td width="17"><h3> <center> 1 </center> </h3></td> <td width="17"><h3> <center> 2 </center> </h3></td> <td width="17"><h3> <center> 3 </center> </h3></td> <td width="17"><h3> <center> 4 </center> </h3></td> <td width="17"><h3> <center> 5 </center> </h3></td> </tr> <tr> <td width="475">1. It is fun</td> <td width="17"><input type="radio" id="q1" name="q1" value="1" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="2" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="3" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="4" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="5" /></td> </tr> <tr> <td>2. To motivate students to pursue further education in Science and Engineering</td> <td width="17"><input type="radio" id="q2" name="q2" value="1" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="2" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="3" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="4" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="5" /></td> </tr> <tr> <td><input type="submit" name="submit" /></td> </tr> <tr></tr> </form> </table> testing </body> </html> The problem: I can't get the code to send out my alerts due to empty radio groups. what I'm trying to accomplish: I want Javascript to send a alert to the user if none of the radio buttons within a group are checked. Short Summary: I'm new to Javascript and I've been trying to figure this out myself, but I honestly don't know what's wrong. If you guys can help that'd be great. Thanks in advance. and if the information that I've provided is in anyway confusing let me know and I'll try to help, but again my knowledge is limited. Here is a simplified version of my form.*There are originally 10 questions total. "Names: q1-q10"* Code: <html> <head> <script type="text/javascript" src="val.js"></script> </head> <body> <form method="POST" name="theForm" onsubmit="javascript:check();" class="surv_style" > <p class="ttl" ><label>Question 1: </label></p> <p><label> <input type="radio" name="q1" value="yes"> Yes </label></p> <p><label> <input type="radio" name="q1" value="some"> Sometimes </label></p> <p><label> <input type="radio" name="q1" value="no"> No </label></p> <p class="ttl" ><label>Question 2: </label></p> <p><label> <input type="radio" name="q2" value="yes"> Yes </label></p> <p><label> <input type="radio" name="q2" value="somet"> Sometimes</label></p> <p><label> <input type="radio" name="q2" value="no"> No</label></p> <p><label> <input type="radio" name="q2" value="no_notice"> I havent noticed</label></p> <p class="ttl" ><label>Question 3: </label></p> <p><label> <input type="radio" name="q3" value="yes"> Yes </label></p> <p><label> <input type="radio" name="q3" value="somet"> Sometimes</label></p> <p><label> <input type="radio" name="q3" value="no"> No</label></p> <input type="submit" name="sub_butt" value="Submit"> </form> </body> </html> Here is my Javascript code: Code: function valR_butt(rbgn){ var formName = "theForm"; var form = document.form[formName]; var isChecked = false; var counter = form[rbgn].length; for(var x=0;x<counter;x++){ if(form[rbgn][x].checked==true){ isChecked=true; break; } } if(isChecked==false){ alert(errorMessage); return false; }else{ return true; } } function check(){ var q1 =validateRadioButton("q1"); if(q1==false){ alert("Please select a answer to question 1"); return false; } function check(){ var q2 =validateRadioButton("q2"); if(q1==false){ alert("Please select a answer to question 2"); return false; function check(){ var q3 =validateRadioButton("q3"); if(q1==false){ alert("Please select a answer to question 3"); return false; } alert("OK!\nYour selection is valid"); return true; } } 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! Hi, I am a newbie at XML and this issue is proving to be a tough nut to crack for me. My AJAX query returns me an XML response of the following structure for a query on "ind": <countries> <country> <name>India</name> <capital>New Delhi</capital> </country> <country> <name>Indonesia</name> <capital>Jakarta</capital> </country> </countries> How do I transform the XML response into a HTML layout? Particularly, how do I get down to the value at each node?How do I traverse the XML document using JS? Is this (using XML) better than JSON (other than the obvious platform-independence)? Which is better? Thanks! need help.... I need to create a web page that can pull data from sensatronics senturion sensor probe. The unit has a web server that displays temperature, humidity,etc. You can also query it for from telnet or webpage which kicks back xml. My page needs to read the values of the probes. I don't know much about javascript and have been unsuccessful trying to use httprequest. I guess this would be considered cross domain as well? Here is the XML that is generated from the unit. I get this by pulling through a web browser x.x.x.x/xmldata Thanks <?xml version="1.0" encoding="ISO-8859-1"?> <Sensatronics id="S10604" hb="10554"> <Group id="1"> <Probe id="100"><Value>75.2</Value></Probe> </Group> <Group id="2"> </Group> <Group id="3"> </Group> <Group id="4"> </Group> <Group id="5"> </Group> <Group id="6"> </Group> <Group id="7"> </Group> <Group id="8"> </Group> <Group id="9"> <Probe id="99"><Value>1.0</Value></Probe> <Probe id="1"><Value>79.5</Value></Probe> <Probe id="2"><Value>34.3</Value></Probe> <Probe id="3"><Value>35.6</Value></Probe> <Probe id="4"><Value>0.0</Value></Probe> </Group> </Sensatronics> All, Say I have the following code: Code: <!DOCTYPE html> <html> <head> <style>img{ height: 100px; float: left; }</style> <script src="http://code.jquery.com/jquery-1.7rc2.js"></script> </head> <body> <div id="images"> </div> <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", { tags: "cat", tagmode: "any", format: "json" }, function(data) { $.each(data.items, function(i,item){ $("<img/>").attr("src", item.media.m).appendTo("#images"); if ( i == 3 ) return false; }); });</script> </body> </html> This came from the jQuery website. What I would like to do is change the link to something like this: https://graph.facebook.com/me/friend...ss_token=12345 The data that comes back is something like: Code: { "data": [ { "review_comment": "Here is a comment", "id": "12" }, { "review_comment": "Testing With more", "id": "34" }, { "review_comment": "Third comment", "id": "643" }, { "review_comment": "More Comments", "id": "120" }, { "review_comment": "Testing", "id": "3455" } ] } What I would like to do is basically read all of the review_comment tags and basically rotate these to display them on the webpage. So have "Here is a comment" be displayed for like 10 seconds and then fade out and have "Testing with More" fade in and be displayed for another 10 seconds etc. What is the best way to do this? I'm not sure how to change my JSON code above to acheive this. Would I need to basically put the comments in a div and then use jQuery to fade in the divs in and out? Any help you could provide would be greatly appreciated!! Hi there! I'm having a little bit of trouble, I've read through tutorials on parsing XML to Javascript and such, but the XML file I'm working with is very different to the ones the tutorial showed me. Normally it'd be like Code: <here> <there></there> </here> But the one I'm wanting to work in looks like this: Code: <rowset name="names" columns="name"> <row name="this"> <rowset name="fun" columns="name"> <row name="that"> </rowset> </row> </rowset> To make it more clear, my question to you is: How can I parse <row name="that"> where only we only have <row name="this"> Hi all, I am having trouble trying to use the substring String method. Relevant HTML code: Code: <img id="news" src="../images/news.png" alt="News" onmouseover="change(this)" /> Relevant JavaScript code: Code: function change(element) { if (element.id == "news" && element.src.substring(3,5) != "../") { element.src = "../images/news.png"; alert(element.src.substring(3,5)); } else if (element.id == "news" && element.src.substring(3,5) == "../") { element.src = "../../images/news.png"; } } I want the image to change to another image, but depending on the src in the HTML code. This is so that it can locate the correct folder. However, it doesn't work, and I tried using an alert statement to show me what JavaScript is reading and it seems to read "e:", which is not correct. It never reads "../", which it should. I don't know how to solve this problem, any ideas? I would like to modify an old script retrieve a registry key and sifting through the many forums put this together but not sure if this is correct? Thanks Code: <html> <head> <script language="javascript"> <!-- var value; var Shell; var cicserver; Shell = new ActiveXObject("WScript.Shell"); value = Shell.RegRead("HKLM\\Software\\Interactive Intelligence\\EIC\\Notifier"); if value = "servername1" { cicserver = "servername1" } else { cicserver = "servername2" } Hi All, Im trying to write a html with javascript page that reads values from an XML file and outputs to a table. Thats easy i hear you say? Trouble is the application that is outputing the XML file doesnt output a simple XML file. Below is a section of the file: Code: <?xml version="1.0" encoding="UTF-8"?> <CVES name="EUREX" datetime="09 Aug 10 14:40:41"> <thread name="DB 0" state ="active" nb="0" tempo="00:00:02" action="Wait"/> <thread name="DB 1" state ="active" nb="0" tempo="00:00:02" action="Wait"/> <thread name="match" state ="active" nb="0" tempo="00:00:02" action="Wait"/> <MatchingList> <Tickets value="142"/> <TicketsCleared value="23"/> <TicketsNotCleared value="119"/> <Orders value="21"/> <OrdersCleared value="21"/> <OrdersNotCleared value="0"/> </MatchingList> <thread name="exch 1" state ="active" nb="0" tempo="00:00:10" action="Wait"/> <Exchange> <Tickets value="142"/> <TicketsWithUnknownExternalCodes value="212"/> <ClearingInProgress value="4"/> <Clearing> <AverageClearingTime value="00:00:00"/> <LastClearingTime value="14:26:37"/> <LastUnclearingTime value="14:27:55"/> <TotalQtyCleared value="705"/> <TotalQtyUnCleared value=""/> </Clearing> <Reading> <LastReadingTime value="14:40:31"/> <NextReadingTime value="14:41:00"/> im able to read the contents of the CVES tag (Name and datetime) but cannot get any others to load. how can i get details from LastReadingTime? Thread name="Exch 1" Having googled reading XML into HTML file and cannot find anything that covers this kind of xml file THanks Dear frnd I wanna read on html page , and i have script : " [I]<html> <head> <script type="text/javascript" language="javascript"> function Read() { var Scr = new ActiveXObject("Scripting.FileSystemObject"); var CTF = Scr .OpenTextFile("C:\\123.txt", 1, true); data = CTF .ReadAll(); document.write("<pre>" + data + "</pre>"); CTF .Close(); } </script> </head> <body onLoad="Read()" > </body> </html> [I] " But as its using activex control not allowing in all browser . Have you any other way with pure js to read the file contains ? or allowing activex in all browser ? I am having an issue reading from a div that is being changed. The div in question was initially empty. A function that was called upon the selection of something in the drop down list creates another drop down list within that div (sets the inner html). Now, I have another function that needs to read from this new drop down list. However, when I use alert(document.getelementbyid('divid').innerhtml) in the function it returns undefined. The drop down list is created successfully and populated by the relevant data. The method of creation was calling another php file that created the list after querying a database. Any ideas? I can post the code if it will help.
i am thinking of using a xml file as a data base for example , the xml file stores a list of reference numbers which is allocated to a url or a name such as 0123456789 and i have a text box on a webpage and the user types in a reference number and the javascripts reads the xml file to check if its a valid reference number i.e a registered number i am new to working with xml etc... so would be nice to have a little help here EXAMPLE <DATA> <REF> <0123456789>JOE</01234567890> <1111111111>www.google.com</1111111111> </REF> </DATA> id like it to read the specific data thats contained within the tag such as 0123456789's tag = JOE hi Guys , I have some instructions in property files , now I wat to retrive that fmt tag values in scriptlets So that I can modify the content in property file So i have written the code in jsp as <c:set var="mailBodyData" value='<fmt:message key="confirmemail.body.message"/>' scope="request"/> <% out.println("hero "+request.getAttribute("mailBodyData")); %> but its displays empty , Also I have tried as <% String str ="<fmt:message key="confirmemail.body.message"/>' %> but its throughs the Compilation error , Pls help , So that I can retrive the data from fmt to Scriptlets I am trying to make a simple alert come up stating a checkbox is checked when it changes, and then another alert for when the checkbox is unchecked. Problem is, only the alert for when the box is checked is coming up. Anyone know why? Code: function displayCheckPopUp() { if(document.activeElement.checked=true) { alert("A check box has been selected"); } else if(document.activeElement.checked=false)<!--if(document.getElementById().checked=false)--> { alert("****"); } } Code: <input type="checkbox" name="Checkbox 1" value="Checkbox 1" id="first_cbox" onchange="displayCheckPopUp(this)" /> <p class="custom_style2"> Checkbox 1 </p> hi, (JAVASCRIT) the actual program reads and prints values from a checkbox tree and this piece of code does it. Code: dhtmlXTreeObject.prototype.getAllChecked=function(){ return this._getAllChecked("","",1); } dhtmlXTreeObject.prototype.getAllCheckedBranches=function(){ return this._getAllChecked("","",0); } dhtmlXTreeObject.prototype._getAllChecked=function(htmlNode,list,mode){ if(!htmlNode)htmlNode=this.htmlNode; if(((mode)&&(htmlNode.checkstate==1))||((!mode)&&(htmlNode.checkstate>0))){if(list)list+=","+htmlNode.id;else list=htmlNode.id;} var j=htmlNode.childsCount; for(var i=0;i<j;i++) { list=this._getAllChecked(htmlNode.childNodes[i],list,mode); }; if(list)return list;else return ""; }; the values are returned to alertbox. Code: <a href="javascript:void(0);" onclick="alert(tree2.getAllChecked());">Get list of checked</a><br><br> kindly help me with reading the returned values in to an array or list (but bot in alertbox) ...so that i can pass them to next JSP page. waiting for ur answer, BeanBoy ! |