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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble using CSS inside JavaScript 1

Status
Not open for further replies.

Dragonfish

Programmer
Apr 25, 2001
62
UG
The following scenorio:
On this WebSite a button is pushed to call a JavaScript-function which writes a (style-sheet-formatted) text. This code is in the HTML document (note the rollover-function and the class="style_button_eins" which positions the button work - except with Netscape):

<!doctype html public &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>hauptfenster</title>
<link rel=stylesheet type=&quot;text/css&quot; href=&quot;textstyle.css&quot;>
<meta name=&quot;author&quot; content=&quot;gullever&quot;>
<meta name=&quot;generator&quot; content=&quot;Ulli Meybohms HTML EDITOR&quot;>
<script language=&quot;JavaScript&quot; src=&quot;steuern.js&quot; type=&quot;text/javascript&quot;></script>
</head>

<body text=&quot;#FF0000&quot; bgcolor=#C0C0C0 link=&quot;#FF0000&quot; alink=&quot;#FF0000&quot; vlink=&quot;#FF0000&quot;>
<FORM>
<input type=&quot;image&quot;
src=&quot;button1-1.gif&quot;
name=&quot;Image1&quot;
class=&quot;style_button_eins&quot;
onclick=&quot;button('Herren_eins')&quot;
onMouseOver=&quot;MM_swapImage('Image1','','button1-2.gif',1)&quot;
onMouseOut=&quot;MM_swapImgRestore()&quot;>

<input type=&quot;image&quot;
src=&quot;button1-1.gif&quot;
name=&quot;Image11&quot;
class=&quot;style_button_elf&quot;
onclick=&quot;button('Update')&quot;
onMouseOver=&quot;MM_swapImage('Image11','','button1-2.gif',1)&quot;
onMouseOut=&quot;MM_swapImgRestore()&quot;>
</FORM>
</body>
</html>

When the JavaScript-funtion calls an alert as in case &quot;Herren_eins&quot; it is sucessful. When the JavaScript-funtion calls &quot;Update&quot; then the text - This is a Test - is writen but not formatted with class='style_Mannschaften'.

*** External JavaScript ***
function button(buttonName)
{
switch (buttonName)
{
case &quot;Herren_eins&quot;: alert(buttonName);
Break;
case &quot;Update&quot;: Update();
Break;
default: alert(&quot;does´t work!&quot;);
}
}

function Update()
{
document.write(&quot;<p class='style_Mannschaften'>This is a Test</p>&quot;);
}

*** External CSS ***
The CSS line looks like this:
.style_Mannschaften { border: none; position: absolute; top: 100px; left: 570px; width: 250pt; }

If I simply write This is a Test in the HTML document using the style sheet then it works

So my problem is how to integrate CSS into Javascript. Other HTML tags - as we all Know - work in JavaScript. Later when this works I´d like to know how to integrate PHP-statements into JavaScript to access a MySQL Database but I have´nt found any interdeciplinary literature in WWW. Can anybody help.

Thanks - David in Germany
 
Are you using Netscape? or IE? Klae

You're only as good as your last answer!
 
I´m testing first with IE because NE never does want you want it to. When the whole thing works I´ll fine tune it for NE.

Thanks David
 
try inserting it into an element in the page (innerHTML) - instead of overwriting.Also, careful how deep in you get before trying to crossover to NS - this can caue huge headaches, I actually think developing for NS may be easier to do first, thn ad any extras for IE afterward, but that's just me ;-)
b2 - benbiddington@surf4nix.com
 
with IE you can use innerHTML method. so your p tag is hard coded and you write in it like this.

Code:
HARDCODED---
<P class=&quot;style_Mannschaften&quot; id=&quot;ptag&quot;></P>


Code:
DYNAMIC CODE---
window.ptag.innerHTML = &quot;This is a Test&quot;;

innerHTML is not available for NS. What I use is LAYERS or ILAYERS for the equivalent effect.

Code:
HARDCODED---
<LAYER id=&quot;layertag&quot;></LAYER>


Code:
DYNAMIC CODE---
document.layertag.document.open();
document.layertag.document.write(&quot;This is a test&quot;);
document.layertag.document.close();


Hope this helps. Klae

You're only as good as your last answer!
 
Thanks to allofya,

I´m busy ploughing thro´ Dan Steinmans WebSite (found the link here). Seems like there´s plenty of Info there

David in Germany
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top