![]() |
Save style settings
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 |
Re: Save style settings
seans <seanss01@yahoo.com> wrote in message news:1124115720.879877.136480@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. |
Re: Save style settings
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 |
Re: Save style settings
seans <seanss01@yahoo.com> wrote in message news:1124180604.674690.327460@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. |
Re: Save style settings
Stephen Chalmers wrote:
> seans <seanss01@yahoo.com> wrote in message news:1124180604.674690.327460@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 |
Re: Save style settings
seans <seanss01@yahoo.com> wrote in message news:1124210814.856210.209530@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. |
Re: Save style settings
Hi Stephen cheers for that. I'll give it a go.
thanks. sean |
Re: Save style settings
Hi Stephen cheers for that. I'll give it a go.
thanks. sean |
| All times are GMT. The time now is 06:48 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.