Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Adding HTML into Javascript
Old 05-23-2007, 02:18 AM Adding HTML into Javascript
8105's Avatar
Experienced Talker

Posts: 37
Location: UK
Trades: 0
Is it possible to add HTML into Javascript?

Like an includes file or something?

eg:

Text[8]=["sticky style","A HTML Form here"]

Thanks.
8105 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-23-2007, 02:42 AM Re: Adding HTML into Javascript
jito's Avatar
MY LIFE IS 'i' LIFE

Posts: 565
Name: surajit ray
Location: inside the heart of my friends
Trades: 0
you can create javascript form with DOM, try this tutorial:
http://developer.mozilla.org/en/docs..._DOM_Reference
__________________
I am not smart, that's why i don't act smart


Please login or register to view this content. Registration is FREE
jito is offline
Reply With Quote
View Public Profile
 
Old 05-23-2007, 07:04 AM Re: Adding HTML into Javascript
Angelosanto's Avatar
Webmaster Talker

Posts: 554
Name: Danny Angelosanto
Trades: 0
I think adding HTML to JavaScript is done using 'document.write'. For example:

document.write("<h1>A Header</h2>")

This is just simply formatting a header using HTML, but I'm sure you can add whatever you want really

Hope that helped
__________________
"Those who believe in telekinetics, raise my hand."
-Kurt Vonnegut
_____________________________________
Angelosanto is offline
Reply With Quote
View Public Profile Visit Angelosanto's homepage!
 
Old 05-23-2007, 08:35 AM Re: Adding HTML into Javascript
8105's Avatar
Experienced Talker

Posts: 37
Location: UK
Trades: 0
Thanks, i'll give it a go and let you know how it goes.
8105 is offline
Reply With Quote
View Public Profile
 
Old 05-23-2007, 08:55 AM Re: Adding HTML into Javascript
QiSoftware's Avatar
Skilled Talker

Posts: 74
Location: U.S.
Trades: 0
If you want to write an array variable-- set the variable text[8]="something here" + "something else"

and then use document.write(text[8])...

Q...
__________________


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by QiSoftware; 05-23-2007 at 08:58 AM..
QiSoftware is offline
Reply With Quote
View Public Profile Visit QiSoftware's homepage!
 
Old 05-23-2007, 10:26 AM Re: Adding HTML into Javascript
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
document.getElementById("someDiv").innerHTML = "<h1>This is a header</h1>";

That'll work too.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-23-2007, 12:52 PM Re: Adding HTML into Javascript
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
For most cases, I'd shun using document.write or innerHtml, unless you are targeting legacy browsers.

To keep yourself moving forward for compliance, I'd recommend using DOM.
document.write started with Netscape2 and IE3.
innerHTML support started with IE4 and Netscape6.
However, neither is part of a standard, like DOM.
I have a lot of respect for both Adam and Danny but, weren't you guys just complaining about IE's lack of standards support.

Go with Jito's advice. Its a little more work and has a higher learning curve but, you find less suffering down the road.
Basically, you will do
var myNewDiv = document.createElement("div");
// add some properties and/or children
node.appendChild(myNewDiv);
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 05-23-2007, 02:41 PM Re: Adding HTML into Javascript
8105's Avatar
Experienced Talker

Posts: 37
Location: UK
Trades: 0
What about adding javascript into php?

Could you just use an include() file for that?
8105 is offline
Reply With Quote
View Public Profile
 
Old 05-24-2007, 07:57 AM Re: Adding HTML into Javascript
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Quote:
Originally Posted by 8105 View Post
What about adding javascript into php?

Could you just use an include() file for that?
As far as PHP is concerned, there is no difference between javascript and html, its just template data
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 05-24-2007, 10:33 AM Re: Adding HTML into Javascript
8105's Avatar
Experienced Talker

Posts: 37
Location: UK
Trades: 0
I'm going a bit off topic now (I will post it in the PHP forum if asked to).

Lets say I have this javascript:

Code:
<a href="search.htm" onClick="return overlay(this, 'subcontent2', 'rightbottom')">login</a>
and I want to add it into this PHP:

PHP Code:
<?php
// Are they a guest?
if ($context['user']['is_guest'])
{
 
// Show a login box...
 // Uncomment below to show login box
 // ssi_login();
 // ... and a little notice about registering
 
echo '
 Welcome, <b>Guest</b>, Please **THE JAVASCRIPT HERE** or'
;
 echo 
'
 <a href="'
$scripturl'?action=register">register</a>';
}
// Otherwise, a user here :)
else
{
 
// Show them a nice welcome notice
 
ssi_welcome();
 echo 
' ';
 
// And a logout link
 
ssi_logout("#");
}
?>

Last edited by 8105; 05-24-2007 at 10:47 AM..
8105 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Adding HTML into Javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31124 seconds with 12 queries