JavaScript - My Code: What's Wrong With My Javascript For Retrieving A Radio Button Value?
Here's my HTML:
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>The Happy Hoppin' Hotel</title> <script src="happyhoppin.js" language="javascript" type="text/javascript"></script> </head> <body> <h1>The Happy Hoppin' Hotel Checkout Page</h1> <h2>Fill out the form below to calculate balance due</h2> <form> Guest ID Number: <input type="text" id="guestID" /> <br /> <br /> Room Type: <select id="roomType"> <option></option> <option>Parlor</option> <option>Single</option> <option>Double</option> </select> <br /> <br /> Length of Stay: <input type="text" id="stayLength" /> <br /> <br /> Number of Drinks: <input type="text" id="drinkNumber" /> <br /> <br /> Number of Towels: <input type="text" id="towelNumber" /> <br /> <br /> Number of Flushes: <input type="text" id="flushNumber" /> <br /> <br /> Bug Complaints?: <br /> <form name="bugComplaintRadio"> <input type="radio" name="bugComplaint" value="No" />No</label> <br /> <input type="radio" name="bugComplaint" value="Yes" />Yes</label> <br /> </form> <br /> Customer Comments: <br /> <textarea name="customerComment" cols="50" rows="5">Enter your comments here...</textarea> <br /> <br /> <input type="button" onclick="calculateBill()" value="Calculate Bill"> </form> </body> </html> Here's my Javascript: Code: const parlorPrice = 80; const singlePrice = 100; const doublePrice = 150; const drinkPrice = 5; const towelPrice = 3; const flushPrice = 1; var guestID = 0; var roomPrice = 0; var stayLength = 0; var drinkNumber = 0; var towelNumber = 0; var flushNumber = 0; var totalDue = 0; var totalCharge = 0; function calculateBill(){ validateForm(); //roomType// if(roomType == "Parlor"){ roomPrice = parlorPrice; } if(roomType == "Single"){ roomPrice = singlePrice; } if(roomType == "Double"){ roomPrice = doublePrice; } //roomType// //drinkCharge// drinkCharge = drinkNumber * drinkPrice; //drinkCharge// //towelCharge// towelCharge = towelNumber * towelPrice; //towelCharge// //flushCharge// flushCharge = flushNumber * flushPrice; //flushCharge// //totalCharge// totalCharge = roomPrice + drinkCharge + towelCharge + flushCharge; //totalCharge// //**bugDiscount**// function getCheckedRadio() { bugValue = ""; bugLength = document.bugComplaintRadio.bugComplaint.length; var bugDiscount = 0; for (x = 0; x < bugLength; x ++) { if (document.bugComplaintRadio.bugComplaint[x].checked) { bugValue = document.bugComplaintRadio.bugComplaint[x].value; } } if (bugValue == "") { alert("You did not choose whether you had a bug complaint or not"); } if (bugValue = "No"){ bugDiscount = 0; } if (bugValue = "Yes"){ bugDiscount = 20; } } //**bugDiscount**// getCheckedRadio(); //totalDue// totalDue = totalCharge + bugDiscount //totalDue// displayBill(); } function validateForm(){ //guestID// guestID = parseInt(document.getElementById("guestID").value); if(isNaN(guestID)){ alert("Guest ID must be a number"); return; } if(guestID <= 0){ alert("Guest ID must be greater than zero"); return; } //guestID// //roomType// roomType = document.getElementById("roomType").value; if(roomType == ""){ alert("Room type must be selected"); return; } //roomType// //stayLength// stayLength = parseInt(document.getElementById("stayLength").value); if(isNaN(stayLength)){ alert("Length of stay must be a number"); return; } if(stayLength <= 0){ alert("Length of stay must be greater than zero"); return; } //stayLength// //drinkNumber// drinkNumber = parseInt(document.getElementById("drinkNumber").value); if(isNaN(drinkNumber)){ alert("Number of drinks must be a number"); return; } if(drinkNumber <= 0){ alert("Number of drinks must be greater than zero"); return; } if(drinkNumber > 25){ alert("Number of drinks has exceeded 25"); return; } //drinkNumber// //towelNumber// towelNumber = parseInt(document.getElementById("towelNumber").value); if(isNaN(towelNumber)){ alert("Number of towels must be a number"); return; } if(towelNumber <= 0){ alert("Number of towels must be greater than zero"); return; } //towelNumber// //flushNumber// flushNumber = parseInt(document.getElementById("flushNumber").value); if(isNaN(flushNumber)){ alert("Number of flushes must be a number"); return; } if(flushNumber <= 0){ alert("Number of flushes must be greater than zero"); return; } //flushNumber// //customerComment// customerComment = document.getElementById("customerComment"); //customerComment// } function displayBill(){ var newPage = "<html><head><title>Billing Summary</title></head>"; newPage += "<body><h1>Happy Hoppin Hotel</h1>"; newPage += "<h2>Guest Billing Statement</h2>"; newPage += "Guest Identification: #" + guestID; newPage += "<br />"; newPage += "Room Type: " + roomType; newPage += "<br />"; newPage += "Room Charge: $" + roomPrice; newPage += "<br />"; newPage += "Length of Stay: " + stayLength + " days"; newPage += "<br />"; newPage += "Drink Charge: $" + drinkCharge; newPage += "<br />"; newPage += "Towel Charge: $" + towelCharge; newPage += "<br />"; newPage += "Flushing Charge: $" + flushCharge; newPage += "<br />"; newPage += "Total Charge: $" + totalCharge; newPage += "<br />"; newPage += "Discount: $" + bugDiscount; newPage += "<br />"; newPage += "Total Due: $" + totalDue; newPage += "<br />"; newPage += "<h3>Come back and visit us again at the Happy Hoppin' Hotel!</h3>"; var z = window.open("","","width=400,height=500"); z.document.write(newPage); z.document.close(); } My question is, I've been spending countless hours trying to: 1. Make two radio buttons indicating "No" and "Yes", 2. Retrieve which selection the user has made, 3. Change the value of "bugDiscount" or the amount of money ($20 or $0) depending on which choice the user made; $0 for No & $20 for Yes. 4. Subtract the value of bugDiscount (0 or 20) from the totalCharge to get TotalDue I know I'm close, but I've tried any number of variations in my code and I still can't seem to get it right. Can anyone help? Similar TutorialsHi all. I'm having some trouble w/ my radiobutton code and i dont know why. for instance if i select yes for the 1st radio button, and no for the 2nd, instead of doing what it should do for no, it gets rid of w/e it did for yes.. also, if i enter something into the 1st box, and select another radio button, it deletes w/e is in all boxes... Code: <html> <head><title>So you want to make a website?</title></head> <body> <script> var lvl=0; var cssbgc=0; var ischecked=0; var isgroup1=0; var isgroup2=0; function get_funcs(lvl){ if(lvl == "Easy"){ a='<hr>\n'; a+='<h1>Website Controls</h1>\n'; a+='Do you want to add a title to your website?<br>\n'; a+='Yes <input onclick="checkchecks()" type="radio" name="group1" value="Yes"> No<input onclick="checkchecks()" type="radio" name="group1" value="No"><br><br>\n'; a+='<div id="websitep">- Does not want website title</div><br>\n'; a+='Do you want to add a background image to your website?<br>\n'; a+='Yes <input onclick="checkchecks()" type="radio" name="group2" value="Yes1"> No<input onclick="checkchecks()" type="radio" name="group2" value="No1"><br><br>\n'; a+='<div id="websiteq">- Does not want website background</div><br>\n'; a+='Your Website scripts:<br><input name="websitescripts" type="text" size="30"> <a href="javascript:answerq(\'websitescripts\');">Help?</a><br>\n'; a+='<br>Your website content (this will appear inbetween <body></body>)<br>This can be done for you if you wish: <a href="javascript:answerq(\'webcontent\');">Help?</a><br><textarea rows="15" cols="45" id="websitecontent" name="websitecontent"></textarea><br>\n'; a+='<input type="button" value="Submit" name="sub1" id="sub1" onClick="checkconts(lvl)"><br>\n'; a+='<h1>Your Website</h1><hr>\n'; a+='<textarea rows="15" cols="45" id="websitelvl" name="websitelvl"></textarea>\n'; document.getElementById("websitecontrols").innerHTML = a; }else if(lvl == "Medium"){ a='<hr>\n'; a+='<h1>Website Controls</h1>\n'; a+='<table>\n'; a+='<tr><td>\n'; a+='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n'; a+='Your Website scripts:<br><input name="websitescripts" type="text" size="30"> <a href="javascript:answerq(\'websitescripts\');">Help?</a><br>\n'; a+='Do you want a website background color using css?<br><br>Yes<input onclick="check()" type="checkbox" value="Yes" id="group1" name="group1"> No<input onclick="check()" type="checkbox" value="No" id="group1" name="group1"><br>\n<div id="cssbc"></div>\n'; a+='<br>Your website content (this will appear inbetween <body></body>)<br>This can be done for you if you wish: <a href="javascript:answerq(\'webcontent\');">Help?</a><br><textarea rows="15" cols="45" id="websitecontent" name="websitecontent"></textarea><br>\n'; a+='<input type="button" value="Submit" name="sub1" id="sub1" onClick="checkconts(lvl)"><br>\n'; a+='</td></tr>\n'; a+='</table>\n'; a+='<h1>Your Website</h1><hr>\n'; a+='<textarea rows="15" cols="45" id="websitelvl" name="websitelvl"></textarea>\n'; document.getElementById("websitecontrols").innerHTML = a; } } function checkchecks(){ for (i=0; i<document.forms.radioform.group1.length; i++){ if(i == 0 && document.forms.radioform.group1[i].checked == true){ ischecked = 1; isgroup1 = 1; isgroup2 = 0; }else if(i == 1 && document.forms.radioform.group1[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } for (i=0; i<document.forms.radioform.group2.length; i++){ if(i == 0 && document.forms.radioform.group2[i].checked == true){ ischecked = 1; isgroup1 = 0; isgroup2 = 1; }else if(i == 1 && document.forms.radioform.group2[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } if(isgroup1 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='Your Website Title:<br><input name="webtitle" type="text" size="30"> <a href="javascript:answerq(\'webtitle\');">Help?</a><br>\n'; document.getElementById("websitep").innerHTML = a; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website title<br>\n'; document.getElementById("websitep").innerHTML = a; } if(isgroup2 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); b='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n'; document.getElementById("websiteq").innerHTML = b; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website background image<br>\n'; document.getElementById("websiteq").innerHTML = b; } alert('isgroup1:'+isgroup1+'|'+'isgroup2:'+isgroup2+''); } function check(){ for (i=0; i<document.forms.radioform.website.length; i++){ if(document.forms.radioform.website[i].checked == true){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); if(i == 0 && document.forms.radioform.website[1].checked == true){ cssbgc = 0; document.forms.radioform.website[1].checked = false; }else if(i == 1 && document.forms.radioform.website[0].checked == true){ cssbgc = 1; document.forms.radioform.website[0].checked = false; } } } if(cssbgc == 0){ alert('ok then'); }else if(cssbgc == 1){ document.getElementById("cssbc").innerHTML = ""; } } function preview_website(){ if(document.forms.radioform.websitecontent.value != ""){ alert('Previewing your website...'); a='<center><h1>Website Preview<\/h1><\/center>\n<br><br>\n'; a+=document.forms.radioform.websitecontent.value+'\n'; document.write(a); } } function previewconts(){ if(document.forms.radioform.websitecontent.value != "" || document.forms.radioform.webtitle.value != "" || document.forms.radioform.webback.value != "" || document.forms.radioform.weblvl.value != ""){ preview_website(lvl); }else{ alert('Please enter something into the box before continuing...'); } } function checkconts(lvl){ if(document.forms.radioform.websitecontent == null || document.forms.radioform.websitecontent == null || document.forms.radioform.webtitle == null || document.forms.radioform.webback == null || document.forms.radioform.weblvl == null){ alert('Please select an option 1st...'); }else if(document.forms.radioform.websitecontent.value == null || document.forms.radioform.websitecontent.value == null || document.forms.radioform.webtitle.value == null || document.forms.radioform.webback.value == null || document.forms.radioform.weblvl.value == null){ alert('Please enter something into the box before continuing...'); }else{ a=document.forms.radioform.websitelvl.value = website(lvl); document.getElementById('websitecontent').innerHTML = a; } } function get_option(which){ if(which == "webtitle"){ return document.radioform.webtitle.value; }else if(which == "webback"){ return document.radioform.webback.value; }else if(which == "websitecontent"){ return document.radioform.websitecontent.value; }else if(which == "websitescripts"){ return document.radioform.websitescripts.value; } } function answerq(divname){ if(divname == "webtitle"){ alert('This is where you enter the name of your website that appears in the top left corner of your web browser.'); }else if(divname == "webback"){ alert('This is where you enter a background image link or a select a picture from your hard drive (IE: When selected you will see something like C:/mypics/pic.jpg appear in the box).'); }else if(divname == "webcontent"){ alert('this is where you enter what you want to appear on the page (this can be done for you if you wish).'); }else if(divname == "websitescripts"){ alert('This is where you enter any file locations to your script file(s).'); } } function website(lvl){ if(lvl == "Easy"){ a = "<html>\n"; a += "<head><title>"+get_option('webtitle')+"</title></head>\n"; if(document.forms.radioform.webback.value == ""){ a += "<body>\n"; }else{ a += "<body background=\""+get_option('webback')+"\">\n"; } if(document.forms.radioform.websitecontent.value != ""){ a += get_option('websitecontent')+"\n"; a += "</body>\n"; }else{ a += "</body>\n"; } a += "</html>\n"; } return a; } function callcontrols(lvl){ if(lvl == "Easy" || lvl == "Medium" || lvl=="Hard" || lvl == "Extreme"){ get_funcs(lvl); }else{ document.getElementById("websitecontrols").innerHTML = "NO!"; } } function getwebsite(lvl){ if(lvl == "Easy" || lvl == "Medium" || lvl == "Hard" || lvl == "Extreme"){ callcontrols(lvl); } } function get_radio_value() { for (var i=0; i < document.radioform.website.length; i++) { if (document.radioform.website[i].checked) { var rad_val = document.radioform.website[i].value; getwebsite(rad_val); } } lvl = rad_val; alert(lvl); } </script> <center> <h1>So you want to build a website?</h1><br> Easy - HTML Website<br> Medium - HTML / JavaScript / CSS Website<br> Hard - HTML / JavaScript / CSS / PHP Website<br> Extreme - HTML / Encrypted HTML / JavaScript / Encrypted JavaScript / CSS / PHP Website<br><br> You have four choices: <br> <form name="radioform"> Step 1:<br>Choose an option<br><br> Easy<input type="radio" onclick="get_radio_value()" name="website" value="Easy">Medium<input onclick="get_radio_value()" type="radio" name="website" value="Medium">Hard<input onclick="get_radio_value()" type="radio" name="website" value="Hard">Extreme<input onclick="get_radio_value()" type="radio" name="website" value="Extreme"><br><br> <div id="websitecontrols"></div> </form> </center> </body> </html> The functions you are looking at are checkchecks() and checkconts(). here's the functions: checkchecks(): Code: function checkchecks(){ for (i=0; i<document.forms.radioform.group1.length; i++){ if(i == 0 && document.forms.radioform.group1[i].checked == true){ ischecked = 1; isgroup1 = 1; isgroup2 = 0; }else if(i == 1 && document.forms.radioform.group1[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } for (i=0; i<document.forms.radioform.group2.length; i++){ if(i == 0 && document.forms.radioform.group2[i].checked == true){ ischecked = 1; isgroup1 = 0; isgroup2 = 1; }else if(i == 1 && document.forms.radioform.group2[i].checked == true){ ischecked = 0; isgroup1 = 0; isgroup2 = 0; } } if(isgroup1 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='Your Website Title:<br><input name="webtitle" type="text" size="30"> <a href="javascript:answerq(\'webtitle\');">Help?</a><br>\n'; document.getElementById("websitep").innerHTML = a; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website title<br>\n'; document.getElementById("websitep").innerHTML = a; } if(isgroup2 == 1){ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); b='Your Website background picture (if any):<br><input name="webback" type="file" size="30"> <a href="javascript:answerq(\'webback\');">Help?</a><br>\n'; document.getElementById("websiteq").innerHTML = b; }else{ alert('Make SURE this option is what you want. If you select another option after entering data, it will erase your data...'); a='- Does not want website background image<br>\n'; document.getElementById("websiteq").innerHTML = b; } alert('isgroup1:'+isgroup1+'|'+'isgroup2:'+isgroup2+''); } checkconts(): Code: function checkconts(lvl){ if(document.forms.radioform.websitecontent == null || document.forms.radioform.websitecontent == null || document.forms.radioform.webtitle == null || document.forms.radioform.webback == null || document.forms.radioform.weblvl == null){ alert('Please select an option 1st...'); }else if(document.forms.radioform.websitecontent.value == null || document.forms.radioform.websitecontent.value == null || document.forms.radioform.webtitle.value == null || document.forms.radioform.webback.value == null || document.forms.radioform.weblvl.value == null){ alert('Please enter something into the box before continuing...'); }else{ a=document.forms.radioform.websitelvl.value = website(lvl); document.getElementById('websitecontent').innerHTML = a; } } I'm trying to make radiobuttons with a javascript function that gets called when a button is selected to make an image appear depending on what they click. However, after looking it up for a while I have nothing since some tell me to do document.formName.name.value; some tell me to use an id with my buttons and just use a document.getElementByID(""); etc. This is for a project and we havent used parameters yet and I dont know how to implement them in the HTML as well This is my code: function classchoice() { if(document.getElementById('mage') == true) { classtype = "<img class='display' src='mage.jpg'>"; document.getElementById("picture").innerHTML=classtype; } if(document.classes.classes.paladin == true) { classtype = "<img class='display' src='paladin.jpg'>"; document.getElementById("picture").innerHTML=classtype; } if(document.classes.classes.hunter == true) { classtype = "<img class='display' src='hunter.jpg'>"; document.getElementById("picture").innerHTML=classtype; } if(document.classes.classes.rogue == true) { classtype = "<img class='display' src='rogue.jpg'>"; document.getElementById("picture").innerHTML=classtype; } } This is the HTML: <form name="classes"> <input type="radio" name = "classes" id="mage" onmousedown="classChoice();"> <img src = "mage.jpg" /> <input type="radio" name = "classes" id = "Paladin" onmousedown="classChoice();"> <img src = "Paladin.png" /> <input type="radio" name = "classes" id = "hunter" onmousedown="classChoice();"> <img src = "hunter.PNG" /> <input type="radio" name = "classes" id = "rogue" onmousedown="classChoice();"> <img src = "rogue.jpg" /> </form> I hope it's readable because I copy and pasted my code and the indentations are a bit messed up Hello, I am trying to implement a radio button option so that users can search specific sites such as google, yahoo, or bing from input box. Here's my code. Please help. <script type="text/javascript"> <!-- function goSearch(){ //search according to checked radio button } --> </script> <h1>Search Option</h1><br /> <input type="radio" name="search" id="google"/><a href="http://www.google.com" rel="nofollow" target="_blank"><img src="images/google.jpg" /></a> <input type="radio" name="search" id="yahoo"/><a href="http://www.yahoo.com" rel="nofollow" target="_blank"><img src="images/yahoo.jpg" /> </a> <input type="radio" name="search" id="bing" /><a href="http://www.bing.com" rel="nofollow" target="_blank"><img src="images/bing.jpg" /> </a> <br /><br /> <form method="get" action="goSearch()" rel="nofollow" target="_blank"> <div style="border:1px solid black;padding:4px;width:20em;"> <table border="0" cellpadding="0"> <tr> <td> <input type="text" name="q" size="25" maxlength="255" value="" /> <input type="submit" value="Search" /> </td> </tr> </table> </div> </form> I want to change radio button values dependent on the selected item in a drop down list. The radio buttons have default values but I need them to be changed when the selection has been made in the drop down list and before the submit button has been pressed so the changed values will be written to the database. Example : Drop down item : National Radio 1 value : Director Radio 2 value : National PA Drop down item : Regional Radio 1 value : Regional Manager Radio 2 value : Regional PA Drop down item : Local Radio 1 value : Store Manager Radio 2 value : Assistant Store Manager Any help will be appreciated. I am very new Beginner of Javascript.. My query is that 1)I have 2 radio buttons A and B 2)When I click A I want 2 dropdownbox and a button to be displayed 3)When I click B I want 2 dropdownbox to be displayed. 4)Both should be independent Plz tell me the code..for this I have 4 rows in a table. Each row consist of 4 radio buttons. Each radio button per row has different values in it but has the same name (group) ex: <input type="radio" name="a" value="1"> <input type="radio" name="a" value="2"> <input type="radio" name="a" value="3"> <input type="radio" name="a" value="4"> <input type="radio" name="b" value="1"> <input type="radio" name="b" value="2"> <input type="radio" name="b" value="3"> <input type="radio" name="b" value="4"> and so on.. If I click radio button A with value 2, I want to output the total at the bottom as "2".. Also, if I click radio button B with value 3, I want to output the total of A and B as 5 and so on.. How can I automatically calculate the answer based on which radio button was click? update: I got my answer from this site: http://stackoverflow.com/questions/1...s-using-jquery Hello All. What my script does is if you do not select a radio button and you hit submit an error will pop up saying please select game1. this is taken from the name of the radio button.. How can i make it so it prints out the VALUES of the 2 radio buttons. end result should print please select Baltimore Ravens vs. Cincinnati Bengals rather than please select game1. Code: function isChecked(radgrp) { var i = radgrp.length; do if (radgrp[--i].checked) return true; while (i); return false; } function validateTest(els) { var focus_me = null, msg = ""; if (!isChecked(els.game1)) { msg += " Game #1\n"; focus_me = focus_me || els.game1[0]; } if (!isChecked(els.game2)) { msg += " Game #2\n"; focus_me = focus_me || els.game2[0]; } if (!isChecked(els.game16)) { msg += " Game #16\n"; focus_me = focus_me || els.game16[0]; } if (msg != "") { var prefix = "\n WARNING: The following Games(s) were not selected:\n\n"; var suffix = "\nClick OK to submit your picks anyway.\n\n"; var suffix = suffix + "\n Click CANCEL to correct your picks." var ask = confirm(prefix + msg + suffix); if (ask) { if (focus_me) focus_me.focus(); return true; } else{ return false; } } } Here is the radio button. If you dont select the radio button i want the javascript validation pop but to say "please select Baltimore Ravens vs. Cincinnati Bengals rather than game1 like it does now. Code: <INPUT TYPE=RADIO NAME="game1" VALUE="Baltimore Ravens">Baltimore Ravens<BR> <INPUT TYPE=RADIO NAME="game1" VALUE="Cincinnati Bengals">Cincinnati Bengals<BR> Thanks 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 Hi, I have a choice of three market items and I want the value of the selected one to be sent to my form. My code is: Code: <script type="text/javascript"> function loadXMLDoc2(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> </head> <body> <input type="radio" name="myitem" id="myitem" value="All;" onclick="OtherFunction()" />All <br /><br />' <input type="radio" name="myitem" id="myitem" value="Shirts" onclick="OtherFunction()" />Shirts <br /><br /> <input type="radio" name="myitem" id="myitem" value="Trousers" onclick="OtherFunction()" />Trousers <br /><br /> <br /><br /> <input type="button" class="indent" name="submitB" id="submitB" value="Submit" onclick="loadXMLDoc2('insertMarket.php','txtHint', 'md='+encodeURI(document.getElementById('myitem').value))" /> <div id="txtHint"></div> This doesn't work. I have tried giving them different ids, I have tried replacing the id with checked="id=\'myitem\'", I have tried getElementById(\'myitem.checked\'), I have tried getElementbyName. In my full page I have far more radio buttons, so I don't want to do a getElementById(\'myitem[0].checked || myitem[1].checked etc. I think the solution must be along these lines. But I have run out of alternatives to try. Needless to say as it currently stands it gives the last radio button's value, which means it doesn't like them having the same id, but when I tried changing how the id was applied, or called - ElementByName, FF gives the error message as id is null. Dear All, I am trying to design a from with radio buttons and text boxes which will accept text values upon clicking the radio buttons. So basically the textbox only appears when the radio button is clicked. The problem I am facing is the textbox does not hide upon selecting different radio button. Below I am posting the javascript and the associated html form for the same. I would like to request some suggestions and directions for the same. Regards Code: Javascript: <script type="text/javascript"> function show() { var i = 0; var el; while(el = document.getElementsByName('radio')[i++] ) { (document.getElementById('radio'+i).checked) ? document.getElementById('text'+i).style.display="block" : document.getElementById('text'+i).style.display="none" } } </script> Code: <div id="SeqInput"> <form method="post" action="the url to process this form" > <div> <label><input type="radio" name="seqinput" value="accession" id="radio1" onclick="show()"></label> NCBI accession number: <label for="accession"><input type="text" id="text1"></label><br> <label><input type="radio" name="seqinput" value="gene" id="radio2" onclick="show()"></label> NCBI Gene Name: <label for="gene"> <input type="text" id="text2"></label><br> <label><input type="radio" name="seqinput" value="file" id="radio3"></label> Upload fasta sequence from file: <label for="file"><input type="file" id="file"></label><br> <label><input type="radio" name="seqinput" value="fasta" id="radio4" onclick="show()"></label> Click to type in or copy/paste the fasta sequence:<br> <label><textarea rows="10" cols="100" id="text3" style="display: none"> </textarea></label> </div> </form> </div> I am using ASP validators and I have a contact form. I want to be able to have a phone and email radio button group. The email textbox also has a RegularExpressionValidator If the phone item is selected then I want the validation to be enabled on the phone text box making it mandatory while the email text box isn't, and if they choose the email as the contact it will be reversed. I want to be able to do this without having to do a postback. I already have the logic on the code behind and the enquiry object. also I am fairly new to javascript so I have been using mostly jQuery as easier to implement Ok, the code below works ok in Firefox but not in IE and I can't figure out why. Please note that when I include the movie src in the body tag, the way it is in the code below, the movie loads fine but the window does not resize as it should (see the document.getElementByID). When I take the movie src out of the body tag however, it doesn't load. It's supposed to load just from the javascript meaning the src shouldn't need to be in the body for this to work. Can anyone see what the problem is? Code: <html> <head> <style type="text/css"> <!-- .fontStyle { font-family: Verdana, Geneva, sans-serif; font-size: small; font-weight: bold; color: #67A2DC; } --> </style> <script type="text/javascript"> /*window.onload=function(){ loadVideo(); } /* function wait() { //loadVideo(); setTimeOut("loadVideo()", 2000); } */ function loadVideo() { <!-- if (parseInt(navigator.appVersion)>3) { if (navigator.appName == "Netscape") { winW = window.innerWidth; winH = window.innerHeight; } if (navigator.appName.indexOf("Microsoft") != -1) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } } var dimW = winW-50; var dimH = winH-20; var w1 = dimW.toString(); var h1 = dimH.toString(); if(document.getElementById("vidEmbed") != null) { document.getElementById("vidEmbed").src = "oracleWelcome_1.wmv"; document.getElementById("vidEmbed").style.width = w1; document.getElementById("vidEmbed").style.height = h1; } else if(document.getElementById("Player") != null) { document.getElementById("Player").style.width = w1; document.getElementById("Player").style.height = h1; document.getElementById("objectSrc").value = "oracleWelcome_1.wmv"; } } </script> </head> <body><div> <p><span class="fontStyle">Introduction<br> </span> <object id="Player" width="100%" height="100%" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="border:0px;"> <param name="autoStart" value="True"> <param name="uiMode" value="full"> <param name="volume" value="50"> <param name="mute" value="false"> <param name="URL" id="objectSrc" value=""> <embed src="" id="vidEmbed" width="100%" height="100%" autostart="true" uimode="full" volume="50" mute="false"> </embed> </object> </p><body onload="loadVideo();"></body> </div> </body> </html> I am trying to validate the form on my site using an external js file. Here is the HTML for my form: <form method="post" form action="sendmail.asp"> <p><label for="emailAddr">Email Address: <input id="emailAddr" name="emailAddr" type="text" size="30" class="reqd email" /> </label></p> <p><span id="spryselect1"> <label for="Players">Players: <select id="player" class="reqd" name="player"> <option value="" selected="selected">Choose a Player</option> <option value="Woodson">Charles Woodson</option> <option value="Rodgers">Aaron Rodgers</option> <option value="Driver">Donald Driver</option> <option value="Hawk">A.J. Hawk</option> <option value="Barnett">Nick Barnett</option> <option value="Bigby">Atari Bigby</option> </select> </label> <span class="selectRequiredMsg">Please select an item.</span></span></p> <p><label for"options"> Size(default is X-Large): <label for="medium"><input type="checkbox" name="options" id="medium" value="Medium" /> X-Large</label> <label for="large"><input type="checkbox" name="options" id="large" value="Large" /> Large</label> </p> <p> <label for="setStyle">Jersy Style: <input type="radio" id="homeStyle" name="setStyle" value="homeStyle" class="radio" /> Home <input type="radio" id="awayStyle" name="setStyle" value="awayStyle" class="radio" /> Away </label></p> <p> <label for="zip"> Zip: <input id="zip" name="zip" type="text" size="10" maxlength="5" class="isZip dealerList" /> </label></p> <p><input type="submit" value="Submit" /> <input type="reset" /></p> <p> </p> <p> </p> </form> Here is the JavaScript file attached: window.onload = initForms; function initForms() { for (var i=0; i< document.forms.length; i++) { document.forms[i].onsubmit = function() {return validForm();} } document.getElementById("medium").onclick = sizeSet; } function validForm() { var allGood = true; var allTags = document.getElementsByTagName("*"); for (var i=0; i<allTags.length; i++) { if (!validTag(allTags[i])) { allGood = false; } } return allGood; function validTag(thisTag) { var outClass = ""; var allClasses = thisTag.className.split(" "); for (var j=0; j<allClasses.length; j++) { outClass += validBasedOnClass(allClasses[j]) + " "; } thisTag.className = outClass; if (outClass.indexOf("invalid") > -1) { invalidLabel(thisTag.parentNode); thisTag.focus(); if (thisTag.nodeName == "INPUT") { thisTag.select(); } return false; } return true; function validBasedOnClass(thisClass) { var classBack = ""; switch(thisClass) { case "": case "invalid": break; case "reqd": if (allGood && thisTag.value == "") { classBack = "invalid "; } classBack += thisClass; break; case "radio": if (allGood && !radioPicked(thisTag.name)) { classBack = "invalid "; } classBack += thisClass; break; case "isNum": if (allGood && !isNum(thisTag.value)) { classBack = "invalid "; } classBack += thisClass; break; case "isZip": if (allGood && !isZip(thisTag.value)) { classBack = "invalid "; } classBack += thisClass; break; case "email": if (allGood && !validEmail(thisTag.value)) { classBack = "invalid "; } classBack += thisClass; break; default: if (allGood && !crossCheck(thisTag,thisClass)) { classBack = "invalid "; } classBack += thisClass; } return classBack; } function crossCheck(inTag,otherFieldID) { if (!document.getElementById(otherFieldID)) { return false; } return (inTag.value != "" || document.getElementById(otherFieldID).value != ""); } function radioPicked(radioName) { var radioSet = ""; for (var k=0; k<document.forms.length; k++) { if (!radioSet) { radioSet = document.forms[k][radioName]; } } if (!radioSet) { return false; } for (k=0; k<radioSet.length; k++) { if (radioSet[k].checked) { return true; } } return false; } function isNum(passedVal) { if (passedVal == "") { return false; } for (var k=0; k<passedVal.length; k++) { if (passedVal.charAt(k) < "0") { return false; } if (passedVal.charAt(k) > "9") { return false; } } return true; } function isZip(inZip) { if (inZip == "") { return true; } return (isNum(inZip)); } function validEmail(email) { var invalidChars = " /:,;"; if (email == "") { return false; } for (var k=0; k<invalidChars.length; k++) { var badChar = invalidChars.charAt(k); if (email.indexOf(badChar) > -1) { return false; } } var atPos = email.indexOf("@",1); if (atPos == -1) { return false; } if (email.indexOf("@",atPos+1) != -1) { return false; } var periodPos = email.indexOf(".",atPos); if (periodPos == -1) { return false; } if (periodPos+3 > email.length) { return false; } return true; } function invalidLabel(parentTag) { if (parentTag.nodeName == "LABEL") { parentTag.className += " invalid"; } } } } function sizeSet() { if (this.checked) { document.getElementById("homeStyle").checked = true; } } Thank you very much in advance for any and all help. I am a noob with JavaScript. I didn't know where else to turn for help. Thanks in advance, guys. The URL of the page I'm working on can be found he http://graph-art.matc.edu/romanot/vi...inal/order.php Hi guys, I am working on my first validation form and although the Submit button works fine and puts me to the landing page, I don't get the alert, when nothing is checked. Please look at my code and help if you can. I really don't need anything fancy, just working 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" /> <meta name="keywords" content="social media survey, social media, media survey, survey, danish media, danish media survey" /> <meta name="description" content="This survey is a school project, not an actual research. It has been designed to figure out the connection between the gender of the Danish users and their knowledge and usage of social media." /> <script language="JavaScript" type="text/javascript"></script> <script> function isRadioButtonSelected(radioGrpName, errorMsg){ var radios = document.getElementsByName(radioGrpName); var i; for (i=0; i<radios.length; i=i+1 ){ if (radios[i].checked){ return true; } } alert(errorMsg); return false; } function validate(){ if(isRadioButtonSelected('gender', 'please select your gender')){ return true; } return false; } </script> <title>The Social Media survey</title> <style type="text/css"> <!-- body { font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif; background: #8DC63F; margin: 0; padding: 0; color: #000; } } a img { border: none; } .container { width: 960px; margin: 0 auto; } .header { background: #FFF; margin-top: 30px; background-color:transparent; background-image:url(header.jpg); background-attachment: fixed; background-position:left center; background-repeat:no-repeat; } .content { padding-left: 50px; padding-right: 50px; padding-top: 30px; padding-bottom: 30px; background-color:#E7EFB9; font-family:Verdana, Geneva, sans-serif; font-size: 13px; } .footer { background: #FFF; } .fltrt { float: right; margin-left: 8px; } .fltlft { float: left; margin-right: 8px; } .clearfloat { clear:both; height:0; font-size: 1px; line-height: 0px; } </style> </head> <body> <div class="container"> <div class="header"><img src="header1.jpg" alt="The Social Media survey" width="960" height="175" /></div> <div class="content"> <form id="page1" action="http://projects.knord.dk/interaction/saveforminfo.aspx" onsubmit="return validate(); method="post"> <input type="hidden" name="surveyid" value="igakotra" /> <input type="hidden" name="landingpage" value="http://www.google.com" /> <input type="hidden" name="usecookie" value="true" /> <h3>1. Choose your gender</h3> <input type="radio" name="gender" value="male" id="male"/><label for "male">Male</label> <input type="radio" name="gender" value="female" id="female"/><label for "female">Female</label><br /><br /> <input type="submit" name="submit" value="Submit"/> </form> </div> <div class="footer"><a href="page1.html"><img src="1page.jpg" width="960" height="99" alt="1/6 pages" /></div> </div> </body> </html> I really need it asap... thanks guys, you're awesome Hello chaps, I'm Nick I'm in the process of creating a web app using Google Maps. What the following code should do is retrieve some xml code from a page, then load it on to the map, using the geocoder to get lat/long values from the address. Most of it's just Google code I've mauled about with. The map loads, but none of the markers load on to the map. I've gone to the php page which generates the XML for the markers and all is fine there. I know the code is a messy crock of junk, I was sort of concentrating on trying to make it work then I'll sort out the nomenclature. Bad methodology, I know. Code: var id = null; var adress = null; var image = null; var point = null; var pointer = null; var geocoder = null; var iconBlue = new GIcon(); iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png'; iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; iconBlue.iconSize = new GSize(12, 20); iconBlue.shadowSize = new GSize(22, 20); iconBlue.iconAnchor = new GPoint(6, 20); iconBlue.infoWindowAnchor = new GPoint(5, 1); var iconRed = new GIcon(); iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png'; iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; iconRed.iconSize = new GSize(12, 20); iconRed.shadowSize = new GSize(22, 20); iconRed.iconAnchor = new GPoint(6, 20); iconRed.infoWindowAnchor = new GPoint(5, 1); var customIcons = []; customIcons["restaurant"] = iconBlue; customIcons["bar"] = iconRed; function load() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(52.2725, -0.8825), 12); geocoder = new GClientGeocoder(); GDownloadUrl("phpsqlajax_genxml3.php", function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { id = markers[i].getAttribute("ID"); address = markers[i].getAttribute("ADDRESS"); image = markers[i].getAttribute("IMAGE"); var point3 = showAddress(address); var marker = createMarker(pointer, id, address, image); map.addOverlay(marker); } }); } } function showAddress(address) { point = geocoder.getLatLng(address,function(point) { if (!point) { alert(address + " not found"); } else { pointer = new GLatLng(point); return pointer; } }); } function createMarker(pointer, id, address, image) { var marker4 = new GMarker(pointer); var html = "<b>" + id + "</b> <br/>" + address + "</b> <br/>" + image; GEvent.addListener(marker, 'click', function() { marker4.openInfoWindowHtml(html); }); return marker4; } Thanks in advance Hi All, I am very new to HTML programming and Javascripts. What I am trying to accomplish is I have a radio button "RequiredApprovalYesNo". When the selection is "Yes", I need fields "Approver" and "ApproverEmail" to be required upon submit. I also need to make sure that a selection is made with this radio button of either Yes or No. Here is my HTML code for these three fields and was wondering if someone could show me how to code this script or, give me an example of a Radio button selection resulting in additional fields being required or not. Thank you in advance. Code: <td> <input type="radio" name="RequireApprovalYesNo" id="RequireApprovalYesNo" value="Yes">Yes <input type="radio" name="RequireApprovalYesNo" id="RequireApprovalYesNo" value="No">No </tr> <tr> <td><table width="190" border="0" align="right" cellspacing="0"> <tr> </tr> </table></td> <tr> <td colspan="3"><div align="left"><em><strong><b style= 'color: red;'>If Yes, You Must Enter an Approver with a corresponding Email:</b> </strong></em></div></td> </tr> <tr> <td height="25"><div align="right">Approver:</div></td> <td> </td> <td><input name="Approver" type="text" id="Approver" size="40";"></td> </tr> <tr> <td height="25"><div align="right"> <p>Approver's Email: </p> </div></td> <td> </td> <td><input name="ApprovalEmail" type="text" id="ApprovalEmail" size="40"></td> </tr> <tr> Hi, I have the below javascript that insert smiles for me. But in Firefox, it is inserting at the bottom of the message Edit: This only happens when there in no text input first before the smile. For exmple Quote: -- Original Message --- test send :-) -- End Original Message --- ;-) I would like it be inserted, like Quote: ;-) -- Original Message --- test send :-) -- End Original Message --- Note: ;-) would be the smile It works fine in Internet Explorer, but Firefox, put it in the wrong place, can anyone help. The javascript code I use is below: Code: //Smile Start var myAgent = navigator.userAgent.toLowerCase(); var myVersion = parseInt(navigator.appVersion); var is_ie = ((myAgent.indexOf("msie") != -1) && (myAgent.indexOf("opera") == -1)); var is_nav = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1) && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1) && (myAgent.indexOf('webtv') ==-1) && (myAgent.indexOf('hotjava')==-1)); var is_win = ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1)); var is_mac = (myAgent.indexOf("mac")!=-1); function smile( txt ) { // document.all.txtmessage.value = document.all.txtmessage.value + txt; // return false; doInsert(" " + txt + " ", "", false,document.getElementById('txtmessage')); } function smile2( txt ) { doInsert(" " + txt + " ", "", false,document.getElementById('txttemplate')); } function smile3( txt ) { doInsert(" " + txt + " ", "", false,document.getElementById('txtcomments')); } function doInsert(ibTag, ibClsTag, isSingle, name_txt) { var isClose = false; var obj_ta = name_txt; //---------------------------------------- // It's IE! //---------------------------------------- if ( (myVersion >= 4) && is_ie && is_win) // if ( (ua_vers >= 4) && is_ie && is_win) { if (obj_ta.isTextEdit) { obj_ta.focus(); var sel = document.selection; var rng = sel.createRange(); rng.colapse; if((sel.type == "Text" || sel.type == "None") && rng != null) { if(ibClsTag != "" && rng.text.length > 0) ibTag += rng.text + ibClsTag; else if(isSingle) isClose = true; rng.text = ibTag; } } else { //-- mod_bbcode begin // this should work with Mozillas if ( (myVersion >= 4) && is_win) { var length = obj_ta.textLength; var start = obj_ta.selectionStart; var end = obj_ta.selectionEnd; if (end == 1 || end == 2) end = length; var head = obj_ta.value.substring(0,start); var rng = obj_ta.value.substring(start, end); var tail = obj_ta.value.substring(end, length); if( start != end ){ if (ibClsTag != "" && length > 0) ibTag += rng + ibClsTag; else if (isSingle) isClose = true; rng = ibTag; obj_ta.value = head + rng + tail; start = start + rng.length; } else{ if(isSingle) isClose = true; obj_ta.value = head + ibTag + tail; start = start + ibTag.length; } obj_ta.selectionStart = start; obj_ta.selectionEnd = start; } else { //-- mod_bbcode end if(isSingle) { isClose = true; } obj_ta.value += ibTag; //-- mod_bbcode begin } //-- mod_bbcode end } } //---------------------------------------- // It's MOZZY! //---------------------------------------- else if ( obj_ta.selectionEnd ) { var ss = obj_ta.selectionStart; var st = obj_ta.scrollTop; var es = obj_ta.selectionEnd; if (es <= 2) { es = obj_ta.textLength; } var start = (obj_ta.value).substring(0, ss); var middle = (obj_ta.value).substring(ss, es); var end = (obj_ta.value).substring(es, obj_ta.textLength); //----------------------------------- // text range? //----------------------------------- if (obj_ta.selectionEnd - obj_ta.selectionStart > 0) { middle = ibTag + middle + ibClsTag; } else { middle = ibTag + middle; if (isSingle) { isClose = true; } } obj_ta.value = start + middle + end; var cpos = ss + (middle.length); obj_ta.selectionStart = cpos; obj_ta.selectionEnd = cpos; obj_ta.scrollTop = st; } //---------------------------------------- // It's CRAPPY! //---------------------------------------- else { if (isSingle) { isClose = true; } obj_ta.value += ibTag; } obj_ta.focus(); return isClose; } function CDE(elemId) { if(document.getElementById(elemId).style.display != "none") document.getElementById(elemId).style.display = "none" else document.getElementById(elemId).style.display = "inline" } //Smile End Thanks for any help you can give me Hi, I have 31 audio files and want to play one each day from a single html button. I have the audio files in the same directory as the html page. I have tried to adapt some code to do this, but have not had success. Any help would be much appreciated! Here is what I have so far: Code: <body> <button id="button" onclick=" " return false">Play</button> </body> <script type="text/javascript"> var currentDay = (new Date()).getDate(); document.getElementById('button').onclick = "proverbs" + currentDay + ".mp4" ; </script> I think this is a relatively simple problem, instead of hard coding the latitude and longitude in map.setCenter I need it to read it in from an XML file, like the the markers do below (.getAttribute("lat") and .getAttribute ("lng")). I hope this makes sense, I've tried changing the code around but I can't seem to make it work. Any help appreciated. Code: // create the map var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng( 49.4008,1.4941), 5); // Read the data from example.xml GDownloadUrl("example.xml", function(doc) { var xmlDoc = GXml.parse(doc); var markers = xmlDoc.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { // obtain the attribues of each marker var lat = parseFloat(markers[i].getAttribute("lat")); var lng = parseFloat(markers[i].getAttribute("lng")); var point = new GLatLng(lat,lng); var html = markers[i].getAttribute("html"); var label = markers[i].getAttribute("label"); // create the marker var marker = createMarker(point,label,html); map.addOverlay(marker); } Hello all, Sorry if this may seem like a silly question, I have searched but not really to sure how to word what I am searching for as I don't know if I am going the right way around it! Basically, I am looking to insert a keyword in to a javascript alert box when someone visits my website, so say they came from codingforums.com, it would say "Welcome, CodingForums.com Visitor". My keyword will be passed from the ad platform I am working with and shows up correctly in the tracking, so I'd imagine it's just a case of having the snippet of code for it to show in the alert, correct? If there is no keyword, I would just like it to say "Welcome Visitor" or something. How do I go about this? Thank you in advance for any help. |