|
Hi,
How can I replace html for a JavaScript variable?
In VBScript, I would just do something like the following:
<font name="something" size="<%=myVar%>">Text</Font>
I know I can use getElementById, but thats not quit getting me where I need to go since blocks of text would be all over and would have to have different ID`s - hence I dont want to look for 200 id`s.
Anyway if i can figure out how to output the variable that would be great.
Thanks a lot.
|
|
|
If you are are talking about modifying the page using client-side javascript, then DHTML methods are your only hope. You could put the entire page in one single <DIV> with an id. Then create your own special tag system. Using javascript, you could read the <DIV> contents into a variable, p-a-r-s-e the contents, replace your variable placeholders with the values, and rewrite the entire <DIV> contents.
document.getElementById("mainDIV").innerHTML = newHTML;
If you are talking server-side, just use VBScript as you already know how to do.
|
|
|
|
|
WOW! Thats a whole lotta page parsin.
I want to change a size value of fonts -- but I cannot use the same id for each, so how can I do something like this?
function changeSize(){
document.getElementById(`wooboo`).size ++;
}
<font id="wooboo" size="2">Text 1</font>
<font id="wooboo" size="2">Text 2</font>
If I call the function above, it only changes the font size for Text 1
Any idea how I can change it for multiple id`s? Its impossible for me to put all the text I want changed under one ID.
Thanks very much for your help.
|
|
|
You will want to learn about Cascading Style Sheets (CSS). CSS will revolutionize the way you format your HTML documents. CSS allows you to format the page in ways you can`t do with <FONT> tags, etc. Also, CSS will allow you to dynamically change the format -- which is exactly what you want to do.
Here is some code to demonstrate one way to dynamically change all the font sizes of a page. Just copy and paste this as a new HTML document the check it out:
---------------------------
<html>
<head>
<style>
.style1 {
font-face:Verdana;
font-size:8pt;
color:#663333;
}
</style>
<script language=javascript>
function TextSizer() {
textSize = document.forms[0].textSize.value + "pt";
document.styleSheets[0].rules[0].style.fontSize = textSize;
}
</script>
</head>
<body>
<span class=style1>The style of this text will change.</span>
<form>
<input type=textbox name=textSize size=2>
<input type=button value="Set Text Size" onclick="TextSizer()">
</form>
</body>
</html>
---------------------------
For more advanced training about Dynamic style sheets, check out: http://developer.apple.com/internet/javascript/styles.html http://www.wdvl.com/Authoring/DHTML/Intro/changing_rules.html
But first, you should go through a CSS tutorial -- then worry about scripting against the style sheet. http://www.w3schools.com/css/default.asp
Excellent CSS reference http://www.devguru.com/Technologies/css/quickref/css_index.html
I also use devguru for VBScript and JavaScript references.
|
|
|
|
|
Thank you very much. Thats exactly what I wanted to do.
|
|
|
|
|
Any idea on Netscape 7.1 and other browsers (tried: k-meleon, Netscape, Opera (Opera gives no error or anything)?
The error was: document.styleSheets[0].rules has no properties
But (of course), it works just fine in IE only.
Thanks!!!
|
|
|
One of two links I provided in a previous reply shows some cross-browser methods. One of those links actually has a complete javascript library for dynamic styles with detailed explanations. It`s tedious to go through, but if you want to do cross-browser, dynamic styles, read up! Enjoy!
You know what is funny to me? Most of what I do on the Internet is figure out how to do things on the Internet. Seems like a means with no end. What`s the goal?! I swear this Internet thing is just a fad. I`m opening a mobile taco stand. The taco industry seems pretty solid.
|
|
|
|
|
I know what you mean. It seems like I finally figured out everything there is about classic ASP, so then I learn .NET from the ground up and change my entire way of thinking. Once I learn the .NET platform 100% I will probably switch to .NET2 which will probably be 100% Java (LOL)
Just beware that the taco industry may become volatile if we stop mexicans from crossing the border.
Thanks again for all of your help.
|
|
|
Man, that`s where I`m at. I got into "classic" ASP/VBScript 3 years ago. Now I`m really good at it, and consider myself a SQL Server and JavaScript guru as well -- a good combination for a web developer guy! Now .NET makes my entire methodology "classic" and "obsolete". I like .NET -- nothing against it, and I look forward to mastering C# (I`ve chosen C# over VB.NET. If I was previously a VB guy, things would be different.) So far I haven`t had the luxury of a "learning" project so as of now, I`m not a .NET programmer. But now I`m falling behind! I`m seeing the job postings looking for .NET people. Recruiter called me last night--employer wants .NET experience. May consider me anyway...but ouch. If you are in the Kansas City area, and know ASP.NET style programming, contact me.
|
|
|
|
|
Troy,
I am in Ohio, but:
I started .NET with VB.NET and have developed over 10 multi-tiered asp.net apps utilizing either: SQL/Oracle/Access.
I have recently switched to C# and I love it even more. I have created a few components, sites and apps using C#. All of my developement is now C#.
I am able to use VS.NET or Dreamweaver and create components from scratch.
So at any rate, if you decide to stick with it, feel free to ask me anything you want. I will help you out as much as I can. Just plan on losing some hair, major time and your sanity -- cause its a 180 from Classic (but WELL worth it).
E-mail me at sendittokeith@yahoo.com if you want to chat further.
Thanks again for YOUR help!!!
|
|
|