Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Easy Date   ClickBooth Network   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 01-02-2005, 07:01 AM   #1 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Simple JavaScript question

Hi there -

I have a piece of HTML code I want to insert into the main template of a site using Javascript, but I'm not quite sure what I need to do.

I figure I'll need to call up the script using something like:

Code:
<SCRIPT LANGUAGE="JavaScript1.4" SRC="/js/html.js" TYPE='text/javascript'></SCRIPT>
I tried putting the HTML code within:

Code:
document.write(' HTMLcode ');
and saving it as a .js document, but that didn't work.

As you can probably etll, I'm not at all used to JS, and am simply fumbling around here.

Any pointers on how to solve this little chestnut would be most appreciated.

My main requirement is to simply ensure that the JS file is called externally.
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 01-02-2005, 02:24 PM   #2 (permalink)
Inactive
 
dave conz's Avatar
 
Join Date: 10-13-03
Location: New Zealand
Posts: 534
iTrader: 0 / 0%
Latest Blog:
None

dave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the rough
It looks like it should work. What exactly is the problem, e.g. does the script load and cause an error, or does the script not load at all?
dave conz is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-02-2005, 02:31 PM   #3 (permalink)
Member
 
Join Date: 01-02-05
Posts: 45
iTrader: 0 / 0%
Latest Blog:
None

dejaone is liked by many
code looks ok. make sure SRC="/js/html.js" point to your javascript source code. for debug purpose, you can include your javascript into the html doc, instead of a source file.
__________________
Build one-way permanent links | Add to 100 SEO friendly Directories and get 50 one-way links in 2 hours.
dejaone is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-02-2005, 04:51 PM   #4 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Does it make a difference if I put the code between the body tags at all?? I'm simply getting no effect - the HTML is simply not appearing and there is no error message at all.
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-02-2005, 08:01 PM   #5 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
Quote:
SRC="/js/html.js"
the first slash here means start form the root folder (of your space), did u mean to do that or is js a subfolder of the page?
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-02-2005, 08:05 PM   #6 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
procedure for finding source of error, try html in the page (no JS) as suggested above, (if u can), assuming this works...
next try JS to insert a simple text like 'hello world' to check if you can do that, so the HTML u wanted to insert would be the problem.
if not try JS alert('ALERT!'); to see if the js is being run.

in the <body> yes! if you want to document.write() something in you page it wiouldn't be seen if outside of the body tag.
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt

Last edited by LazyJim : 01-02-2005 at 08:08 PM.
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-02-2005, 11:44 PM   #7 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,941
iTrader: 0 / 0%
imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
In the HTML file you want to use the code type the following (make sure you save the JS file in your JS folder):

<SCRIPT LANGUAGE="JavaScript1.4" SRC="/js/html.js" TYPE='text/javascript'></SCRIPT>

In the html.js file use ONLY (DO NOT use the SCRIPT tags in the JS file):

document.write('HTMLcode');

The other way to do it is to just add the javascript into your html file directly.

<SCRIPT LANGUAGE="JavaScript1.4" TYPE='text/javascript'>
document.write('HTMLcode');
</SCRIPT>


TIP: I would remove the 1.4 unless you are using ONLY 1.4 JavaScript code. Because older browsers will not work if they don't support JavaScript 1.4.

imaginemn
__________________
Imagine Creative Services
Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-03-2005, 04:06 AM   #8 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Thanks for the help, all - just adding text within the document.write commas works fine - which suggests it to be an issue with the HTML code itself. It simply does not want to call up a table with cells via the Javascript. Are there special rules for handling this??
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-03-2005, 07:25 AM   #9 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,941
iTrader: 0 / 0%
imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
Double check all your characters.

document.write('<table><TR><TD>How's my work?</TD></TR></TABLE>');

This will fail because of the extra ' character under "How's". If you need special characters (which is usually the problem) use a leading slash.

document.write('<table><TR><TD>How\'s my work?</TD></TR></TABLE>');

or

document.write('<table><TR width=\"600\"><TD>How\'s my work?</TD></TR></TABLE>');

You might want to post the code that is not working to see if there is something we can see to help you better.

imaginemn
__________________
Imagine Creative Services
Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-04-2005, 07:55 AM   #10 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
yup that means probably an escape problem.
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-04-2005, 07:58 AM   #11 (permalink)
Contributing Member
 
DragonEye's Avatar
 
Join Date: 10-13-03
Location: Belgium
Posts: 322
iTrader: 0 / 0%
Latest Blog:
None

DragonEye is liked by somebodyDragonEye is liked by somebodyDragonEye is liked by somebodyDragonEye is liked by somebodyDragonEye is liked by somebody
Send a message via MSN to DragonEye
Quote:
Originally Posted by imaginemn
Double check all your characters.

document.write('<table><TR><TD>How's my work?</TD></TR></TABLE>');

This will fail because of the extra ' character under "How's". If you need special characters (which is usually the problem) use a leading slash.

document.write('<table><TR><TD>How\'s my work?</TD></TR></TABLE>');

or

document.write('<table><TR width=\"600\"><TD>How\'s my work?</TD></TR></TABLE>');

You might want to post the code that is not working to see if there is something we can see to help you better.

imaginemn

You forget document.write("<TABLE><TR WIDTH=600><TD>How's my work?</TD></TR></TABLE>");
DragonEye is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-05-2005, 01:28 AM   #12 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
The HTML code I'm trying to Javascript is the DMOZ copyright code:

Code:
<TABLE BORDER="0" BGCOLOR="#666699" CELLPADDING="3" CELLSPACING="0"><TR><TD> <TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=0 BORDER=0><TR ALIGN=center> <TD><FONT COLOR="#FFFFFF">Help build the largest human-edited directory on the web.</FONT></TD> </TR><TR BGCOLOR="#DDDDDD" ALIGN=center> <TD>&nbsp; <A HREF="http://dmoz.org/cgi-bin/add.cgi?where=$path">Submit a Site</A> - <A HREF="http://dmoz.org/about.html"><B>Open Directory Project</B></A> - <A HREF="http://dmoz.org/cgi-bin/apply.cgi?where=$path">Become an Editor</A> &nbsp;</TD> </TR></TABLE> </TD></TR></TABLE>
I'm building a site that calls on DMOZ data, but I figure that Google and friends may use the DMOZ footprint as a way to devalue pages using DMOZ data - something I am keen to avoid. Using external Javascript is one way that may circumvent that issue - for the time being at least.

However, even with forward slashes, I simply cannot get the DMOZ code to work in a Javascript code.

Is there something radical I'm overlooking, or am I just being sloppy?
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-05-2005, 02:26 AM   #13 (permalink)
Contributing Member
 
DragonEye's Avatar
 
Join Date: 10-13-03
Location: Belgium
Posts: 322
iTrader: 0 / 0%
Latest Blog:
None

DragonEye is liked by somebodyDragonEye is liked by somebodyDragonEye is liked by somebodyDragonEye is liked by somebodyDragonEye is liked by somebody
Send a message via MSN to DragonEye
I don't understand why it doesn't work, but I tried it myself and with me it doesn't work either

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <SCRIPT LANGUAGE="javascript"> document.write("<TABLE BORDER=\"0\" BGCOLOR=\"#666699\" CELLPADDING=\"3\" CELLSPACING=\"0\"><TR><TD><TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=0 BORDER=0><TR ALIGN=center><TD><FONT COLOR=\"#FFFFFF\">Help build the largest human-edited directory on the web.</FONT></TD></TR><TR BGCOLOR=\"#DDDDDD\" ALIGN=center><TD><A HREF=\"http://dmoz.org/cgi-bin/add.cgi?where=$path\">Submit a Site</A> - <A HREF=\"http://dmoz.org/about.html\"><B>Open Directory Project</B></A> - <A HREF=\"http://dmoz.org/cgi-bin/apply.cgi?where=$path\">Become an Editor</A> &nbsp;</TD></TR></TABLE></TD></TR></TABLE></SCRIPT></body></html>"); </SCRIPT> </BODY> </HTML>
this just prints "); onto the page without any error warning

DragonEye
DragonEye is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-05-2005, 07:55 AM   #14 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,941
iTrader: 0 / 0%
imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
JavaScript does some funny things sometimes.

Try:

Code:
<SCRIPT LANGUAGE="javascript"> document.write('<TABLE BORDER="0" BGCOLOR="#666699" CELLPADDING="3" CELLSPACING="0"><TR><TD>'); document.write('<TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=0 BORDER=0><TR ALIGN=center>'); document.write('<TD><FONT COLOR="#FFFFFF">Help build the largest human-edited directory on the web.</FONT></TD>'); document.write('</TR><TR BGCOLOR="#DDDDDD" ALIGN=center>'); document.write('<TD>&nbsp; <A HREF="http://dmoz.org/cgi-bin/add.cgi?where=$path">Submit a Site</A> - <A HREF="http://dmoz.org/about.html"><B>Open Directory Project</B></A> - <A HREF="http://dmoz.org/cgi-bin/apply.cgi?where=$path">Become an Editor</A> &nbsp;</TD>'); document.write('</TR></TABLE>'); document.write('</TD></TR></TABLE>'); </SCRIPT>
OR

Code:
<SCRIPT LANGUAGE="javascript"> document.write('<TABLE BORDER="0" BGCOLOR="#666699" CELLPADDING="3" CELLSPACING="0"><TR><TD><TABLE WIDTH=100% CELLPADDING=2 CELLSPACING=0 BORDER=0><TR ALIGN=center><TD><FONT COLOR="#FFFFFF">Help build the largest human-edited directory on the web.</FONT></TD></TR><TR BGCOLOR="#DDDDDD" ALIGN=center><TD>&nbsp; <A HREF="http://dmoz.org/cgi-bin/add.cgi?where=$path">Submit a Site</A> - <A HREF="http://dmoz.org/about.html"><B>Open Directory Project</B></A> - <A HREF="http://dmoz.org/cgi-bin/apply.cgi?where=$path">Become an Editor</A> &nbsp;</TD></TR></TABLE></TD></TR></TABLE>'); </script>
imaginemn
__________________
Imagine Creative Services
Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-05-2005, 02:41 PM   #15 (permalink)
Inactive
 
dave conz's Avatar
 
Join Date: 10-13-03
Location: New Zealand
Posts: 534
iTrader: 0 / 0%
Latest Blog:
None

dave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the roughdave conz is a jewel in the rough
Quote:
Originally Posted by DragonEye
this just prints "); onto the page without any error warning
The code you posted has a rogue </script> tag which causes the script to abort prematurely. It also has questionable </body></html> tags.
dave conz is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-06-2005, 04:56 AM   #16 (permalink)
Inactive
 
I, Brian's Avatar
 
Join Date: 10-26-03
Posts: 2,466
iTrader: 0 / 0%
Latest Blog:
None

I, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebodyI, Brian is liked by somebody
Superb work again, imaginenm.
I, Brian is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-07-2005, 11:27 AM   #17 (permalink)
Contributing Member
 
FGTH's Avatar
 
Join Date: 03-06-04
Location: NY, CT, CA, AZ
Posts: 540
iTrader: 0 / 0%
Latest Blog:
None

FGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to all
I experimented and found that javascript works when I escape all reserved characters found in CGI/Perl.
__________________
"90% of the game is half mental."
--Yogi Berra
Elizabeth Arden
FGTH is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple javascript solution??? searchbliss Coding Forum 5 06-27-2007 03:52 PM
JS: Simple Javascript But please help Calisonder Coding Forum 1 04-17-2007 07:48 PM
A simple PHP Question Izzmo Coding Forum 4 10-02-2006 11:33 AM
Simple Question timmoyse Marketing Forum 11 09-16-2006 03:45 PM
Simple javascript popup window not working in FF spyderscripts Coding Forum 2 07-15-2006 07:02 PM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 04:39 AM.
© Copyright 2008 V7 Inc