JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 6th, 2004, 06:44 AM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question HI plz help

Hi guys....im new with html and javascript...i have little idea how to do this:

I have a table coded in html but I only want it to be put on the document on a if condition....but I dont know how to add chunk of html code in javascipt...its a big block of html...thanks in advance

Reply With Quote
  #2  
Old February 6th, 2004, 06:48 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Check into the document.write() function. I recommend devguru.com as a reference.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old February 6th, 2004, 06:52 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Hi ocean - welcome.

Inserting HTML into an HTML document via Javascript isn't really a recommended method. For example - you user may have Javascript turned off. To pragmatically control data in your page, you are much better off using a server-side language such as ASP, PHP, ASP.NET.... there's a few of 'em round these days.

Failing that, if you REALLY want to mess with your HTML doc via JS, check out the "innerhtml" method, along with document.write. There is some great JS documentation here - http://devedge.netscape.com/central/javascript/
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #4  
Old February 6th, 2004, 06:56 AM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by dhouston
Check into the document.write() function. I recommend devguru.com as a reference.


I tried document.write() like this :

Code:
<script>
document.write("<table width = 400 align ="center"><tr><td>hello</td></tr></table>")
</script>


what am i doing wrong there? plz help

Reply With Quote
  #5  
Old February 6th, 2004, 07:37 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Since you need to begin and end the string parameter in the document.write method, you can't use it within the string, like you have with your align="center".. instead, use single quote (').

You should probably read a few tutorials/documents on Javascript & HTML just to get some knowledge of how functions, etc work.

Reply With Quote
  #6  
Old February 6th, 2004, 09:27 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Or use single quotes as your outside quotes and standard doubles inside. Or escape nested quotes by using the backslash character. Stumpy's right, of course, that you should strive not to have your content display dependent upon js. At the very least, you might look into using server side includes, if you don't have access to bona fide programming functionality. Most hosts nowadays offer PHP, though, so I'd be surprised if you couldn't do a quick PHP if statement with different includes.

Reply With Quote
  #7  
Old February 6th, 2004, 10:34 AM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I really think that I need to learn php too....can you tell me what I need to get started...do I need any sort of compilers...and plz tell me what free webhosts allow php..and what is a php parser...

Reply With Quote
  #8  
Old February 6th, 2004, 11:07 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Oh, I don't know about free Web hosts allowing PHP. That's not necessarily the case. There are a million PHP tutorials and books out there. Take your pick. No compilers are necessary; a host just has to allow PHP pages and you're good to go.

Reply With Quote
  #9  
Old February 6th, 2004, 06:26 PM
almcnicoll's Avatar
almcnicoll almcnicoll is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Montargis, France
Posts: 6 almcnicoll User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to almcnicoll
Lightbulb ... or a different method ...

If the whole document.write() thing seems clumsy to you (and no, I doubt you'll find PHP on a free-hosting site) then there's another way of doing all this.

Either with CSS or inline tags (I'll explain both as you're new to HTML/JS) you can tell the table not to be displayed by default. Then you let your JavaScript display it on the IF condition (or if you're worried about non-JS browsers, have it shown and hide it with the JS if script condition not met, which is a better compromise but uglier)

how you do this is:
CSS:
in the <head></head> of your document, put the following:

<style>
.myTable {
display: none;
}
</style>

then you write your table code as follows:

<table id='conditionaltable' class="myTable" ... >
<tr><td>
whatever
</td><td>
whatever
</td></tr>
</table>

If you don't like taking the <style> tags by the horns as yet, you can also use:

<table id='conditionaltable' style="display: none;" .... >
etc.
</table>

Then in your JavaScript (making sure that the table has been drawn by the time the script is called - ie in <body onload="">) you put a function that locates the table and sets that "display:none" attribute to "display:block". This can be done two ways - one is more reliable but requires you to have script for telling which browser the end-user has (there's plenty available - search google for "javascript browser sniffer") - that solution is:

if Internet Explorer:
document.all['conditionaltable'].style.display = "block"; (if that fails, try document.all.conditionaltable.style = "block"; - I could be wrong)
if Netscape / similar:
var myObj = document.getElementByID("conditionaltable");
myObj.style.display = "block";

the other solution depends on you knowing how many tables are in your document. If it's the only one, then all well and good. In any case, assuming it's the only (or else the first to be rendered), use:

document.tables[0].style.display = "block";

Lastly, if you want to do the thing I suggested earlier of having it displayed unless not needed, just swap all references to "none" with the references to "block"

Think that's it - any problems do PM or email me

Al

Last edited by almcnicoll : February 6th, 2004 at 06:39 PM. Reason: inaccuracies and spelling!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > HI plz help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway