|
Do you really need a regular expression for this? I mean, it's a simple string search replace so using a regex will be a bit of an overkill.
What language are you using?
~javier lozano
(blog || email)
|
|
|
|
|
I just discovered that <HTML> tag will be automatically removed from text entered in a <textarea> when <textarea> loses, then regain input focus. How can I get around it?
Example: Entering this into <textarea>...
<HTML><BODY>login<INPUT name=login><BR>password <INPUT name=login></BODY></HTML>
will get trimmed down to:
login<INPUT name=login> <BR>password <INPUT name=login>
Thanks!
Norman Fung
|
|
|
|
|
A textarea won't AFAIK remove anything....
However htmlarea which replaces an textarea does remove html and body tags. See htmlarea (here on CP) for possible solutions.
How do I print my voice mail?
|
|
|
|
|
Hi,
I'm developing an application that takes credit cards. I do not want to go back to the server when the client swipes the card to break the mag-stripe data apart, so I would like to do this client side using JavaScript.
I can write the JavaScript code, I just don't know how to code the input statement in HTML to call my script on a text change of a textbox.
Thanks,
Glenn
|
|
|
|
|
Check your form elements inside onsubmit
How do I print my voice mail?
|
|
|
|
|
Try this code. This will put a text box on the browser and when you change the text and step back on to browser, will call teh function 'yourfunction()'
------------
document.write("")
------------------------
|
|
|
|
|
This is my code for calculating Variance between two dates
function presentDate(startDate, endDate) {<br />
var ierr = 1 ;<br />
<br />
var roundDays = 1 ;<br />
<br />
if(startDate != '') {<br />
if(!isNaN(Date.parse( startDate ))) {<br />
var s = new Date(Date.parse(startDate)) ;<br />
ierr = 0 ;<br />
}<br />
}<br />
<br />
if(endDate != '' && ierr != 1) {<br />
if(!isNaN(Date.parse( endDate ))) {<br />
var e = new Date(Date.parse(endDate)) ;<br />
<br />
var temp = suycDateDiff( s, e, 'd', roundDays ) ;<br />
}else{<br />
ierr = 1;<br />
}<br />
}else{<br />
ierr = 1;<br />
}<br />
<br />
if ( temp != null && ierr != 1 ) <br />
<br />
return temp.toString() ;<br />
}<br />
<br />
function suycDateDiff( start, end, interval, rounding ) {<br />
<br />
var iOut = 0;<br />
<br />
var startMsg = "Check the Start Date and End Date\n"<br />
startMsg += "must be a valid date format.\n\n"<br />
startMsg += "Please try again." ;<br />
<br />
var intervalMsg = "Sorry the dateAdd function only accepts\n"<br />
intervalMsg += "d, h, m OR s intervals.\n\n"<br />
intervalMsg += "Please try again." ;<br />
<br />
var bufferA = Date.parse( start ) ;<br />
var bufferB = Date.parse( end ) ;<br />
<br />
if ( isNaN (bufferA) || isNaN (bufferB) ) {<br />
alert( startMsg ) ;<br />
return null ;<br />
}<br />
<br />
if ( interval.charAt == 'undefined' ) {<br />
alert( intervalMsg ) ;<br />
return null ;<br />
}<br />
<br />
var number = bufferB-bufferA ;<br />
<br />
switch (interval.charAt(0))<br />
{<br />
case 'd': case 'D': <br />
iOut = parseInt(number / 86400000) ;<br />
if(rounding) iOut += parseInt((number % 86400000)/43200001) ;<br />
break ;<br />
case 'h': case 'H':<br />
iOut = parseInt(number / 3600000 ) ;<br />
if(rounding) iOut += parseInt((number % 3600000)/1800001) ;<br />
break ;<br />
case 'm': case 'M':<br />
iOut = parseInt(number / 60000 ) ;<br />
if(rounding) iOut += parseInt((number % 60000)/30001) ;<br />
break ;<br />
case 's': case 'S':<br />
iOut = parseInt(number / 1000 ) ;<br />
if(rounding) iOut += parseInt((number % 1000)/501) ;<br />
break ;<br />
default:<br />
alert(intervalMsg) ;<br />
return null ;<br />
}<br />
<br />
return iOut ;<br />
}
Now again, I need to find the variance between these two dates excluding the non-working days i.e Thirsday and Friday.
Help kindly appreciated.
Regards,
The Phantom.
|
|
|
|
|
Hey,
I've worked out the DateVariance function. The function below returns the number of non-working days (non-Thursdays/Fridays) between the two given dates (startDate and endDate ).
Here is the function:
function DateVariance(startDate, endDate)
{
var diffMS = (endDate.getTime() - startDate.getTime());
var days = Math.floor(diffMS / (1000 * 3600 * 24));
if(days == 0)
return days;
var nonworkdays = 0;
var weeks = Math.floor(days / 7);
if(weeks > 0)
{
days -= weeks;
nonworkdays += (weeks * 2);
}
if(days > 0)
{
var dayofweek = startDate.getDay();
if(dayofweek < 5)
{
if(dayofweek == 4)
nonworkdays++;
else
{
if(days > (4 - dayofweek))
nonworkdays += 2;
}
}
else
{
if(dayofweek == 5 && days == 6)
nonworkdays++;
else if(dayofweek == 6 && days >= 5)
nonworkdays += (days == 5 ? 1:2);
}
}
return (days-nonworkdays);
}
Basically what this does is as follows:
1) Get difference (in milliseconds) between the two different dates
2) Convert those milliseconds into number of whole days between the two dates
3) Convert that number of days into number of whole weeks between the two dates
4) For every week between the two dates, add 2 to a variable called nonworkdays -- this var will keep track of the non-work days between the two dates
5) Now, subtract out (7 * weeks) from days so we're left with a number for days that is less than 7.
6) With that number of days (if it is greater than 0) perform the following to add more work days:
6a) If the day of the week is Thursday, add 1 more work day to the total non-work days
6b) If the day of the week is less than Thursday (i.e. Sunday-Wednesday) add 2 work days if, by adding the remaining number of days to the current day of the week, we pass wednesday (in which case we're passing Thursday and Friday, so we have to add 2 to nonworkdays ), otherwise, don't add anything to nonworkdays (because we don't pass Thursday and Friday).
6c) If the day of the week is Friday AND days is 6, then we need to add 1 to nonworkdays (because otherwise we'll land on a Thursday).
6d) If the day of the week is Saturday, add 2 non work days if days==6 (because otherwise we will land on Friday) or 1 non work day if days==5 (because otherwise we will lang on Thursday).
7) Finally, return days - nonworkdays which will be the total non-work days between the two given dates.
[EDIT] I removed the document.write line from the function. Obviously, that was there for testing purposes only! [/EDIT]
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|
|
I make a web page which contain two frames. The upper frame is to play some MPEG-2 video in sequence and the lower frame is an sliding text (simialr to HTML marquee effect) written in java applet. I use IE6.0 browser and window XP. However, I encounter some problems:
First, I write HTML using the <object> tag to play the video and use javascript to control playing the next video when one is finished. Everything is fine except that when the first video is finished and loading the next video to play, the sliding text which is written in java applet will stop for a while. (I test under local LAN and the stop times is about 1-2 seconds) I want to ask why this problem happen and can this problem be avoided? If yes, how to avoid this?
Second, I try doing the same things as the first question. However, in this time, I use HTML+TIME instead of pure HTML + javascript. The problem is very strange this time. The sliding text no longer stopped when finish playing one video and everything is all right. But after 2-3 hours, the IE6.0 is no responding and everything is stopped (the videos and the sliding text). During these 2-3 hours period, I haven't touch the computer and I do not have any screen saver opening. I just let the browser to continuous to play the videos sequentially. So I want to ask why the browser will have no responding in this case and how to solve this problem.
Thank You.
|
|
|
|
|
Hi Friends,
I am using JMF to run video files in JSP. Should i install JMF in all client PC?. If not, u tell me the solution to overcome.
by,
senthil
senthil
|
|
|
|
|
Hi all,
Please anyone knows how to add day to a Date excluding weekends, preferrable language is Javascript.
function DateAdd(startDate, numDays, numMonths, numYears)<br />
{<br />
var returnDate = new Date(startDate.getTime()) ;<br />
var yearsToAdd = numYears ; <br />
var month = returnDate.getMonth() + numMonths + 1 ;<br />
<br />
if ( month > 11 )<br />
{<br />
yearsToAdd = Math.floor((month+1)/12) ;<br />
<br />
month -= 12*yearsToAdd ;<br />
<br />
yearsToAdd += numYears ;<br />
}<br />
<br />
returnDate.setMonth(month) ;<br />
<br />
returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd) ;<br />
<br />
returnDate.setTime(returnDate.getTime()+60000*60*24*numDays) ;<br />
<br />
return returnDate ;<br />
}
Now I need to exclude non-working days, i.e Thursday and Friday.
Help kindly appreciated.
Thanks
The Phantom.
|
|
|
|
|
Hi,
I think this algorithm should work for what you are trying to do (it assumes that Thursday and Friday are the "non-work days":
<br />
function DateAdd(startDate, numDays, numMonths, numYears)<br />
{<br />
var returnDate = new Date(startDate.getTime()) ;<br />
var yearsToAdd = numYears ; <br />
var month = returnDate.getMonth() + numMonths + 1 ;<br />
<br />
if ( month > 11 )<br />
{<br />
yearsToAdd = Math.floor((month+1)/12) ;<br />
month -= 12*yearsToAdd ;<br />
yearsToAdd += numYears ;<br />
}<br />
<br />
returnDate.setMonth(month) ;<br />
returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd) ;<br />
<br />
var finalDays = 0;<br />
if(numDays >= 5)<br />
{<br />
var weeks = (numDays / 5);<br />
finalDays = (weeks * 7);<br />
numDays -= (weeks * 5);<br />
}<br />
<br />
if(numDays > 0)<br />
{<br />
var dayOfWeek = returnDate.getDay();<br />
<br />
if(dayOfWeek < 4 && (dayOfWeek + numDays) >= 4)<br />
{<br />
finalDays += (numDays + 2);
}<br />
else<br />
{<br />
if(dayOfWeek == 4 || dayOfWeek == 5)<br />
{<br />
finalDays += (numDays + (5-dayOfWeek));<br />
}<br />
else<br />
finalDays += numDays;<br />
}<br />
}<br />
<br />
returnDate.setTime(returnDate.getTime()+60000*60*24*finalDays);<br />
<br />
return returnDate;<br />
}<br />
I didn't test the code, but I think it should work. Let me know if it doesn't, or if you have more questions.
[EDIT]
Sorry, slight mistake in the function if dayOfWeek = 6. Now it is fixed
[/EDIT]
Sincerely,
Alexander Wiseman
Est melior esse quam videri
It is better to be than to seem
|
|
|
|
|
Alexander Wiseman,
Your forumula worked.
Five points for you.
Cheers ,
Regards,
The Phantom.
|
|
|
|
|
Alexander,
Buddy, sometimes it doesnot work.
What this logic is simply doing is after taking 7 seven days into consideration it simply deducts 2 days, and after doing this, it sometimes skips the working days as well.
Please help me out.
Best Regards,
The Phantom.
|
|
|
|
|
Hey,
I tested the function today and realized I made a mistake in the calculate of weeks.
My line read var weeks = (numDays / 5); . When I wrote this I was thinking in C++ mode, thinking that the division operator would only return a whole number. In Javascript it returns the exact quotient, so we simply need to add the Math.floor function so it looks like this: var weeks = Math.floor(numDays / 5) .
Give that a try and see if it works for you. Also, I ran across another problem in your section of the function. You have this line: var month = returnDate.getMonth() + numMonths + 1; . I think that the + 1 is unnecessary and returns the wrong date.
Make those two changes and it should be working for you! I didn't do extensive testing, so if you find any other strange scenarios which don't work, please tell me and I would be happy to correct the code.
Sincerely,
Alexander Wiseman
Est melior esse quam videri
It is better to be than to seem
|
|
|
|
|
Alex,
I've done those two changes accordingly, still some places it includes Thursday's and Friday's.
Please have a look.
Regards,
The Phantom.
|
|
|
|
|
Okay, I figured it out and this time I've tested it. The remaining problem was caused under these conditions:
1) The startDate is a Thursday or a Friday
2) The number of days being added is a multiple of 5
In this case, the algorithm would always return a Thursday or Friday because it would simple add 7*(number of times 5 goes into numDays). To fix this, all I added was another "else" clause which checked this case and fixed it. Below is the final function:
function DateAdd(startDate, numDays, numMonths, numYears)
{
var returnDate = new Date(startDate.getTime()) ;
var yearsToAdd = numYears ;
var month = returnDate.getMonth() + numMonths;
if ( month > 11 )
{
yearsToAdd = Math.floor((month+1)/12) ;
month -= 12*yearsToAdd ;
yearsToAdd += numYears ;
}
returnDate.setMonth(month) ;
returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd) ;
var finalDays = 0;
if(numDays >= 5)
{
var weeks = Math.floor((numDays / 5));
finalDays = (weeks * 7);
numDays -= (weeks * 5);
}
var dayOfWeek = returnDate.getDay();
if(numDays > 0)
{
if(dayOfWeek < 4 && (dayOfWeek + numDays) >= 4)
{
finalDays += (numDays + 2);
}
else
{
if(dayOfWeek == 4 || dayOfWeek == 5)
{
finalDays += (numDays + (5-dayOfWeek));
}
else
finalDays += numDays;
}
}
else
{
if(dayOfWeek == 4 || dayOfWeek == 5)
{
finalDays -= (dayOfWeek - 3);
}
}
returnDate.setTime(returnDate.getTime()+60000*60*24*finalDays);
return returnDate;
}
Hope that works for you. I apologize for the mistakes.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Alex,
The way you help for writing this snippet is more than the success factor for the snippet.
I really appreciate for your help and you don't need to make the apologize.
I was trying for the whole day on the logic I was thinking on, I made it work but the logic was not efficient enough and it was slowing down the system and eating the memory resources. But I thought you will come up the solution.
Alright, I've tried the code and this time it works but it doesn't work where I need to get the back days, I mean instead of addition I tried to do subtraction of days, it never works for the condition but when I try to change the code:
if(numDays > 0) to if(numDays > 0 || numDay < 0) to make subtraction work it again took Thursday and Friday.
In the mean time, if you've some time then there is a reverse situaion where I need to calculate the difference between two dates excluding the same non-working days, I already submitted a Thread with the reference:
Calculating Variance excluding non-working days busisoft 23:03 20 Jul '04
Thanks again for your kind help.
Regards,
The Phantom.
|
|
|
|
|
Alex,
Please first check this out.
As you said i made the changes, but it only works when I remove the 1 from calculating the month, remember I was adding 1 in calculating month. Now when I remove the 1 it works but what will happen it goes back to the month , for example if the selected date was 26/07/2004 and if we add 1 then it shows 27/06/2004.
Please check it out what's happening.
Thanks.
Regards,
The Phantom.
|
|
|
|
|
Hi,
I pasted the function source from my post above into a webpage and tested the scenario you mentioned, but, oddly enough, I didn't have the same problem. Maybe check to see if your function is identical to the one I posted above and then, if that doesn't work, give me the exact code where you invoke the function.
I will look at DateVariance when I have a chance.
Sincerely,
Alexander Wiseman
|
|
|
|
|
First I found that javascript function getMonth() always starts from zero
I copied it as it is from the above reply!
This is the place where I am calling it
FormatDate(AddDayToDate(FormatDate(document.frmEngine.PLREMDATE.value,"yyyy/mm/dd"), 0), "dd/mm/yyyy") ;
function AddDayToDate(plandate, days)<br />
{<br />
var gCurrentDate = new Date(plandate)<br />
<br />
var newDate = DateAdd(gCurrentDate, parseInt(days,10), <br />
parseInt(0,10), <br />
parseInt(0,10)); <br />
<br />
var year = newDate.getFullYear() ; <br />
var month = newDate.getMonth() ;<br />
var date = newDate.getDate() ;<br />
return date + "/" + month + "/" + year ;<br />
}
function FormatDate(DateToFormat,FormatAs)<br />
{<br />
if(DateToFormat=="")<br />
{<br />
return"";<br />
}<br />
<br />
if(!FormatAs){FormatAs="dd/mm/yyyy";}<br />
<br />
var strReturnDate;<br />
<br />
FormatAs = FormatAs.toLowerCase();<br />
<br />
DateToFormat = DateToFormat.toLowerCase();<br />
<br />
var arrDate<br />
<br />
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");<br />
<br />
var strMONTH;<br />
<br />
var Separator;<br />
<br />
while(DateToFormat.indexOf("st")>-1)<br />
{ <br />
DateToFormat = DateToFormat.replace("st","");<br />
}<br />
<br />
while(DateToFormat.indexOf("nd")>-1)<br />
{<br />
DateToFormat = DateToFormat.replace("nd","");<br />
}<br />
<br />
while(DateToFormat.indexOf("rd")>-1)<br />
{<br />
DateToFormat = DateToFormat.replace("rd","");<br />
}<br />
<br />
while(DateToFormat.indexOf("th")>-1)<br />
{<br />
DateToFormat = DateToFormat.replace("th","");<br />
}<br />
<br />
if(DateToFormat.indexOf(".")>-1)<br />
{<br />
Separator = ".";<br />
}<br />
<br />
if(DateToFormat.indexOf("-")>-1)<br />
{<br />
Separator = "-";<br />
}<br />
<br />
<br />
if(DateToFormat.indexOf("/")>-1)<br />
{<br />
Separator = "/";<br />
}<br />
<br />
if(DateToFormat.indexOf(" ")>-1)<br />
{<br />
Separator = " ";<br />
}<br />
<br />
arrDate = DateToFormat.split(Separator);<br />
DateToFormat = "";<br />
<br />
for(var iSD = 0;iSD < arrDate.length;iSD++)<br />
{<br />
if(arrDate[iSD]!="")<br />
{<br />
DateToFormat += arrDate[iSD] + Separator;<br />
}<br />
}<br />
<br />
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);<br />
arrDate = DateToFormat.split(Separator);<br />
<br />
if(arrDate.length < 3)<br />
{<br />
return "";<br />
}<br />
<br />
var DAY = arrDate[0];<br />
var MONTH = arrDate[1];<br />
var YEAR = arrDate[2];<br />
<br />
if(parseFloat(arrDate[1]) > 12)<br />
{<br />
DAY = arrDate[1];<br />
MONTH = arrDate[0];<br />
}<br />
<br />
if(parseFloat(DAY) && DAY.toString().length==4)<br />
{<br />
YEAR = arrDate[0];<br />
DAY = arrDate[2];<br />
MONTH = arrDate[1];<br />
}<br />
<br />
<br />
for(var iSD = 0;iSD < arrMonths.length;iSD++)<br />
{<br />
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();<br />
var MonthPosition = DateToFormat.indexOf(ShortMonth);<br />
if(MonthPosition > -1)<br />
{<br />
MONTH = iSD + 1;<br />
if(MonthPosition == 0)<br />
{<br />
DAY = arrDate[1];<br />
YEAR = arrDate[2];<br />
}<br />
break;<br />
}<br />
}<br />
<br />
var strTemp = YEAR.toString();<br />
<br />
if(strTemp.length==2)<br />
{<br />
if(parseFloat(YEAR)>40)<br />
{<br />
YEAR = "19" + YEAR;<br />
}<br />
else<br />
{<br />
YEAR = "20" + YEAR;<br />
}<br />
}<br />
<br />
<br />
if(parseInt(MONTH)< 10 && MONTH.toString().length < 2)<br />
{<br />
MONTH = "0" + MONTH;<br />
}<br />
<br />
if(parseInt(DAY)< 10 && DAY.toString().length < 2)<br />
{<br />
DAY = "0" + DAY;<br />
}<br />
<br />
switch (FormatAs)<br />
{<br />
case "dd/mm/yyyy":<br />
return DAY + "/" + MONTH + "/" + YEAR;<br />
case "mm/dd/yyyy":<br />
return MONTH + "/" + DAY + "/" + YEAR;<br />
case "dd/mmm/yyyy":<br />
return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;<br />
case "mmm/dd/yyyy":<br />
return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;<br />
case "dd/mmmm/yyyy":<br />
return DAY + " " + arrMonths[MONTH -1] + " " + YEAR; <br />
case "mmmm/dd/yyyy":<br />
return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;<br />
case "yyyy/mm/dd":<br />
return YEAR + " " + arrMonths[MONTH -1] + " " + DAY ;<br />
}<br />
<br />
return DAY + "/" + strMONTH + "/" + YEAR;;<br />
<br />
}
Regards,
The Phantom.
|
|
|
|
|
Hey,
I have looked through your code and discovered why the month is being decreased by 1. You were exactly right when you said that the getMonth() function returns the zero-based index of the month. Your formatting functions assume a one-based index of the month, which means that the when you call FormatDate after the call to AddDayToDate , the month gets set back by 1 (July becomes June, in your test scenario).
Fortunately, there is an easy way to fix this and I have tested it to make sure it works. You need to modify the AddDayToDate function to add one to the month returned by getMonth . Below you will find the modified version of AddDayToDate . Copy it into your code and it should work fine.
function AddDayToDate(plandate, days)
{
var gCurrentDate = new Date(plandate);
var newDate = DateAdd(gCurrentDate, parseInt(days,10),
parseInt(0,10),
parseInt(0,10));
var year = newDate.getFullYear() ;
var month = newDate.getMonth() + 1 ;
var date = newDate.getDate() ;
return date + "/" + month + "/" + year ;
}
Hope that helps! Let me know if it still doesn't work. Also, I haven't had a chance, but I plan to work on the DateVariance function. I already know how to go about it, so it will just be a matter of sitting down and writing the code when I have a free moment.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Alex,
It worked.
5 stars for you
Please, look for the day variance as I am loosing my patience
Thanks.
Regards,
The Phantom.
|
|
|
|
|
|
Dear people,
I have been searching for the correct code to call upon a webservice directly from an aspx page.
Can anyone tell me how to do it?
|
|
|
|
|