Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse href

Status
Not open for further replies.

rob51383

Programmer
Jun 23, 2004
134
US
Hello,

I am looping through every <td> of a named table and retrieving the first element of each <td> and do something if the first element in the <td> is <a>.

For every <a> element the HREF value will be something like:
<a href="
What I want to do with javascript is after detecting that the first element of the current <TD> is in fact an <a>, I want to get the value of "date" off the HREF string and comput the date range like so:

if date is between 1/2/2006 and 2/22/2006 {Do something}
elseif date is between 2/23/2006 and 6/21/2006 {Do Something}
else if date is between 6/21/2006 and 12/31/2006 {Do something}

Thanks for any help you can swing at me.
 
Like this.
[tt]
//suppose obj is the anchor identified
var s=obj.href;
var cm=(/&date=\W*(.*?)\W*&/i).exec(s);
if (Date.parse(RegExp.$1)==Date) {
var dt=new Date(Date.parse(RegExp.$1));
var dt1=new Date(Date.parse("1/2/2006"));
var dt2=new Date(Date.parse("2/22/2006"));
var dt3=new Date(Date.parse("6/21/2006"));
var dt4=new Date(Date.parse("12/31/2006"));
if (dt<dt1) {
//do something
} else if (dt>=dt1 && dt<=dt2) {
//do something
} else if (dt>dt2 && dt<=dt3) {
//do something
} else if (dt>dt3 && dt<=dt4) {
//do something
} else if (dt>dt4) {
//do something
}
} else {
alert("the data is not a date")
//do something with it
}
[/tt]
 
Amendment

I'd forgotten to key in the critical word. The corresponding line should be read like this.
[tt]
if (Date.parse(RegExp.$1)[blue]].constructor[/blue]==Date) {[/tt]

ps. Just for other reader's sake.
 
A re-take for typos.
[tt] if (Date.parse(RegExp.$1)[blue].constructor[/blue]==Date) {[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top