JavaScript - How To Add To An Existing Element Within An Array
Im trying to add to each element within an array. In this program I have an existing array which is called aScores. I have copied its contents into another array called aScores using slice. Now Im trying to add the value of variable called classCurve to each element of aCurve using a for loop (see under the Curve Scores functrion section). However, it does not seem to add the two together(e.g 78 + 5).
Any advice would be very helpful. Here is my code: Code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script> <!-- var aScores = new Array(); //array to hold test scores var aCurve = new Array(); //array to hold test scores with curve var classAveRounded = 0; //average of test scores var howLong = 0; //length of array -- contingent on how many test scores entered //------------------- LoadScores function ----------------------------- function LoadScores() { var classAve = 0; var rawScores = document.getElementById("Scores").value; aScores=rawScores.split(","); //seperate the test scores by comma //alert(aScores[1]); //test to see if they are separated var howLong = aScores.length; //variable to measure how long the array is for(i=0; i<howLong; i++){ aScores[i] = parseInt(aScores[i]); //convert strings to numbers } //alert(aScores[0] + aScores[1]); //test to make sure array contains numbers aScores.sort(sortNumber); //sort the scores from highest to lowest //insert scores from the array into the score text boxes. for (i=0; i<howLong; i++) { document.getElementById("Score" + i).value = aScores[i]; } //total the test scores var total=0; for(i=0; i<howLong; i++) { total += aScores[i]; } //average the total and insert it into the Average textbox(Math.ceil rounds up aveCalc). classAve = total/howLong; classAveRounded = Math.ceil(classAve); document.getElementById("Average").value = classAveRounded; } //------------------- sortNumber function ------------------------------ function sortNumber(a,b){ return b-a; } //------------------- CurveScores function ----------------------------- function CurveScores() { var classCurve = 0; alert(classAveRounded); if(classAveRounded<75) { classCurve=(75-classAveRounded); }else{ classCurve=0; } alert(classCurve); aCurve=aScores.slice(); //alert(aCurve[7]); //test to see if aCurve holds test scores for(i=0; i<howLong; i++) { aCurve[i]=aCurve[i] + classCurve; } // alert(aCurve[0]); //total the curved scores var totalCurvedScores=0; for(i=0; i<howLong; i++) { totalCurvedScores += aCurve[i]; } //average the total and insert it into the CurvedAverage textbox(Math.ceil rounds up aveCalc). curvedAve = totalCurvedScores/howLong; curvedAveRounded = Math.ceil(curvedAve); document.getElementById("CurvedAverage").value = curvedAveRounded; } --> </script> </head> <body> <table border="1"> <tr style="background-color:#F0F0F0; font-size:10pt; font-weight:bold; text-align:center; vertical-align:bottom"> <td>Score</td> <td>Curved</td> <td>Grade</td> </tr> <tr> <td> <input id="Score0" type="text" style="width:60px;text-align:right"/><br/> <input id="Score1" type="text" style="width:60px;text-align:right"/><br/> <input id="Score2" type="text" style="width:60px;text-align:right"/><br/> <input id="Score3" type="text" style="width:60px;text-align:right"/><br/> <input id="Score4" type="text" style="width:60px;text-align:right"/><br/> <input id="Score5" type="text" style="width:60px;text-align:right"/><br/> <input id="Score6" type="text" style="width:60px;text-align:right"/><br/> <input id="Score7" type="text" style="width:60px;text-align:right"/><br/> <input id="Score8" type="text" style="width:60px;text-align:right"/><br/> <input id="Score9" type="text" style="width:60px;text-align:right"/><br/> </td> <td> <input id="CurvedScore0" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore1" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore2" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore3" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore4" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore5" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore6" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore7" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore8" type="text" style="width:60px;text-align:right"/><br/> <input id="CurvedScore9" type="text" style="width:60px;text-align:right"/><br/> </td> <td> <input id="Grade0" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade1" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade2" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade3" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade4" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade5" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade6" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade7" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade8" type="text" style="width:60px;text-align:center"/><br/> <input id="Grade9" type="text" style="width:60px;text-align:center"/><br/> </td> </tr> <tr> <td><input id="Average" type="text" style="width:60px;text-align:right"/></td> <td><input id="CurvedAverage" type="text" style="width:60px;text-align:right"/></td> <td> </td> </tr> <tr> <td><input type="button" value="Load" style="width:60px;font-size:7pt" onclick="LoadScores()"/></td> <td><input type="button" value="Curve" style="width:60px;font-size:7pt" onclick="CurveScores()"/></td> <td><input type="button" value="Grades" style="width:60px;font-size:7pt" onclick="AssignGrades()"/></td> </tr> </table> <div style="position:relative; left:225px; top:-25px; font-size:10pt"> <b>Enter Scores: </b> <input id="Scores" type="text" style="width:250px; font-family:courier new" value="40,46,48,56,62,64,66,70,76,78"/> </div> </body> </html> Similar TutorialsI know for sure that lastRowTD_s[i] does not have "textarea" element ! The whole page is html valid. Code: else if (lastRowTD_s[i].getElementsByTagName('textarea')) { alert(lastRowTD_s[i].id); //checked, it is the row that does not have "textarea" element. alert(lastRowTD_s[i].getElementsByTagName('textarea')); // gives me [Object HTML collection] !? alert(lastRowTD_s[i].getElementsByTagName('textarea')[0]); //gives me "undefined", heh where has it gone since previous line ? } I am not a master of javascript. I am only beginning. I know how to edit most codes I come by to make them work for what I need them for, but I haven't really been able to get this concept to work. I know there is a way to count the characters of a text box. I have used them a thousand times. (Think twitter) I am making a forum, and I am not self-hosting. So I don't have access to change all of the HTML on the forum software. So, here is what I want to do, and I really just need to know if its possible. There is a reply box on this forum. A pre-existing element. It cannot be changed by going into the html, because I don't have access to it. I want a box to appear underneath it to count the number of characters that are typed into that box, and cut off if they go over. I know of codes that allow you to count characters in a box you create, because you can add the "onkeyup=" to the html... I just don't have access to that part. Do you see where I'm getting at? So to further illustrate, something like this: If it can be done, can someone show me how? I have the idea of how it might work, but I don't know enough to make my own code, only enough to figure out what existing code is talking about. I am sorry if this doesn't make sense. I can try to explain further if need be. Hey CF, I've been meaning to learn the answer to this question for a long time, I guess now is the time and place to hopefully have it answered. I'm wanting to know if there is a technique one can use to have Ajax request live data from a database as it happens but I want it to do this with out having to request a bunch of other information with it. Imagine you come to a webpage and there is the latest 10 comments on a video. Let's say that I want new comments to arrive as they happen (say every 5 seconds we will do an Ajax hit on the server). Let's say for sake of argument there is 2 new comments. Is there a way to make Ajax only request and display the latest 2 comments with out having to refresh the 10 latest as well? If this sounds confusing, try imagine the 10 comments as an array. I just want to pop one off the end and push a new one onto the front. Any tips in the right direction would be great to hear. --------RESOLVED-------- I am trying to make a finance tracker, but for some reason this code will only output the first transaction: Code: <html> <head> <style> tr:nth-child(even) {background: #CCC} tr:nth-child(odd) {background: #FFF} </style> <script type="text/javascript"> var finance={ ls : localStorage, codes : new Array(), getCodes : function (){ finance.codes=(eval("["+finance.ls.code+"]")) return finance.codes; }, dates : new Array(), getDates : function (){ finance.dates=(eval("["+finance.ls.dates+"]")) return finance.dates; }, desc : new Array(), getDescs : function (){ finance.desc=(eval("["+finance.ls.desc+"]")) return finance.desc; }, change : new Array(), getChanges : function (){ finance.change=(eval("["+finance.ls.change+"]")) return finance.change; }, getAll : function(){ var t=new Array(); t[0]=finance.getCodes(); t[1]=finance.getDates(); t[2]=finance.getDescs(); t[3]=finance.getChanges(); return t; }, getRows : function(){ var temp=new Array(); var bal=0; for (i=0;i<finance.getAll()[0].length;i++){ bal+=finance.getAll()[3][i]; var temp3=document.createElement("tr"); var temp4=new Array(); for(a=0;a<6;a++){ temp4[a]=(document.createElement("td")) } temp4[0].innerHTML=finance.getAll()[0][i]; temp4[1].innerHTML=finance.getAll()[1][i]; temp4[2].innerHTML=finance.getAll()[2][i]; temp4[3].innerHTML=((finance.getAll()[3][i]>0)?"":finance.getAll()[3][i]); temp4[4].innerHTML=((finance.getAll()[3][i]<0)?"":finance.getAll()[3][i]); temp4[5].innerHTML=bal; for(i=0;i<6;i++){ temp3.appendChild(temp4[i]); } temp.push(temp3); } for(i=0;i<temp.length;i++){ document.getElementById("fin").appendChild(temp[i]); } } } localStorage.code='" ","1001","DC"'; localStorage.dates='" ","8/30/2010","9/4/2010"'; localStorage.desc='"Starting","Check for Bob","ATM"'; localStorage.change='100,-10,-20'; </script> </head> <body onload="finance.getRows();"> <table id="fin"> <tr><th>Code</th><th>Date</th><th>Description</th><th>Payment</th><th>Deposit</th><th>Balance</th></tr> </table> </body> </html> hahahahaha wow im dumb i forgot that nesting two for statements that use "i" is a nono also i know the code may be sloppy, i am just building it now, i will clean it up later. Hi. I'm fairly new to javascript. I have a code where I'm trying to generate scrollx1 through scrollx100. I can get the array to work with doc.write and I can get one concat variable to work in the element but when I combine them it doesn't work. Any suggestions as to what I need to add to this code: Code: var sp=1; for (sp=1;sp<=100;sp++) { var sx = "scrollx"; var sy = "scrolly"; var thissx = sx + sp; var thissy = sy + sp; theForm[thissx].value = scrollx; theForm[thissy].value = scrolly; } Any help would be much appreciated!! Hi. I'm fairly new to javascript. I have a code where I'm trying to generate scrollx1 through scrollx100. I can get the array to work with doc.write and I can get one concat variable to work in the element but when I combine them it doesn't work. Any suggestions as to what I need to add to this code: var sp=1; for (sp=1;sp<=100;sp++) { var sx = "scrollx"; var sy = "scrolly"; var thissx = sx + sp; var thissy = sy + sp; theForm[thissx].value = scrollx; theForm[thissy].value = scrolly; } Any help would be much appreciated!! What I need help with is sorting the [0] of my array. I need it to sort so that if the user puts in his last name, whether its uppercase or lowercase (Adams, adams), it will sort through the list of students I add, and put them in an alphabetic order i.e adams, Adams, cook, Douglas....and so on. Here is the code that I have below for just sorting by last name, which will seperate the lowercase entries from the uppercase entries. That would be the opposite of what I want. I had it sorted so that it would sort the [o], which is where the last name value is located. Any thoughtful help would be appreciated. Code: function Last_names( s1, s2 ) { if ( s1[0] > s2[0] ) return 1; return 0; } function sortLast(form) { StudentsLists.sort( Last_names ); windows(form);//calling the windows function each time the sortLast function is called } Hi, Below is the code which is used to validate the entries on a form(some field are not be left blank). The user gets the msg when he hits the "Check"button. The problem is after the user gets the msg, I am not able to set the focus in the field which is the first element of an error array which stores the info about the fields with errors on this form. Please help. ========================================================== <html> <head> <script type="text/javascript"> function check_alert() { var errors=[]; if (text1.value==""||text1.value==null) { errors[errors.length]="Please enter the Company Name"; } if(text3.value==""||text3.value==null) { errors[errors.length]="Please enter the Address"; } if(text5.value==""||text5.value==null) { errors[errors.length]="Please enter the City"; } if(text6.value==""||text6.value==null) { errors[errors.length]="Please enter the Zip/Costal Code"; } if(text7.value==""||text7.value==null) { errors[errors.length]="Please enter the Country"; } if (errors.length>0) { reportErrors(errors); return false; } else return true; } function reportErrors(errors) { var msg="There are some errors..\n"; var numerror; for (var i=0;i<errors.length;i++) { numerror=i+1; msg+="\n"+numerror+"."+errors[i]; } alert(msg); document.form.element(errors[0]).focus(); } </script> </head> <body onload="text1.focus()"> Company:<input type="text" name="text1" /><br> Division:<input type="text" name="text2" /><br> Address1:<input type="text" name="text3" /><br> Address2:<input type="text" name="text4" /><br> City:<input type="text" name="text5" /><br> State:<select name="state"> <option value= "Alabama" selected>Alabama</option> <option value= "Alaska">Alaska</option> <option value= "Arizona">Arizona</option> <option value= "Arkansas">Arkansas</option> </select><br> Zip/Postal Code:<input type="text" name="text6"/><br> Country:<input type="text" name="text7" /><br> <input type="button" value="Check" onclick="return check_alert()"/> </body> </html> ======================================================= I want to create an array for a religious website that will display a different Bible verse for each day of the year. This is how I incremented each day of the year. Code: var myDate=new Date(); myDate.setFullYear(2011,2,4); myDate.setDate(myDate.getDate()+1); How do I make the connection between the array and the new date as it changes? This is a snippet from the array. Code: var dailyVerseRef=new Array(); dailyVerseRef[0]="Genesis 1:1"; dailyVerseRef[2]="Genesis 1:2"; dailyVerseRef[3]="Genesis 1:3"; dailyVerseRef[4]="Genesis 1:4"; dailyVerseRef[5]="Genesis 1:5"; dailyVerseRef[6]="Genesis 1:6"; dailyVerseRef[7]="Genesis 1:7"; dailyVerseRef[8]="Genesis 1:8"; I used a switch to go through the days of the week, but to go through the days of the year seems more difficult. Hi all. I am having a problem understanding exactly how setInterval and setTimeout work and really need some help. I want to create an array and then print out each element one at a time at one second intervals. I've only been able to come up with something like this, but it just prints the last value of the array after a second. Code: <script type = "text/javascript"> <!-- var myArray = new Array(); for (var i = 0; i < 11; i++){ myArray[i]=i+50; } for (var i = 0; i < myArray.length-1; i++){ setInterval("document.getElementById('here').innerHTML = myArray[i];", 1000); } //--> </script> <div id="here">Stuff here</div> I'm hoping someone can help correct a small problem with this script, which is intended to highlight particular text strings. Background: The script is being used at a MediaWiki site, and is adapted from a working script from Wikipedia (highlightmyname.js). The original script highlights the logged-in user's username (represented by wgUserName). I've made a copy of the script, which you can see in full here, and adapted it to work on a pre-defined array of names, adding: Code: var Admin; var ArrayAdmins = ['Adam', 'Axiomist', 'Matt', 'Steve']; for (Admin in ArrayAdmins) I also replaced each instance of wgUserName with ArrayAdmins[Admin] The problem: is that, instead of highlighting all instances of every element in ArrayAdmins, only the last element listed ('Steve') is being used. So my question is, what change(s) need to be made to apply function highlightmyname to every element in ArrayAdmins? Any help would be hugely appreciated! The bit of code in bold in the code below is giving me this error in IE: Error: Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; Tablet PC 2.0; InfoPath.2; OfficeLiveConnector.1.4; .NET CLR 3.0.30729; OfficeLivePatch.1.3; MSN OptimizedIE8;ENGB) Timestamp: Tue, 16 Mar 2010 15:07:11 UTC Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917) Line: 0 Char: 0 Code: 0 URI: http://www.mateinastate.co.uk/users/mateinastate Code: Code: if(document.getElementById('msn1').innerHTML=="") { document.getElementById('msn1').style.display='none'; } if(document.getElementById('yahoo1').innerHTML=="") { document.getElementById('yahoo1').style.display='none'; } if(document.getElementById('skype1').innerHTML=="") { document.getElementById('skype1').style.display='none'; } if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,18)=='<a href="http://">') { document.getElementById('facebook1').style.display='none'; } else if(document.getElementById('facebook1').innerHTML.toLowerCase().substr(0,11)=='<a href="">') { document.getElementById('facebook1').style.display='none'; } else { document.getElementById('fbook-add').innerHTML='Facebook Profile'; } What it's saying isn't actually true (I don't think)... this is how the section is laid out: Code: <div id="submenu1" class="anylinkcss"> <ul> <li class="contact-pm"><a href="/index.php?do=pm&act=new&to=$RateViewProfileUserName$&returnurl=$ReturnURL$">PM me</a></li> <li class="contact-email"><a href="/index.php?do=email&id=$RateViewProfileUserId$">E-mail me</a></li> <li class="contact-msn" id="msn1">$RateViewProfileUser-profile_msn$</li> <li class="contact-yahoo" id="yahoo1">$RateViewProfileUser-profile_yahoo$</li> <li class="contact-skype" id="skype1">$RateViewProfileUser-profile_skype$</li> <li class="contact-facebook" id="facebook1"><a href="$RateViewProfileUser-profile_facebook$"><span id="fbook-add"></span></a></li> </ul> </div> <script type="text/javascript" src="/html_1/js/contact-information.js"></script> Does anyone know why this might error in just IE? Hi, I'm relativly new to JS and brand new to the forum so you might need to dumb down your replys for my slightly lacking knowledge. That being said I do have a very solid grasp of html, css and am getting there with JS and its various frameworks. I'm integrating wordpress into an existing site for a friend and currently have the main blog page appear in a DIV. This is the best way to integrate in this case due to many reasons mostly of way the site is constructed. Code: <div class="scroll-pane" id="scrollbox"> WORDPRESS BLOG </div> My issue is that links within that DIV, in the blog, when clicked redirect the page. The simple answer to this would be to have them just open in a new page, which I can easily do with the below code. Code: function Init() { // Grab the appropriate div theDiv = document.getElementById('scrollbox'); // Grab all of the links inside the div links = theDiv.getElementsByTagName('a'); // Loop through those links and attach the target attribute for (var i=0, len=links.length; i < len; i++) { // the _blank will make the link open in new window links[i].setAttribute('target', '_blank'); } } window.onload = Init; But what I'd rather it do is have any link clicked inside the DIV to reload in that same DIV, similar to an iframe, but obviously without using an iframe, due to it's compatibility issues. Is this possible by editing the above code? If not what do I need? Thanks in advance for any help! I have an iframe. I load a page within it. The page I load is a php page that I build with a table with the id of 'readmail_table'. My iframe is 'readmail_frame'. Someone clicks on a message title outside of the iframe and I load the contents of the message in the iframe from the database in my table. Sometimes this takes longer than others depending on how large the message is. What I am doing here is letting the contents load then calculating the width and height of the table and then increasing the iframe's size so there are no scrollbars. This works 98% of the time but I ran into an issue where the table does not exist yet in the iframe and the JS code errors out. So what I did then was add a local var, set it to false then had a while loop check for the table and once it finds it, set the var to false and run my code. Again, mixed results. Sometimes this works then others I get that the table id I am looking for is null but my if statement in the while loop is checking to see if != null line 159 is where it is breaking The error I am getting in firebug is Code: window.frames.readmail_frame.document is null Line 159 Code: 156 var temp = false; 157 while ( !temp ) 158 { 159 if ( window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ) != null ) 160 { 161 //height of the table that holds the actual message 162 var tempheight = window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ).clientHeight; 163 //height of the from, to, subject and date section 164 var tempheight2 = window.frames[ "readmail_frame" ].document.getElementById( 'readmail_heading' ).clientHeight; 165 var tempwidth = window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ).clientWidth; 166 document.getElementById( 'readmail_frame' ).style.width = tempwidth + 'px'; 167 //add up the table for the message, table for from, to, date and icon for print and some extra to ensure enough room 168 document.getElementById( 'readmail_frame' ).style.height = ( tempheight + tempheight2 + 130 ) + 'px'; 169 temp = true; 170 } 171 } I have also tried Code: if ( window.frames[ "readmail_frame" ].document.getElementById( 'readmail_table' ) ) and Code: if ( window.frames[ "readmail_frame" ].document ) Like I said, most of the time this works exactly how I need it. I just need a fool proof way to determine that this table is in fact on the page. I am not sure why it works sometimes and not others since I am looping until it is there Thank you for any help with this. I would like to know if anyone cane explain some javascript source code that i got from the chess.com website. Here is the following code Im talking about: window.Meebo||function(c){function p(){return["<",i,' onload="var d=',g,";d.getElementsByTagName('head')[0].", j,"(d.",h,"('script')).",k,"='//cim.meebo.com/cim?iv=",a.v,"&",q,"=",c[q],c[l]? "&"+l+"="+c[l]:"",c[e]?"&"+e+"="+c[e]:"","'\"></",i,">"].join("")}var f=window, a=f.Meebo=f.Meebo||function(){(a._=a._||[]).push(arguments)},d=document,i="body", m=d[i],r;if(!m){r=arguments.callee;return setTimeout(function(){r(c)},100)}a.$= {0:+new Date};a.T=function(u){a.$[u]=new Date-a.$[0]};a.v=4;var j="appendChild", h="createElement",k="src",l="lang",q="network",e="domain",n=d[h]("div"),v=n[j](d[h]("m")), b=d[h]("iframe"),g="document",o,s=function(){a.T("load");a("load")};f.addEventListener? f.addEventListener("load",s,false):f.attachEvent("onload",s);n.style.display="none"; m.insertBefore(n,m.firstChild).id="meebo";b.frameBorder="0";b.id="meebo-iframe"; b.allowTransparency="true";v[j](b);try{b.contentWindow[g].open()}catch(w){c[e]= d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try{var t= b.contentWindow[g];t.write(p());t.close()}catch(x){b[k]=o+'d.write("'+p().replace(/"/g, '\\"')+'");d.close();'}a.T(1)}({network:"chess"}); </script> Hi guys! As title says I need to create variable named with value of other variable! So is that possible? What exactly I need is something like this: Code: for(var i=0; i<11; i++){ var Img[i] = "" } Hi all and hope you can help. I have a form validication function that checks a variety of form inputs which appears to be working fine. Trouble is that if I deliberately throw it some non-valid entries it clears the form with the data I've already supplied. Can anyone suggest a method for preserving the input the user has already made so that this doesn't need to be re-input when the user has input invalid data? My thanks Rog Here's my validation code. which checks.. Whether a user has input their full name - entering full name is optional and if not true will negate subsequent checks, i.e. doesn't bother checking any other inputs. Whether a user has supplied both first and last names, fail message pops up if not. Whether a user has suppllied a full name but not an email or telephone number, fail message pops up if not. Whether a user has supplied a valid email address, fail message pops up if not. Whether a user has supplied a valid telephone number, fail message pops up if not. If we've passed all these tests, O.K. - submit. Code: function check_id(){ var status = false; var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; var telRegEx = /^\s*\(?(020[7,8]{1}\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3}\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$/; // 1st test, are the name fields blank, this is valid if the user doesn't want to enter the draw? if (document.feedback.first.value =="" && document.feedback.second.value =="") { status=false; confirm("You will not be entered in our free prize draw unless you supply your full name and email address or telephone number. Is that O.K?"); return status; } // 2nd test, has the user supplied both a first name and surname? else if (document.feedback.first.value =="" || document.feedback.second.value =="") { status=false; alert("You need to supply your full name to enter the draw."); } // 3rd test, has the user supplied a full name but not supplied an email address or tel number, this isn't valid. else if (document.feedback.email.value =="" && document.feedback.tel.value ==""){ status=false; alert("You need to supply either a valid email address or telephone number to enter the draw."); } // 4th test, user has supplied an email address and / or an email address and tel, check each. else if(document.feedback.email.value !=""){ // 4th test part 1, user has supplied an email address, check it is valid. if (document.feedback.email.value.search(emailRegEx) == -1) { alert("Please enter a valid email address."); status=false; } else { alert("Thank you. You will be entered into our free prize draw. Good luck!"); status = true; } return status; } // 4th test part 2, has the user supplied a tel number, this is a valid option, check it. else if (document.feedback.tel.value !="" ) { if (document.feedback.tel.value.search(telRegEx) == -1) { alert("Please enter a valid telephone number."); status=false; } else { alert("Thank you. You will be entered into our free prize draw. Good luck!"); status = true; } return status; } } If i have an existing HTML Select statement with options specified, and then based on an even, i want to rebuild that options list, how do I wipe the existing options parameters in order to add new ones? Is that even possible?
I am working on a site which is pretty old school.. i have a vertical drop down menu using javascript which uses <img src tag>.. Check the tab fountains at http://www.texaslakesandponds.com/index_html.html (it has a vertex and kasco dropdown) I want to add a similar dropdown for Aerators with the same format and color. I dont know how to do that since it uses a <ul><li> format and the image is called in the css class. Can someone please help me with the code. Hi, I have a script that shows/hides a div but rather than making it sort of snap I would like to make it glide/slide. I have looked at other scripts but can't make them work with mine. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>test</title> <style type="text/css" media="screen"> /* CSS Reset */ * { margin: 0; padding: 0; border: 0; outline: 0; } body { font-family: Arial, Helvetica, sans-serif; background-color: #FFFFFF; color:#FF0000; } a:link { color: #999999; text-decoration: none; letter-spacing: 3px; font-size:14px; } a:visited { color: #999999; text-decoration: none; letter-spacing: 3px; font-size:14px; } a:hover { color: #FF0000; letter-spacing: 3px; text-decoration: none; font-size:14px; } a:active { color: #FF0000; font-size:14px; letter-spacing: 3px; } #wrapper{ position:relative; width:730px; height:600px; margin:0px auto; } #images{ width:730px; height:552px; overflow:hidden; float:right; position: absolute; top: 48px; } #textbox{ position: absolute; width:205px; height:40px; background-color: #FFFFFF; top: 68px; left: 20px; z-index: 2; padding: 10px; border-bottom: 2px solid red; } #logo { position: absolute; width: 101px; position: absolute; left: 634px; top: 19px; padding: opx; margin: 0px; z-index: 2; } .more { display: none; text-decoration: none; font-family: Arial, Helvetica, sans-serif; background-color: #FFFFFF; border-bottom: 2px solid red; padding-left: 8px; padding-right: 8px; margin-left: -10px; width: 209px; padding-bottom:10px; } a.mo hover { text-decoration: none;} a.showLink, a.hideLink { text-decoration: none; font-size: xx-small; color: #36f; padding-left: 8px; /*** background: transparent url(down.gif) no-repeat left;***/ } a.hideLink { /*** background: transparent url(up.gif) no-repeat left;***/ } .drop1 { font-size: 12px; font-weight: bold; } .drop2 { color: #666666; font-size: smaller; } #apDiv1 { position:absolute; left:319px; top:87px; width:234px; height:32px; z-index:1; } .init_image, .inactive_class { } .hover_class, #active_id { color:#F00; } </style> <script language="javascript"> function toggle() { var ele = document.getElementById("toggleText"); var text = document.getElementById("displayText"); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "<img src=ShowProduct.jpg border='0'>"; } else { ele.style.display = "block"; text.innerHTML = "<img src=hideProduct.jpg border='0'>"; } } </script> <script type="text/javascript"> // Reference URL to large images here var Images = new Array( "001.jpg", "002.jpg", "003.jpg", "004.jpg" ); function swap(el) { var timgs=document.getElementsByTagName('a') for (var i_tem = 0; i_tem < timgs.length; i_tem++) if (timgs[i_tem].className=='inactive_class'||timgs[i_tem].className=='hover_class') timgs[i_tem].id='' el.id='active_id' document['imgMain'].src = Images[el.href.substr(el.href.lastIndexOf('#')+1)]; } function init(){ var timgs=document.getElementsByTagName('a') for (var i_tem = 0; i_tem < timgs.length; i_tem++) if (timgs[i_tem].className=='init_image'){ timgs[i_tem].className='inactive_class' timgs[i_tem].onmouseover=function(){this.className='hover_class'} timgs[i_tem].onmouseout=function(){this.className='inactive_class'} timgs[i_tem].onclick=function(){swap(this);return false;} } swap(document.getElementById('first')); } </script> </head> <body onLoad="init();"> <div id="wrapper"> <div id= logo><img src="logo2.png" width="101" height="92" /></div> <div id="textbox"> <div style="position:relative;"> <img style="padding-right:5px;" src="logo_dedon.png" alt=""/> <a href="javascript:toggle();" id="displayText"><img src=ShowProduct.jpg border="0"></a> <img style="padding-right:5px;" src="clear.gif" alt="" width="135" height="10" /> <a class="init_image" id="first" href="#0">1</a> <a class="init_image" id="first" href="#1">2</a> <a class="init_image" id="first" href="#2">3</a> <a class="init_image" id="first" href="#3">4</a> </div> <div id="toggleText" style="display: none;" class="more"> <p><span class="drop1">BARCELONA</span><br /> <span class="drop2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin non mi in urna hendrerit tincidunt. Maecenas eleifend erat et lacus. Sed tempor. Sed venenatis consequat neque. Sed massa. Donec quis orci sed lacus ullamcorper venenatis. </span></p> </div> </div> <div id="images"> <div><img galleryimg="no" name="imgMain" src="img/big/1big.jpg" alt=""></div> </div> </div> </body> </html> Can anyone advise a solution for this please? Thanks alot Joe |