By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

Save style settings

P: n/a
Hi,

I need to change the font, font size, and color of a button on a form.
I need to save the current style settings and restore them later. Is
there an easy way of doing that?

Sorry if there is a simple solution to this; I am still learning
Javascript.

Thanks again.

sean

Aug 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
seans <se******@yahoo.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I need to change the font, font size, and color of a button on a form.
I need to save the current style settings and restore them later. --


What do you mean by 'later' ?

a) Later during the same document load.
b) After a reload during the same browser session.
c) On a subsequent browser session.
d) Other

How are you changing the style values?

a) By swapping to another predefined class.
b) By addressing individual properties.
c) Other

--
S.C.


Aug 15 '05 #2

P: n/a
Hi Stephen thanks for your reply. Sorry about the ambiguity. I am doing
a search for strings in the document. When somebody selects a string
from a drop-down list the string is highligted on the page by changing
the style settings. The font is changed and the color changed to red.
When somebody searches for a different string I want the previously
selected string to revert back to it's original style settings. I am
changing the style by addressing the individual style properties.

thanks again.

sean

Aug 16 '05 #3

P: n/a


seans <se******@yahoo.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
Hi Stephen thanks for your reply. Sorry about the ambiguity. I am doing
a search for strings in the document. When somebody selects a string
from a drop-down list the string is highligted on the page by changing
the style settings. The font is changed and the color changed to red.
When somebody searches for a different string I want the previously
selected string to revert back to it's original style settings. I am
changing the style by addressing the individual style properties.

thanks again.

sean

This is guesswork of course, but presumably the strings to be highlighted are enclosed within <span> or <div> tags,
which initially are styled the same as the surrrounding text.
If this is the case, all that's required is to have two pre-defined style classes and to toggle the className property
of the relevant element.

--
S.C.
Aug 16 '05 #4

P: n/a
Stephen Chalmers wrote:
seans <se******@yahoo.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
Hi Stephen thanks for your reply. Sorry about the ambiguity. I am doing
a search for strings in the document. When somebody selects a string
from a drop-down list the string is highligted on the page by changing
the style settings. The font is changed and the color changed to red.
When somebody searches for a different string I want the previously
selected string to revert back to it's original style settings. I am
changing the style by addressing the individual style properties.

thanks again.

sean

This is guesswork of course, but presumably the strings to be highlighted are enclosed within <span> or <div> tags,
which initially are styled the same as the surrrounding text.
If this is the case, all that's required is to have two pre-defined style classes and to toggle the className property
of the relevant element.

--
S.C.


Hi Stephen thanks for your reply. Yes that is what I am trying to do.
The strings are encloses in span tags.

Is this the way to create styles programmatically in JavaScript? I
tried doing the following but it produced an error saying that there
were an invalid number of arguments.

document.createStyleSheet();
with (document.styleSheets(document.styleSheets.length-1)) {
addRule(".highlight","color:red;font-Size: 16pt;font-family:arial");

}

thanks.

sean

Aug 16 '05 #5

P: n/a
seans <se******@yahoo.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com...

Hi Stephen thanks for your reply. Yes that is what I am trying to do.
The strings are encloses in span tags.

Is this the way to create styles programmatically in JavaScript? I
tried doing the following but it produced an error saying that there
were an invalid number of arguments.

document.createStyleSheet();
with (document.styleSheets(document.styleSheets.length-1)) {
addRule(".highlight","color:red;font-Size: 16pt;font-family:arial");

}


document.styleSheets isn't supported by Opera and is unnecessary.
I advised toggling the element's className.

Try this fragile example:

<HTML>
<HEAD>
<style>
..normText{color:black; font-weight:normal}
..redText{color:red; font-weight:bold}
</style>
</HEAD>
<BODY>
<FORM>

<SELECT name='s1' onchange='hiLite( "theText", this.selectedIndex-1 )'>
<option>Please select a word...
<option>Truth
<option>Indefinite
<option>Doubt
</SELECT>

</FORM>

<DIV id='theText' class='normText'>Any <span>truth</span> is better than <span>indefinite</span>
<span>doubt</span>.</DIV>

<SCRIPT type='text/javascript'>

function hiLite(elem, idx)
{
var spans=document.getElementById( elem ).getElementsByTagName('span');

for(var i=0,len=spans.length; i<len; i++)
spans[i].className = (i==idx)? 'redText' : 'normText';
}

</SCRIPT>
</BODY>
</HTML>

--
S.C.
Aug 16 '05 #6

P: n/a
Hi Stephen cheers for that. I'll give it a go.

thanks.

sean

Aug 17 '05 #7

P: n/a
Hi Stephen cheers for that. I'll give it a go.

thanks.

sean

Aug 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.