JavaScript - Special Of The Day With Getday()
I am trying to make a page that shows a daily special for a *fake* pizza place. I want it to detect the day it is, and write the special within the document as an H1 heading or something like that. For testing I have it setup to do an Alert, but it alerts me of the monday special today which is correct, but if I change my system time to another day it doesn't work. Does it work like that or is there a better way to test it?
Here is the code, there is a <body onload="getToday()"> in place Code: function getToday() { var d = new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; if (weekday[d.getDay()] = 0) { alert("Buy one Pizza get a second for only $5"); } else if (weekday[d.getDay()] = 1) { alert("Order of Breadsticks for $1"); } else if (weekday[d.getDay()] = 2) { alert("Order of Cinnamon Sticks for $1"); } else if (weekday[d.getDay()] = 3) { alert("Free Two Liter with Pizza Order"); } else if (weekday[d.getDay()] = 4) { alert("Order of Hot Wings for $1"); } else if (weekday[d.getDay()] = 5) { alert("Orders of Breadsticks, Cinnamon Sticks, and 2 liter for $3 with"); } else if (weekday[d.getDay()] = 6) { alert("Breadsticks and a two liter for $1"); } } </script> Similar TutorialsI am using the following script to have a calander displayed in my form. It displays a calender on which a user can select a date. If the date is a friday, something else should happen in the form than when selecting other days (see final 15 lines, no need to be specific). The problem is that the code only works for months with 30 days in it. E.g. The september month works fine, when a friday is selected (javascript:setCalendarControlDate(2009,9,25)) the correct changes occur. For the October month (31 days) the same changes that occur correct in september occur in october when selecting thursday, but these should be when selecting friday instead! For November (30 days) everything works fine again, but then for December (31 days) the changes occur again at thursday instead of friday For February (2010) I need to select sunday to get the needed changes. Like I said, I think it has something to do with the amount of days in a month. Since the code works fine on months with 30 days, but not on months with other amounts of days. Can anyone tell me what's wrong in the code? Code: function positionInfo(object) { var p_elm = object; this.getElementLeft = getElementLeft; function getElementLeft() { var x = 0; var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } while (elm != null) { x+= elm.offsetLeft; elm = elm.offsetParent; } return parseInt(x); } this.getElementWidth = getElementWidth; function getElementWidth() { var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } return parseInt(elm.offsetWidth); } this.getElementRight = getElementRight; function getElementRight() { return getElementLeft(p_elm) + getElementWidth(p_elm); } this.getElementTop = getElementTop; function getElementTop() { var y = 0; var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } while (elm != null) { y+= elm.offsetTop; elm = elm.offsetParent; } return parseInt(y); } this.getElementHeight = getElementHeight; function getElementHeight() { var elm; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } return parseInt(elm.offsetHeight); } this.getElementBottom = getElementBottom; function getElementBottom() { return getElementTop(p_elm) + getElementHeight(p_elm); } } function CalendarControl() { var calendarId = 'CalendarControl'; var currentYear = 0; var currentMonth = 0; var currentDay = 0; var selectedYear = 0; var selectedMonth = 0; var selectedDay = 0; var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; var dateField = null; function getProperty(p_property) { var p_elm = calendarId; var elm = null; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } if (elm != null) { if(elm.style) { elm = elm.style; if(elm[p_property]) { return elm[p_property]; } else { return null; } } else { return null; } } } function setElementProperty(p_property, p_value, p_elmId) { var p_elm = p_elmId; var elm = null; if(typeof(p_elm) == "object") { elm = p_elm; } else { elm = document.getElementById(p_elm); } if((elm != null) && (elm.style != null)) { elm = elm.style; elm[ p_property ] = p_value; } } function setProperty(p_property, p_value) { setElementProperty(p_property, p_value, calendarId); } function getDaysInMonth(year, month) { return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1]; } function getDayOfWeek(year, month, day) { var date = new Date(year,month-1,day) var DayOfWeek = date.getDay(); if(DayOfWeek == 0) DayOfWeek = 6; else DayOfWeek--; return DayOfWeek; } this.setDate = setDate; function setDate(year, month, day) { if (dateField) { if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } var dateString = day+"-"+month+"-"+year; dateField.value = dateString; hide(); } return; } this.changeMonth = changeMonth; function changeMonth(change) { currentMonth += change; currentDay = 0; if(currentMonth > 12) { currentMonth = 1; currentYear++; } else if(currentMonth < 1) { currentMonth = 12; currentYear--; } calendar = document.getElementById(calendarId); calendar.innerHTML = calendarDrawTable(); } function getCurrentYear() { var year = new Date().getYear(); if(year < 1900) year += 1900; return year; } function getCurrentMonth() { return new Date().getMonth() + 1; } function getCurrentDay() { return new Date().getDate(); } function calendarDrawTable() { var dayOfMonth = 1; var validDay = 0; var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth); var daysInMonth = getDaysInMonth(currentYear, currentMonth); var css_class = null; //CSS class for each day var table = "<table cellspacing='0' cellpadding='0' border='0'>"; table = table + "<tr class='header'>"; table = table + " <td colspan='2' class='previous'><a href='javascript:changeCalendarControlMonth(-1);'><</a></td>"; table = table + " <td colspan='3' class='caltitle'>" + months[currentMonth-1] + "<br>" + currentYear + "</td>"; table = table + " <td colspan='2' class='next'> <a href='javascript:changeCalendarControlMonth(1);'>></a></td>"; table = table + "</tr>"; table = table + "<tr><th>Mon.</th><th>Tues.</th><th>Wed.</th><th>Thurs.</th><th>Fri.</th><th>Sat.</th><th>Sun.</th></tr>"; for(var week=0; week < 6; week++) { table = table + "<tr>"; for(var dayOfWeek=0; dayOfWeek < 7; dayOfWeek++) { if(week == 0 && startDayOfWeek == dayOfWeek) { validDay = 1; } else if (validDay == 1 && dayOfMonth > daysInMonth) { validDay = 0; } if(validDay) { if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) { css_class = 'current'; } else if (dayOfMonth == getCurrentDay() && currentYear == getCurrentYear() && currentMonth == getCurrentMonth()) { css_class = 'today'; } else if ((dayOfWeek == 5 || dayOfWeek == 6) && (dayOfMonth > getCurrentDay() || currentMonth > getCurrentMonth() || currentYear > getCurrentYear())) { css_class = 'weekend'; } else { css_class = 'weekday'; } if (((dayOfMonth < getCurrentDay() && currentMonth <= getCurrentMonth()) && currentYear <= getCurrentYear()) || currentYear < getCurrentYear()) { table = table + "<td><span class='dayinpast'>"+dayOfMonth+"</span></td>"; } else { table = table + "<td><a class='"+css_class+"' href=\"javascript:setCalendarControlDate("+currentYear+","+currentMonth+","+dayOfMonth+")\">"+dayOfMonth+"</a></td>"; } dayOfMonth++; } else { table = table + "<td class='empty'> </td>"; } } table = table + "</tr>"; } table = table + "<tr class='header'><th colspan='7' style='padding: 3px; text-align:center;'><a href='javascript:hideCalendarControl();'>Close</a></td></tr>"; table = table + "</table>"; return table; } this.show = show; function show(field) { if (dateField == field) { hide(); return; } else { dateField = field; } if(dateField) { try { var dateString = new String(dateField.value); var dateParts = dateString.split("-"); selectedDay = parseInt(dateParts[0],10); selectedMonth = parseInt(dateParts[1],10); selectedYear = parseInt(dateParts[2],10); } catch(e) {} } if (!(selectedYear && selectedMonth && selectedDay)) { selectedMonth = getCurrentMonth(); selectedDay = getCurrentDay(); selectedYear = getCurrentYear(); } currentMonth = selectedMonth; currentDay = selectedDay; currentYear = selectedYear; if(document.getElementById) { calendar = document.getElementById(calendarId); calendar.innerHTML = calendarDrawTable(currentYear, currentMonth); setElementProperty('display', 'block', 'CalendarControlIFrame'); setProperty('display', 'block'); var fieldPos = new positionInfo(dateField); var calendarPos = new positionInfo(calendarId); var x = fieldPos.getElementLeft() - document.getElementById('table_left').scrollLeft; var y = fieldPos.getElementBottom() - document.getElementById('table_left').scrollTop; var w = calendarPos.getElementWidth(); var h = calendarPos.getElementHeight(); var ch = document.getElementById('table_left').style.height; ch = parseInt(ch.substring(0, ch.length-2)) + 143; var cw = document.getElementById('table_left').style.width; cw = parseInt(cw.substring(0, cw.length-2)) + 150; if(y+h > ch) y = ch - h; if(x+w > cw) x = cw - w; setProperty('left', x + "px"); setProperty('top', y + "px"); setElementProperty('left', x + "px", 'CalendarControlIFrame'); setElementProperty('top', y + "px", 'CalendarControlIFrame'); setElementProperty('width', w + "px", 'CalendarControlIFrame'); setElementProperty('height', h + "px", 'CalendarControlIFrame'); } } this.hide = hide; function hide() { if(dateField) { setProperty('display', 'none'); setElementProperty('display', 'none', 'CalendarControlIFrame'); dateField = null; } getSelectedDate('cd_pickup_date') } } var calendarControl = new CalendarControl(); function showCalendarControl(textField) { calendarControl.show(textField); } function hideCalendarControl() { calendarControl.hide(); } function setCalendarControlDate(year, month, day) { calendarControl.setDate(year, month, day); } function changeCalendarControlMonth(change) { calendarControl.changeMonth(change); } document.write("<div id='CalendarControl'></div>"); function getSelectedDate(value) { var selectedDate = document.getElementById('cd_pickup_date').value; var selectedDateArray = selectedDate.split("-"); var convertedDate = new Date(selectedDateArray[2],selectedDateArray[1],selectedDateArray[0]); var selectedDay = convertedDate.getDay(); var weekDay = new Array("Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"); if(weekDay[selectedDay] == "Friday") { document.collectionform.cd_saturday[0].checked = true; document.collectionform.cd_saturday[0].disabled = false; document.collectionform.cd_saturday[1].disabled = true; getAlternateAddress('Yes'); } else { document.collectionform.cd_saturday[1].checked = true; document.collectionform.cd_saturday[1].disabled = false; document.collectionform.cd_saturday[0].disabled = true; getAlternateAddress('No'); } } I find it odd that this function is returning the day as 1, when it is clearly the 28th. when I run the code the answer I get looks like this: 1-Feb-2011 9:27 Code: function getDateTime(when) { var theDate = new Date(); var day = theDate.getDay(); var month = theDate.getMonth(); var year = theDate.getFullYear(); var myTimeArr = theDate.toTimeString().split(":"); var monthNumber = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") when.value = day + "-" + monthNumber[month] + "-" + year + " " + myTimeArr[0] + ":" + myTimeArr[1]; any advice? In Brno, 07.06.2011 Hello everybody, i really need your help with one issue. I have got one page running under Wordpress and i would like to add some countdown to widget to show when i will be again online. for example: I am online every working day (monday - friday) from 08:00 AM to 04:30 PM. So it would be nice to show to my subscribers when i would be online again. So lets think about that is Thuesday 07:00 PM, so on my page would be visible this: "I will be back in 13 hours, 00 minutes, 00 seconds" Or in Saturday at 07:00 PM there will be written: "I will be back in 37 hours, 00 minutes, 00 seconds" I would really apreciate every help, thank you in advance! Stefan alias "Scharfheimlich" Hello, this is only for specialist in javascript. I searching a very special javascript, which can be done expire a web site after some identified time(i.e 10days, 20days....). I have made a web site. now i'm looking for, the site expire(or not working at hosting) within 10 days. can I find any special javascript like this? hi, I would like to change my validation page so that a user cannot use special characters in the form, here is my code below Code: jQuery("#full_name").validate({ expression: "if (VAL) return true; else return false;", message: "Please enter your name" }); jQuery("#name").validate({ expression: "if (VAL.match(/^[^\\W][a-zA-Z\\_\\-\\.]+([a-zA-Z\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;", message: "Please enter your name" }); I am trying to make a very simple form so a user can enter some text then be redirected to a page that uses that text in the URL. So far I have this working using window.open but the ? and & in the URL show up as & # 0 3 8 ; here is the code in the body; Code: <script type="text/javascript"> /* <![CDATA[ */ function orderBlog() { var subDomain = document.blogDomain.domainEntered.value; window.open("http://mydomain.com/portal/cart.php?=add&pid=15&domainoption=subdomain&sld=" + subDomain + ""); } /* ]]> */ </script> <form name='blogDomain' onsubmit="orderBlog();"> <input type='text' name='domainEntered' size='60' style='width:100px;' /> .mydomain.com <input type="submit" value="Get Your Site!" /> </form> but for some reason that goes to the URL mydomain.com/portal/cart.php & # 0 3 8 ; =add & # 0 3 8 ; pid=15 & # 0 3 8 ; domainoption=subdomain & # 0 3 8 ; sld=XXXXXXXX when using firfox, ie7 works fine Hello, I need to improve an existing JavaScript redirect by adding a second redirect based on information contained in the URL. First I will outline the situation, then the specifics: I designed a Realtor website using Joomla 1.5 a few years ago. I will call this SITE-1. The site, SITE-1, displays real estate listing from another site (SITE-2) using iFrames. So the listings from SITE-2 appear to be integrated into the pages of SITE-1. Someone shopping for real estate signs up to be notified of new listings. A new listing comes out and an email is sent to the user with a link to the listing - only the link to the listing is located on SITE-2. So I have been using a JavaScript redirect on SITE-2 that asks the question - "is this in an iFrame" ... if no - redirect to SITE-1 and iframe the results. SITE-1 is ready to receive and parses the new URL: Code: <script language="JavaScript"> <!-- // Start if (window == top) { tops = top.location.href location.replace('http://www.SITE-1.com/index.php?option=com_content&view=article&id=42&Itemid=137&iframe='+tops); } // End --> </script> Now, I have a new problem. I don't have access to SITE-2, I only get to submit a template to them. One of the possible links sent to users from SITE-2 contains a variable in the URL: &id=, followed by a 3 digit number. So the full URL might look like this: http://www.site-2.com/index.php?pg=delacct&id=570 I cannot redirect this to the normal page on SITE-1 because Joomla already uses id=, and it just gets confused and drops a 404 page. Instead I need the code I posted above, to FIRST check for id=. If it exists - go to PAGE-A. If not - then do what the script already does as posted above (we'll call that PAGE-B). Can anyone help? (hopefully I explained that so it can be understood) Thanks, --Kevin Hey. Yes, I'm just starting at the beginning and what I'm trying to understand today is adding special characters such as line break, quotes, etc. into Javascript. I'm missing something, however. Can someone please assist? What I'm trying to do is add a line break without having it show /n on the screen. My Code: <html> <head> <title>Exercise 6-20</title> </head> <body><pre> ********* *** * *\n * * * * *** * *\n * * * * ***** * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n ********* *** * * *\n </pre> </body> </html> Thank you, H First of all thanks for all the help you are providing. I am looking to alert a user if they type in an character that I am going to not allow for their input box Code: function IsExc (str){ var AllChr = "~ # $ % ^ { } [ ] ' ,"; var AC= AllChr.split(" "); var SC = 0; for (SC=0; SC <= AC.length; SC++){ var ACS = AC[SC]; if (str.search(ACS) >0 ) alert ('Cannot use the characters' + AllChr ) } } For reasons I don't understand the code will not work HELLO FELLAS, can someone please show me where get drop down menu like the one goldman sachs uses. take a look please: http://www2.goldmansachs.com/ help is much appreciated julio Hallo. I am a total newbie to JavaScript coding, but I would like to have a price calculator on our internal website. It should calculate the square meter of the product and then multiply it with the square meter price, multiply it with quantity and then plus it with the startup cost. But... if the square meter extend 20 m2 the square meter price should be lower, and also lower when it hit 50 m2. And at 100 m2 it should write that you have to contact sales department. Can this be done with JavaScript? Here is an example: 6 pieces of 2 x 4 meter. 2x4 = 8 m2 6x8 = 48 total m2 48 m2 x price2 x startup = total price I really hope that someone can help me... //Daniel Is there an inbuilt function in javascript to convert web characters like
Code: & back to '&' for use in a search text field? I am trying to get a series of dynamic digits from page one to page two via the url. below are the codes have been able to come up with. The problem am having however is that the variables from the first page contains two other characters mainly (=) and (on). therefore, the result i get is like this; 2=on43=on6=on76=on98=on34=on etc What i want displayed are simply the numbers without these two characters. Code: <script> if(window.location.search){ var query = window.location.search.substr(1); var data = query.split("&"); for (var i = 1; i <= 9; i++){ var data = datas[i].split("="); if (unescape(data[1]) == key_str); data.replace(/\=/g," "); } } </script> below is the code that writes the output Code: <script> for (i = 1; (i <= 9); i++) { document.write(data[i]); data[i]="" } </script> thanks Hi I have downloaded the code to allow special html characters in <textarea> be replaced with the actual code so it does not cause problem when the text is submitted into the database. For example '>' to be replaced with '>' So for a string ' 3 > 2' I expect to be replaced with '3 > 2; in the text box. However it does not work. I put in the alert statements and it shows that the js function is being invoked, but after the function is done, the special characters in the text box remain the same. Can someone help? <html> <header> </header> <body> <script language="javascript"> function html2entities(){ var re=/[(<>"'&]/g for (i=0; i<arguments.length; i++) alert("check char"+ arguments[i].value); arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)}) } function replacechar(match){ if (match=="<") return "<" else if (match==">") return ">" else if (match=="\"") return """ else if (match=="'") return "'" else if (match=="&") return "&" } </script> <form> Data 1 <textarea name="data1" style="width: 400px; height: 100px"></textarea><br /> <input type="button" onClick="html2entities(this.form.data1)" value="Convert special chars to entities"> </form> </body> </html> This code is a bit full on, but it works in IE. I am not suspecting the document.write part, but can anyone tell me why this code fails in Firefox? I think it might be the focus parts in red. Is it not right for FF? Code: function Flash1(tickerstring){ var speedText='<html><head><title>Flashcards - Speed 1</title><script>var sTickString="'+tickerstring+'"</script><script src="flasher(AC).js" language="JavaScript1.2"></script><script>var timeOutVal=300;</script></head> <body onLoad="self.focus()" onBlur="self.focus()"> <a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr><div id=\"bottom_section\"> <\/div>'; function NewWindow(mypage,myname,w,h){ LeftPosition=(screen.width)?(screen.width-w)/2:100; TopPosition=(screen.height)?(screen.height-h)/2:100; settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,resizable=no,status=yes'; win=window.open(mypage,myname,settings); win.document.write(speedText); win.document.close(); if(win.focus){win.focus();} win.refresh; } NewWindow('popup.html','flashcards','620','140'); } Hi guys (and ladies) I am a bit stuck and hope this community might shine a light, or even better can supply me with a solution. I want to do the following: - Having an ordinary webpage containing links - I will link the links with files (word processing files , MS Word, Open Office writer, wordpad or similar) - Now when clicked on the link I want the 'system' to copy the contents of the linked file to the windows clipboard, so when clicking paste, the text from the file is pasted wherever I want. To make clear, I don't want any word processing app to open, just click the link and paste where it needs to be. Possible?? MOST LIKELY but I have no clue how. Any chance someone might know the answer??? I am looking forward to the replies! Thanks PvL http://mybestmaterial.blueeyedpandahosting.com/cep/1/ Works exactly as expected (and all the code is built into the source code view of the page.) What happens is 2 timers are set up. 1 is running when user clicks the Start/Stop link. The second is started when the user clicks the Laughter Start/Stop link. So the sequence should be User -- Start click then after that -- laughter-start-stop click... You will see both timers start running. The laughter click will be clicked multiple times as the app is designed to time how much laughter a comedian or speaker is getting relative to the amount of time on stage. So click the laughter start stop multiple times before clicking the START-STOP the last time. Then a PAR score is generated - which is a simple percent of the time laughter happened, vs the time on stage. The link above works like a charm. THE PROBLEM is -- on my SPRINT TREO 700p --- when I click the laughter start/stop click it stops all the timers. I think for some reason the TREO won't allow the second NEW DATE() to be declared or something... because when I comment those two lines out --- line 166 and 167 in Dreamweaver version of the file -- (if you copy full source into dreamweaver...) Then the clicking doesnt' stop the main timer -- but it also doesn't work!! ANY THOUGHTS on how to decloare the SCOPE fo the NEW DATE() so it only effects that one function? OR any other suggestions? Code pasted below 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=ISO-8859-1" /> <title>Comedy Analyzer - Simple</title> </head> <script type="text/javascript"> var flagclock = 0; var flagstop = 0; var stoptime = 0; var currenttime; var splitdate = ''; var output; var clock; function startstop() { //var startstop = document.getElementById('startstopbutton'); var startdate = new Date(); var starttime = startdate.getTime(); if(flagclock==0) { flagclock = 1; counter(starttime); } else { if(laughter_flagclock==1) { laughter_startstop(); } flagclock = 0; flagstop = 1; splitdate = ''; //total laughter === running_total_laughter_time; //total time == running_total_time; var par_score = (Math.round(running_total_laughter_time/running_total_time*100))/100; var par_score_percent = par_score*100; //var par_score = running_total_laughter_time/running_total_time; laughter_output.value = "PAR SCORE = " + par_score_percent; } } var running_total_time; function counter(starttime) { output = document.getElementById('output'); clock = document.getElementById('clock'); laughter_output = document.getElementById('laughter_output'); currenttime = new Date(); var timediff = currenttime.getTime() - starttime; if(flagstop == 1) { timediff = timediff + stoptime } if(flagclock == 1) { clock.value = formattime(timediff,''); running_total_time = timediff; refresh = setTimeout('counter(' + starttime + ');',10); } else { //start and stop the running counter while adding the values to the next deal. window.clearTimeout(refresh); stoptime = timediff; } } function formattime(rawtime,roundtype) { if(roundtype == 'round') { var ds = Math.round(rawtime/100) + ''; } else { var ds = Math.floor(rawtime/100) + ''; } var sec = Math.floor(rawtime/1000); var min = Math.floor(rawtime/60000); ds = ds.charAt(ds.length - 1); if(min >= 60) { startstop(); } sec = sec - 60 * min + ''; if(sec.charAt(sec.length - 2) != '') { sec = sec.charAt(sec.length - 2) + sec.charAt(sec.length - 1); } else { sec = 0 + sec.charAt(sec.length - 1); } min = min + ''; if(min.charAt(min.length - 2) != '') { min = min.charAt(min.length - 2)+min.charAt(min.length - 1); } else { min = 0 + min.charAt(min.length - 1); } return min + ':' + sec + ':' + ds; } function resetclock() { if(flagclock == 1) { //alert("if side of reset clock"); var resetdate = new Date(); var resettime = resetdate.getTime(); counter(resettime); } else { //alert("ELSE side of reset clock"); clock.value = "00:00:0"; } flagstop = 0; stoptime = 0; splitdate = ''; laughter_resetclock(); window.clearTimeout(refresh); output.value = ''; } </script> <script type="text/javascript"> var laughter_flagclock = 0; var laughter_flagstop = 0; var laughter_stoptime = 0; var laughter_currenttime; var laughter_splitdate = ''; var laughter_output; var laughter_clock; var count = 0; function laughter_startstop() { var laughter_startdate = new Date(); var laughter_starttime = laughter_startdate.getTime(); if(laughter_flagclock==0) { laughter_flagclock = 1; laughter_counter(laughter_starttime); laughter_number_text = document.getElementById('laughter_number'); count++; laughter_number_text.value = count; } else { laughter_flagclock = 0; laughter_flagstop = 1; laughter_splitdate = ''; } } var running_total_laughter_time; function laughter_counter(laughter_starttime) { laughter_clock = document.getElementById('laughter_clock'); laughter_currenttime = new Date(); var laughter_timediff = laughter_currenttime.getTime() - laughter_starttime; if(laughter_flagstop == 1) { laughter_timediff = laughter_timediff + laughter_stoptime } if(laughter_flagclock == 1) { laughter_clock.value = laughter_formattime(laughter_timediff,''); running_total_laughter_time = laughter_timediff; //laughter_output.value += "-- laughter -- "+running_total_laughter_time; laughter_refresh = setTimeout('laughter_counter(' + laughter_starttime + ');',10); } else { window.clearTimeout(laughter_refresh); laughter_stoptime = laughter_timediff; } } function laughter_formattime(laughter_rawtime,laughter_roundtype) { if(laughter_roundtype == 'round') { var laughter_ds = Math.round(laughter_rawtime/100) + ''; } else { var laughter_ds = Math.floor(laughter_rawtime/100) + ''; } var laughter_sec = Math.floor(laughter_rawtime/1000); var laughter_min = Math.floor(laughter_rawtime/60000); laughter_ds = laughter_ds.charAt(laughter_ds.length - 1); if(laughter_min >= 60) { laughter_startstop(); } laughter_sec = laughter_sec - 60 * laughter_min + ''; if(laughter_sec.charAt(laughter_sec.length - 2) != '') { laughter_sec = laughter_sec.charAt(laughter_sec.length - 2) + laughter_sec.charAt(laughter_sec.length - 1); } else { laughter_sec = 0 + laughter_sec.charAt(laughter_sec.length - 1); } laughter_min = laughter_min + ''; if(laughter_min.charAt(laughter_min.length - 2) != '') { laughter_min = laughter_min.charAt(laughter_min.length - 2)+laughter_min.charAt(laughter_min.length - 1); } else { laughter_min = 0 + laughter_min.charAt(laughter_min.length - 1); } return laughter_min + ':' + laughter_sec + ':' + laughter_ds; } function laughter_resetclock() { //alert("laughter_resetclock called"); if(laughter_flagclock == 1) { var laughter_resetdate = new Date(); var laughter_resettime = laughter_resetdate.getTime(); laughter_counter(laughter_resettime); } else { laughter_clock.value = "00:00:0"; } laughter_flagstop = 0; laughter_stoptime = 0; laughter_splitdate = ''; count = 0; laughter_number_text.value = count; window.clearTimeout(refresh); laughter_output.value = ''; //window.clearTimeout(refresh); output.value = ''; } </script> <body> Running Time :: <input id="clock" type="text" value="00:00:0" style="text-align: center;" size="14"readonly><br /> Laughter Time :: <input id="laughter_clock" type="text" value="00:00:0" style="text-align: center;"size="14" readonly><br /> Laugh Count :: <input id="laughter_number" type="text" value="0" style="text-align: center;" size="4" readonly><br /> <div id="start_button"><a href="javascript:startstop();">Timing Start/Stop</a></div> <div id="laughter_start_button"><a href="javascript:laughter_startstop();">Laughter Start/Stop</a></div> <textarea id="laughter_output" style="height: 90%;" cols="40" rows="1"></textarea><br /> <a href="javascript:resetclock();">Full-Reset</a><br /><br /> </body> </html> I want to remove special characters in form fields. It should be automatic. I have a name filed where user entering text and i not want special characters, it should remove automatic. something like this i need, Code: onkeyup="javascript:this.value=this.value.replace(/[^0-9]/g, '');" here, all non-digits get removed automatic. Need help. |