Save style settings

Discussion in 'Javascript' started by seans, Aug 15, 2005.

  1. seans

    seans Guest

    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
    seans, Aug 15, 2005
    #1
    1. Advertising

  2. seans <> wrote in message news:...
    > 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.
    Stephen Chalmers, Aug 15, 2005
    #2
    1. Advertising

  3. seans

    seans Guest

    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
    seans, Aug 16, 2005
    #3
  4. seans <> wrote in message news:...
    > 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.
    Stephen Chalmers, Aug 16, 2005
    #4
  5. seans

    seans Guest

    Stephen Chalmers wrote:
    > seans <> wrote in message news:...
    > > 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
    seans, Aug 16, 2005
    #5
  6. seans <> wrote in message news:...
    >
    > 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.className = (i==idx)? 'redText' : 'normText';
    }

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

    --
    S.C.
    Stephen Chalmers, Aug 16, 2005
    #6
  7. seans

    seans Guest

    Hi Stephen cheers for that. I'll give it a go.

    thanks.

    sean
    seans, Aug 17, 2005
    #7
  8. seans

    seans Guest

    Hi Stephen cheers for that. I'll give it a go.

    thanks.

    sean
    seans, Aug 17, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jaco Bregman

    Save settings on exit

    Jaco Bregman, Nov 17, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,633
    Munsifali Rashid
    Nov 18, 2003
  2. Siegfried Heintze
    Replies:
    0
    Views:
    2,273
    Siegfried Heintze
    Oct 24, 2005
  3. leeanne
    Replies:
    0
    Views:
    1,867
    leeanne
    Sep 24, 2008
  4. donet programmer
    Replies:
    3
    Views:
    1,541
    Gregory A. Beamer
    Nov 20, 2009
  5. Ken Varn
    Replies:
    0
    Views:
    450
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page