Hello people. I have several quesitons, and I appreciate any help that I can get.
1. How do I display a variable in within <span></span>?
e.g. "var x = 10" in my Javascript gives me "10" on my HTML page.
I know document.GetElementById is useful but I don't know how to apply it.
2. How do I create a HTML preview using Javascript? I want to have a section where people can enter certain variables into text areas (say one for the hex colour code, one for URL, etc.) and all these information will be previewed in HTML.
e.g.:
[text area for "color" hex code] [text area for "href" URL] [text area for "title" caption]
Preview: text with the information entered above embedded as HTML.
Thank you so much for the help!
For (1)
<span id="myspan"></span>
<script language="Javascript">
var x = 10;
document.getElementById("myspan").innerHTML = "My x value is " + x;
</script>
Thanks, but it's still not working.
Just to clarify, I want to define a variable within the script itself, and then display it within a span.
Anyone else can help me?
Just to clarify on my second question.
I want to create a text preview.
Basically, I will have several text areas as below:
Enter text: [__________]
Hex color code: [__________]
URL: [__________]
Font size: [__________]
with a "preview" span below:
Preview: <entered text with entered variables>
Can anyone help me out?
Originally posted by RETARDED_MORON:Thanks, but it's still not working.
Just to clarify, I want to define a variable within the script itself, and then display it within a span.
Anyone else can help me?
My code defines a variable within the script itself and then displays it within a span. So why is yours not working? Maybe you want to post your code here.
Originally posted by LatecomerX:
Thank you so much!
One problem though, I have another field for link caption (using the <a title> tag) that does not seem to be working so well when I enter a caption with spaces (e.g. "A B C").
The resultant caption only displays the first word ("A").
Can you help me with this too?
You've been a great help.
Originally posted by RETARDED_MORON:
Thank you so much!One problem though, I have another field for link caption (using the <a title> tag) that does not seem to be working so well when I enter a caption with spaces (e.g. "A B C").
The resultant caption only displays the first word ("A").
Can you help me with this too?
You've been a great help.
Can you post the code somewhere and let me have a look at it?
<!-- function preview(){ var modCaption = document.getElementById("caption").value; var newWin = window.frames['frame']; newWin.document.write("<a href="+document.getElementById('url').value+" mce_href="/forums/2250/topics/+document.getElementById('url').value+" title="+modCaption+"><font color="+document.getElementById('color').value+">D-Generation-X!</font></a>"); newWin.document.close(); } // -->
<script>
function preview(){
var modCaption = document.getElementById("caption").value;
var newWin = window.frames['frame'];
newWin.document.write("<a href="+document.getElementById('url').value+" title="+modCaption+"><font color="+document.getElementById('color').value+">D-Generation-X!</font></a>");
newWin.document.close();
}
</script>
<input type="text" id="color" onkeyup="preview();" value="color">
<input type="text" id="url" onkeyup="preview();" value="url">
<input type="text" id="caption" onkeyup="preview();" value="caption">
<iframe name="frame" width="600" height="200"></iframe>
Originally posted by RETARDED_MORON:<script>
function preview(){
var modCaption = document.getElementById("caption").value;
var newWin = window.frames['frame'];
newWin.document.write("<a href="+document.getElementById('url').value+" title="+modCaption+"><font color="+document.getElementById('color').value+">D-Generation-X!</font></a>");
newWin.document.close();
}
</script>
<input type="text" id="color" onkeyup="preview();" value="color">
<input type="text" id="url" onkeyup="preview();" value="url">
<input type="text" id="caption" onkeyup="preview();" value="caption">
<iframe name="frame" width="600" height="200"></iframe>
Change this code segment:
title="+modCaption+">
to
title='"+modCaption+"'>
Thank you, it worked!
One more question, how do I run two functions simultaneously using the onKeyUp event?
I've tried onKeyUp="function1();function2();" but it doesn't work.