Closed Thread Icon

Topic awaiting preservation: Change textcolor dynamicly - how to refresh string-variable? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8277" title="Pages that link to Topic awaiting preservation: Change textcolor dynamicly - how to refresh string-variable? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Change textcolor dynamicly - how to refresh string-variable? <span class="small">(Page 1 of 1)</span>\

 
eighdee
Nervous Wreck (II) Inmate

From: Pervijse
Insane since: Jul 2001

posted posted 08-23-2002 18:14

OK, First post in this area. Yesterday I decided to learn Javascript, so I'm a newbie in this field.

The problem is:
I want to change the color of a piece of text on my page. The color (in hex-value) is generated in a function when a user clicks a radio-button. It works to change the color of the background of my page to that color. I can also set the color of the string-variable (which holds the text that has to be in color) to that color (it works, I tested it). But the problem is that I have to refresh or reload the writing of the string. Can this be done (and how)? (If I refresh the whole page with 'document.reload();' the radio buttons are also reset, so that doesn't work)

These are the things I'm talking about (the important parts of the page):

code:
<html>
<head>
<script language="JavaScript">

tekstje = "Radio buttons:";//this holds the text that should get colored

function setFontKleur()
{
var kleur="#";
if(document.form_2.radio_red.checked){
kleur += "FF";
}else{
kleur += "00";
}
if(document.form_2.radio_green.checked){
kleur += "FF";
}else{
kleur += "00";
}
if(document.form_2.radio_blue.checked){
kleur += "FF";
}else{
kleur += "00";
}

//this works, if you write 'tekstje' now, it will be the right color (done that)
tekstje = tekstje.fontcolor(kleur);
//the next thing also works, as you can see in the link below (i hope)
document.bgColor=kleur;
}

</script>
</head>

<body bgcolor=#B6B6B6>
<form name="form_2">
<script language="JavaScript">
//THE NEXT THING SHOULD BE REFRESHED (tekstje) when a radio-button is clicked
document.write(tekstje);
</script>
<input type="radio" name="radio_red" onClick="redClicked();">Red
//function redClicked() then calls setFontKleur()
<input type="radio" name="radio_blue" onClick="blueClicked();">Blue
<input type="radio" name="radio_green" onClick="greenClicked();">Green
</form>
</body>
</html>



And this is the page.

PS: Sorry for the mixture of Dutch and bad English in my code.
PSII: Use the code of my link (right-click, view source), not the code that you see here. There are some functions missing.

Edit: damn UBB

[This message has been edited by eighdee (edited 08-23-2002).]

andy_j
Nervous Wreck (II) Inmate

From: uk
Insane since: Aug 2002

posted posted 08-23-2002 18:48

can you not just put your text inside a span or div tag and then change the color with part of your function eg


document.getElementById("text").style.color="#ff0000";

Example

Or have i totally misread the question.. (happens to me all the time)



[This message has been edited by andy_j (edited 08-23-2002).]

eighdee
Nervous Wreck (II) Inmate

From: Pervijse
Insane since: Jul 2001

posted posted 08-23-2002 19:39

Works like a charm. Thanks andy_j

« BackwardsOnwards »

Show Forum Drop Down Menu