Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-04-2008, 02:19 PM   PM User | #1
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
Inserting Hyperlink Inside A Javascript?

I have two part of this script head and body sections. I want to insert hyperlink on text "Prices correct as at:" section so when clicked I take user to another page. I searched thru the web and internal search of the forum but can't find the solution.


<head>
<script type="text/javascript">

function getLastMod() {
var myFrm = document.getElementById('myIframe');
var lm = new Date(myFrm.contentWindow.document.lastModified);
var dt = lm.getDate();
var mm = lm.getMonth() + 1;
var yy = lm.getFullYear();
var lmDate = mm + "-" + dt + "-" + yy;
document.getElementById('LastModified').innerHTML = "Prices correct as at: " + lmDate;
}

</script>
</head>



<body>
<span id="LastModified"></span>

<iframe id="myIframe" onload="getLastMod()" src="prices.txt" style="display:none;">
</iframe>

</body>
</html>
tunayx is offline   Reply With Quote
Old 09-04-2008, 02:48 PM   PM User | #2
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Code:
document.getElementById('LastModified').innerHTML = '<a href="destination.html">Prices correct as at: </a>' + lmDate;
Code:
document.getElementById('LastModified').innerHTML = '<a href="destination.html">Prices correct as at: ' + lmDate + '</a>';
Bill Posters is offline   Reply With Quote
Old 09-04-2008, 03:02 PM   PM User | #3
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
Both didn't worked..
tunayx is offline   Reply With Quote
Old 09-04-2008, 03:20 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Well, it works for me.

Make sure that the url is correctly specified as an absolute address:-

document.getElementById('LastModified').innerHTML = '<a href="http://www.yoursite.com/index.html">Prices correct as at:</a>' + " " + lmDate;


I have nothing but confidence in you. And very little of that.
Groucho Marx (1890 - 1977)

Last edited by Philip M; 09-04-2008 at 03:24 PM..
Philip M is offline   Reply With Quote
Old 09-04-2008, 03:44 PM   PM User | #5
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
I upload it to my site you can see it's not working.

"Prices correct as at:" text is at the bottom right corner of the moon

http://www.aymavisi.org
tunayx is offline   Reply With Quote
Old 09-04-2008, 03:51 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by tunayx View Post
I upload it to my site you can see it's not working.

"Prices correct as at:" text is at the bottom right corner of the moon

http://www.aymavisi.org
It works for me in IE6 (but for some reason it says "Prices correct at 3-9-2008 when today is the 4th).

When I click the link a new window opens with Destek Olun in a red box upper right.
Philip M is offline   Reply With Quote
Old 09-04-2008, 04:00 PM   PM User | #7
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
Hmm you're right about ie, I was using Opera and it does not show any link. Date is for last updated date of a different page it's correct. You clicked the word "Neden" you should have clicked on "Prices correct at"

But your code also does not work on ff 3.0 I need a solution for this.
tunayx is offline   Reply With Quote
Old 09-04-2008, 04:15 PM   PM User | #8
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Checking the DOM in FF3, the anchor is being inserted correctly, so the code should work.

When good code doesn't appear to work, it generally means there's an issue elsewhere in your code which is causing the problem.

Forgive me for saying, but the quality of the code on that site is particularly poor.

A good place to start would be fixing the invalidations in your markup (and probably your css).
http://validator.w3.org/check?verbos...org%2Fana.html


I recommend reading the article linked in my post signature below.
Bill Posters is offline   Reply With Quote
Old 09-04-2008, 04:43 PM   PM User | #9
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
In my site there's lots of codes and all worked fine except this code.

And other thing: I valitaded Google and that site has found 74 Errors, 12 warning(s) errors for Google. How can anybody explain it?

http://validator.w3.org/check?uri=ht...idator%2F1.591
tunayx is offline   Reply With Quote
Old 09-04-2008, 04:51 PM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by tunayx View Post
In my site there's lots of codes and all worked fine except this code.

And other thing: I valitaded Google and that site has found 74 Errors, 12 warning(s) errors for Google. How can anybody explain it?

http://validator.w3.org/check?uri=ht...idator%2F1.591
As Bill Posters has already remarked:-

"Forgive me for saying, but the quality of the code on that site is particularly poor."

But perhaps that is better than it used to be!

Last edited by Philip M; 09-04-2008 at 04:53 PM..
Philip M is offline   Reply With Quote
Old 09-04-2008, 05:16 PM   PM User | #11
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Quote:
Originally Posted by tunayx View Post
In my site there's lots of codes and all worked fine except this code.

And other thing: I valitaded Google and that site has found 74 Errors, 12 warning(s) errors for Google. How can anybody explain it?
…and the moment something didn't work in a popular browser, they'd quite willingly check and double-check their code, making their code valid if invalidity was found to be the cause of a problem.


Believe me when I say that you're not the first to hold up Google as some kind of evidence that valid code is a nonsense - and that, therefore, invalid code can't be the reason that their site is broken. (If I'm honest, it's a bit of a newbie remark.)
Sometimes, they're right, but very often they're wrong. When IE appears to get it right and stricter browsers don't, then that suggests even more strongly that code invalidity (or malformedness) may be the root of the problem.

One way to rule out invalidity and malformedness as the cause of the problem is to make your code well-formed and valid.

I'm loathe to even get further into this debate, but I'll simply urge you one again to read the article to which I link in my signature.
It may well save us both from wasting my time.

You may not appreciate it now, but this is helpful advice.


Fwiw, there are numerous other problems and potential problems with both the site design and the approach used regarding the coding.
However, in all frankness, until you appear more receptive to the advice that has already being given, there's little incentive to spend my time offering more.

Last edited by Bill Posters; 09-04-2008 at 05:25 PM..
Bill Posters is offline   Reply With Quote
Old 09-04-2008, 06:08 PM   PM User | #12
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
I think I identify the problem but I need help for fix it.
In ff when I look view source I see "<a" not closed with ">" but in IE it's okay how to correct this for ff.

document.getElementById('LastModified').innerHTML = '<a href="http://www.aymavisi.org/1yeniler.html"> Son Güncelleme: </a' + " " + lmDate;}


Another thing validator reccommended me to doc type I added it and google ads plus the "Prices correct as at:" text has gone?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

Last edited by tunayx; 09-04-2008 at 06:24 PM..
tunayx is offline   Reply With Quote
Old 09-04-2008, 06:27 PM   PM User | #13
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
There are so many mistakes in your code, any of which might be causing the problem. I'm not willing to debug your entire code.
(I take it that you're new to web development.)

If you aren't going to sort out the validation issues - or aren't even going to read the article which I suggested that you read - then frankly, I'm finished helping.

Hopefully someone else will be along soon to help you.

The js I posted is correct and should work. As said, if it isn't, then it's quite likely that it's being prevented from working by errors elsewhere in your code.


Good luck, sincerely.
Bill Posters is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:34 AM.


Advertisement
Log in to turn off these ads.