JavaScript - Getmonth What Am I Doing Wrong
I'm new to java and have been given the following piece of code to try and fix.
The code is renaming an existing HTML file with the current date but the problem is the date is out by one. I'm aware that in java Jan=0 Feb=1 etc but just dont know enough to know how to fix this... If I add +1 to getmonth all that happens is the file gets named LEICESTER_DAILY - 24-71-2011 17.20.36 rather than LEICESTER_DAILY - 24-8-2011 17.20.36 Here's the piece of code Code: function makePerm() { var txtFile; // Swap the temporary file with the original if (fileSys.FileExists(grabParentFolderUrl() + 'tempsave.htm')) { txtFile = fileSys.getFile(grabParentFolderUrl() + 'tempsave.htm'); if (!(txtFile.size == 0)) { // Check file is not empty if (fileSys.FileExists(grabParentFolderUrl() + 'LEICESTER_DAILY.htm')) { var today = new Date(); var timeStamp = today.getDate() + '-' + today.getMonth() + '-' + today.getFullYear() + ' ' + today.getHours() + '.' + today.getMinutes() + '.' + today.getSeconds(); txtFile = fileSys.getFile(grabParentFolderUrl() + 'LEICESTER_DAILY.htm'); txtFile.Move(grabParentFolderUrl() + 'LEICESTER_DAILY - ' + timeStamp.toString() + '.htm'); txtFile = fileSys.getFile(grabParentFolderUrl() + 'tempsave.htm'); txtFile.Move(grabParentFolderUrl() + 'LEICESTER_DAILY.htm'); Similar Tutorialsi am making a hire script for my website, we have a summer and a winter rate for hires over 28 days, so if the month is between march and September its one price ( sting 9) and if its not then its sting 8. please can someone help Code: function calculate() { var days = parseInt('0' + document.date.days.value, 10), groupstring, total = 0; <!-- 1 day, 2 days, 3 days, 4 days, 5 days, 6 days, 7 days, 28 DaySummer, 28 DayWinter, Excess Amount, excess miles................................. --> switch (document.date.car.value) { case 'A': groupstring = '2500,5000,7500,10000,12500,12800,13000,45000,42000,25000,10'; break;<!--PANDA/SAMRT --> case 'B': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10'; break;<!--CLIO 3/5/MAN PIC --> case 'CD': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10'; break;<!-- RIO CLIO T PIC AUTO--> case 'E': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10'; break;<!-- VENGA RIO AUTO--> case 'F': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15'; break;<!-- FOCUS/MEGANE/CEED--> case 'G': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,25000,15'; break;<!--ESTATE --> case 'H': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15'; break;<!-- -MONDEO-> case 'I': groupstring = '4500,8000,12000,16000,20000,24000,25000,75000,65000,40000,15'; break;<!--2WD SPORTAGE --> case 'J': groupstring = '5000,9000,13500,18000,22500,26000,27000,80000,80000,40000,15'; break;<!--4WD SPORTAGE --> case 'K': groupstring = '6500,11000,16500,22000,27500,30000,31000,950000,82500,40000,15'; break;<!--GLA + RCZ --> case 'L': groupstring = '7000,12000,18000,24000,30000,35000,360000,120000,1200000,25000,15'; break;<!-- SORENTO--> case 'M': groupstring = '2650,5300,7950,10600,13250,14600,15000,49900,48000,25000,10'; break;<!-- KANGOO--> case 'O': groupstring = '4100,8200,12300,16400,20500,20800,21000,75000,72500,40000,15'; break;<!-- TRAFIC--> } groupstring = groupstring.split(','); m = new Date (document.date.firstDate.value); month = m.getMonth(); if (days > 0 && days < 8) {total = groupstring[days - 1]; } else if (days < 28) {total = (groupstring[6] / 7) * days;} else if (days === 28) {total = groupstring[8];} if (days > 28) {total = (groupstring[8] / 28) * days;} if (month > 3 < 8 && day ==28) {total = (groupstring[9];} Hi all, I've got this working perfectly in FF, I have some code that gets the month of a date object, and it doesn't work in IE and it doesn't make sense why... Code: var date = cdr.c[id].date; var month = date.getMonth(); But .getMonth() returns NaN... It is a valid date object as it works perfectly in FF. If you need more code just ask! I'm trying to make it so that on holidays, my page will say Happy"so and so..." at the top. I only started this 5 minutes ago so that's why it's so under developed. Here's what I have. I'm wanting to know if "today.getMonth.getDate" is valid or would I have to do something else. function startTime() { var today=new Date(); var hol=today.getMonth.getDate() if (hol==4+1) p.s I only want the holiday. I already have a clock but I want them to be separate. The script i'm trying to write consist of asking the user for his name in a form format which is then sent in a cookie. When the user reconnect to the same page, it displays : Hi, "HISNAME", welcome to my site! I don't know what I'm doing wrong, seriously. <!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>Untitled Document</title> <script type="text/javascript"> if ( ! get_cookie ( "username" ) ) { var username = document.write( <form name="name"> <table> <tr> <td valign="top"> Name : </td> <td> <input type="text" name="texte" value=""> </td> <td> <INPUT TYPE="button" NAME="bouton" Value="Click" onClick="testResults(this.form)"> </td> </tr> </table> </form>); if ( username ) { var current_date = new Date; var cookie_year = current_date.getFullYear ( ) + 1; var cookie_month = current_date.getMonth ( ); var cookie_day = current_date.getDate ( ); set_cookie ( "username", username, cookie_year, cookie_month, cookie_day ); } } else { var username = get_cookie ( "username" ); document.write ( "Hi " + username + ", welcome to my website!" ); document.write ( "<br><a href=\"javascript:delete_cookie('username'); document.location.reload ( );\"> Forget about me!</a>" ); } </script> </head> <body> </body> </html> I have some inline javascript/jquery that won't function when I move it from inside the body tag. I want to put it into an external file. The proper Jquery library tag is setup and external .js files are linking correctly, Am I missing something in my code? Thanks. I'm trying add the value of multiple text boxes automatically using javascript i revised the code many many times but i cant find an error or maybe im missing something you can find the source code in the link below http://wilson382.info/code.html or just download the file so you can revise and test code easily http://wilson382.info/build.zip what I want to do will work exactly like this: http://wilson382.info/src.html The working code of this script i got it from http://javascriptsource.com/ so credit goes to them thank in advance to anyone who try to help. edit: it works fine now but its not giving me the correct result the correct result is 1076 check it out: http://wilson382.info/build.html first- i wanted to say (for all those who see it before the Mods remove it) how stupid does a bot have to be to set its spam to be resolved at OP? lol so now my question... I have two divs with some styling. Code: #show{CSS code} #menuDet1{CSS code and visibility:hidden;} I then had in html Code: <div id="show" onmouseover="changevis(1)"></div> <div id="me1"></div> and then a function Code: function changevis(index){ acMenuDet="me" + index; document.getElementById(acMenuDet).visibility="visible"; } a colleague of mine helped me "debug" this until it worked and we came up with Code: function details_visible(index) { var acMenuDet = "menuDet" + index; document.getElementById(acMenuDet).style.visibility = "visible"; ; } function details_hidden(index) { var acMenuDet = "menuDet" + index; document.getElementById(acMenuDet).style.visibility = "hidden"; ; } Note: also changed code in div to Code: <div id="show" onmouseover="details_visible(1)" onmouseout="details_hidden(1)"> Hover over me</div> <div id="menuDet1" style="visibility: hidden;" >Plesam Plesam Plesam Plesam Plesam</div> I do not see off the bat what I was doing wrong- anyone else see what I did incorrectly? First, I am new to javascript... I've been trying to get help on a dynamic menu but no one ever seems to respond... So I will start with the pieces... I do not understand why this chunk of code is not working... All i have is a div and the script is simply supposed to make the div have a new size... here is the script... Code: <script type="text/javascript"> var stretch = 200; function Expand(index) { var dname = "menu" + index; document.getElementById(dname).style.width = stretch+'px'; } </script> here is the styling Code: <style type="text/css"> .show{height:20px; width:100px; display:block; background:lightgreen;} </style> and here is the simple html Code: <div id="menu1" class="show" onclick="runExpand(1)"></div> I get the 'Invalid' confirmation but not the 'Valid' one... WHY? It works when I plug in this instead though... if (user.length < 5) 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>Form Validation</title> </head> <body> <script type="text/javascript"> function checkForm() { var user = document.getElementById('user').value; if (user != "turgeon"){ alert("Invalid Username"); return false; } else{ return true; } } function checkUser() { var user = document.getElementById('user').value; var element = document.getElementById('labelUser'); if(user != "turgeon"){ element.innerHTML = "Invalid Username"; element.style.color = "red"; } else{ element.innerHTML = "Valid Username"; element.style.color = "green"; } } </script> <form onsubmit="return checkForm();"> <input type="text" id="user" onblur="checkUser();" /> <label id="labelUser"></label> <input type="submit" value="submit" /> </form> </body> </html> HTML Code: <!DOCTYPE HTML> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!--META TAGS--> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="description" content="The best of the internet all in one place" /> <meta name="keywords" content="Votillity,Homepage,Directory,email,file sharing,financial,games,jobs,language,literature,maps,music,news,politics,pro wrestling,science,shopping,social,networking,sports,travel,tv,movies,videos,calculate,calculator," /> <meta name="author" content="Matthew Chatterton" /> <meta name="google-site-verification" content="iJB8KNduVUeBu7MBY6Jyw7WqxekCCgVgwq_arLQGAZk" /> <meta name="alexaVerifyID" content="vbR_arpXTayIO5B7nHs9BjLOYFE" /> <!--STOP META TAGS--> <!--EXTERNAL FILES--> <link rel="stylesheet" type="text/css" href="css/main.css" /> <link id="altstyle" rel="stylesheet" type="text/css" href="css/main.css" /> <script type="text/javascript" src="main.js"></script> <link rel="shortcut icon" href="http://votillity.com/img/VotillityIcon.ico" /> <link rel="apple-touch-icon" href="http://votillity.com/img/VotillityAppleTouchIcon.png" /> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <!--STOP EXTERNAL FILES--> <title>Votillity.com</title> <!--CSS INTERNAL--> <!--CSS INTERNAL--> <!--JAVASCRIPT INTERNAL--> <!--JAVASCRIPT INTERNAL--> </head> <body onload="startTime()" style="background:#ffffff;"> <button class="buttontabs" style="position:fixed;top:0;left:0;" onclick="function tabs1()">Tab 1</button> <div> <object id="UUS1" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:80px;" onclick="function tabs2()">Tab 2</button> <div> <object id="UUS2" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:160px;" onclick="function tabs3()">Tab 3</button> <div> <object id="UUS3" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:240px;" onclick="function tabs4()">Tab 4</button> <div> <object id="UUS4" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:320px;" onclick="function tabs5()">Tab 5</button> <div> <object id="UUS5" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:400px;" onclick="function tabs6()">Tab 6</button> <div> <object id="UUS6" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:480px;" onclick="function tabs7()">Tab 7</button> <div> <object id="UUS7" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:560px;" onclick="function tabs8()">Tab 8</button> <div> <object id="UUS8" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <button class="buttontabs" style="position:fixed;top:0;left:640px;" onclick="function tabs9()">Tab 9</button> <div> <object id="UUS9" style="width:100%;height:96%;visibility:hidden;" data="http://Votillity.com/Votillity.html"> <embed src="http://Votillity.com/Votillity.html"/> </object> </div> <p class="counter" style="position: fixed; bottom: -18px; right: 3px;"></p> <span class="time" style="position: fixed; top: 0px; right: 5px; font-weight: 900; color: green;" id="time"></span> </body> </html> Javascript Code: function tabs1() { var tabs1 = [ { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs1.style.visibility='hidden' document.getElementById('UUS1').style.visibility="visible" } function tabs2() { var tabs2 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs2.style.visibility='hidden' document.getElementById('UUS2').style.visibility='visible' } function tabs3() { var tabs3 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs3.style.visibility='hidden' document.getElementById('UUS3').style.visibility='visible' } function tabs4() { var tabs4 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs4.style.visibility='hidden' document.getElementById('UUS4').style.visibility='visible' } function tabs5() { var tabs5 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs5.style.visibility='hidden' document.getElementById('UUS5').style.visibility='visible' } function tabs6() { var tabs6 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs6.style.visibility='hidden' document.getElementById('UUS6').style.visibility='visible' } function tabs7() { var tabs7 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS8') }, { document.getElementById('UUS9') } ]; document.tabs7.style.visibility='hidden' document.getElementById('UUS7').style.visibility='visible' } function tabs8() { var tabs8 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS9') } ]; document.tabs8.style.visibility='hidden' document.getElementById('UUS8').style.visibility='visible' } function tabs9() { var tabs9 = [ { document.getElementById('UUS1') }, { document.getElementById('UUS2') }, { document.getElementById('UUS3') }, { document.getElementById('UUS4') }, { document.getElementById('UUS5') }, { document.getElementById('UUS6') }, { document.getElementById('UUS7') }, { document.getElementById('UUS8') } ]; document.tabs9.style.visibility='hidden' document.getElementById('UUS9').style.visibility='visible' } when I click on the buttons, nothing pops up Hello people, I have just started to dabble in Javascript and for my first 'project' i want to display a popup window in the center of the current browser window. I am usng the following script and when testing it using firefox/mozilla it works really well, however when i test it using Internet Explorer it goes a little wonky. here is my script: function doBubblePopUp(myId, moduleId){ var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } var centerX = parseInt(myWidth / 2) - 225; var centerY = parseInt(myHeight / 2) - 275; i have looked at lots of tutorial and reference sites and with my limited understanding, the above script should work. any help would be gratefully appreciated, document.write('<a href='+'"'+imagelinks[ry]+'"'+' target="_blank"><img src="'+myimages[ry]+'" border=0 max-height="250" max-width="900"></a>') I've looked over this 100 times and can't figure it out. The image shows up and you can click it. The max height and width isn't working and the image isn't opening in a new tab. Any help? here is my code Code: <input type="button" onclick='fetch(\"no\", \"wifi.pl?action=connect&network="+document.getElementById(\'networkname\').value+"\");' value="Connect"> no matter how i try the combinations of '"\" i cannot seem to get the element value in the onclick. the fetch('no', 'url'); // no means just send the info and not get results just incase anyone was wondering. is just an ajax query I realy need help what is wrong with the IF Code: <script type="text/javascript"> function Player(name, xStart, yStart){ this.x = xStart; this.y = yStart; this.name = name; this.walk = playerWalk; this.locate = playerLocate; } var urHere = new Player("You",50,50); function playerWalk(dir){ switch(dir){ case "up": this.y++; break; case "down": this.y--; break; case "left": this.x--; break; case "right": this.x++; break; default: alert("I don't understand: " + dir); } this.locate(); } if (this.y == 50){ document.write ("<h3>Blob Wins!</h3>"); } Hello, if you could please tell me what I did wrong to make this code not work. Can you put a variable in a function callback ? Quote: <script type="text/javascript"> var aaa = prompt('number?') var obja = new Const(aaa); functin Const(numb){ this.x=numb; alert(obja.x); } </script> Okay, ive got 3 css classes. (normalfld, focusfld, and errorfld) When a textbox gets focus, the css class gets set to focusfld, when it looses focus it gets set to normalfld. When a textbox has an error, i set the css class to "errorfld" Now, what I would like to happen is that when a box has been set to "errorfld", when it gets and looses focus, its style will not be changed. This is my first ever attempt at javascripting and im sucking pretty bad. Can someone get me going in the right direction? Here is my attempt, that does not work. It always sets the class, even if the box is set to "errorfld" Code: function DoFocus(fld) { if (fld.classname != 'errorfld') { fld.className = 'focusfld'; } } Any ideas where I went wrong? t.i.a, ~Matt Hello all , I just start my self-lessons on javascript, it is pretty cool, but i have some trouble understanding some , can any one tell me what's wrong with this code, i would like when the user press the button the windows pop-ups. the code: <html> <head> <title>Hello World</title> <script type="text/javascript" src="script.js"></script> </head> <body> <form action="#"> <input type="button" value="Click Me!" id="hibut" /> </form> </body> </html> -------------------------------------------- function Hibye(){ window.alert('Hello...'); window.alert('Bye'); } var hi_button = document.getElementById('hibut'); hi_button.onclick = Hibye(); Thanks........ Code: <html> <title>hi</title> <Head> <SCRIPT language="JavaScript"> <!-- var rand_url= new Array() rand_url[0]="http://www.facebook.com"; rand_url[1]="http://www.youtube.com"; rand_url[2]="http://www.bing.com"; rand_url[3]="http://www.yahoo.com"; rand_url[4]="http://www.google.com"; var rand_num= Math.floor(Math.random()*5); //--> </SCRIPT> </head> <body> <H2>Try your luck!</H2> <a href="javascript:func(rand_url[rand_num])"><img src="http://www.mycasinogames.org/editor/assets/button_playnow.jpg" alt="CLICK ME!"/></a> </body> </html> I'm testing out some JavaScripts, and im using one that give a random link. So, basically they have to click a "Play Now" IMAGE to launch ONE of the links above in the "rand_url" However what is in red isn't working. When clicking the image, it does nothing. Can you help? <HTML> <HEAD> <title>User Emails</title> <%@ script type="text/javascript" %> <% set conn=Server.CreateObject("ADODB.Connection"); conn.Provider="Microsoft.Jet.OLEDB.4.0"; conn.Open "e:/Users.mdb"; if (conn!!Null) {sql="INSERT INTO [CustomerResponse] (UserID,UserName,Company,Inserted,Source,Page)"; sql=sql & " VALUES " & "(" & Request.QueryString(UserId) & ",'" & Request.QueryString(UserName) & "',#" & Date() & "#," & Request.QueryString(Source) & "," & Request.QueryString(Page) & ")"; Set rs=conn.Execute(sql); } %> </script> <meta http-equiv="Refresh" content="5;url=http://www.Microsoft.com"> <STYLE> </HEAD> <body> Do Nothing </BODY> </HTML> ================ End of page ============= Note: e:\ is a local drive in the server box Users.mdb is an Access database Thanks in advance for any support(s) or input(s) |