Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Save style settings (http://www.velocityreviews.com/forums/t919714-save-style-settings.html)

seans 08-15-2005 02:22 PM

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


Stephen Chalmers 08-15-2005 09:26 PM

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.





seans 08-16-2005 08:23 AM

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


Stephen Chalmers 08-16-2005 12:15 PM

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.



seans 08-16-2005 04:46 PM

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


Stephen Chalmers 08-16-2005 06:28 PM

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.



seans 08-17-2005 09:10 AM

Re: Save style settings
 
Hi Stephen cheers for that. I'll give it a go.

thanks.

sean


seans 08-17-2005 09:11 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57