SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I want to do is have a script read a cookie, and depending on the value either making a form input/button hidden or visible.


    IS THIS POSSIBLE? what other things can I do with forms like that other than filling, clearing things.


    - sam

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sam,

    Generally speaking: Yes, it's possible. I have a script at my site (Hiding Selects in a Form) that displays a selection list dependent upon the value of a radio button. The things to remember are:
    1) the layers must be <div>s for it to be crossBrowser
    2) netscape wants a form for each layer. So, you will need to have the submission button form accept hidden values from the other layers.

    Vinny


    ------------------
    my site:GrassBlade: cut&paste javascript
    moderator at:The JavaScript Place Forums
    Javascript City

  3. #3
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ew...layers.

    i found a solution using ie4+, but my company still uses n4.5...


    maybe i'll go ahead and use your solution...what's the url?


    - sam

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi sam,

    As Robert DiNero said in "Taxi": "You talkin to me? Nobody else around. You talkin to me?"

    The url is in the sig below my name

    Vinny

    ------------------
    my site:GrassBlade: cut&paste javascript
    moderator at:The JavaScript Place Forums
    Javascript City

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Since you can check the cookie as the page is loading, there's no need for layers or any other DHTML mumbo-jumbo.

    Just check the cookie, and if it's got the right value, write out the code for the form element.

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>&lt;SCRIPT LANGUAGE="JavaScript"&gt;
    &lt;!--

    function readCookie(cookieName) {

    // Get all available cookies
    var docCookies = document.cookie;

    // Look for our cookie's name
    var startIndex = docCookies.indexOf(cookieName);

    // If we can't find it, give up
    if (startIndex == -1) return false;

    // Go to where the cookie's value starts
    startIndex += cookieName.length + 1;

    // Figure out where our cookie's value ends
    // by looking for the start of the next one
    var endIndex = docCookies.indexOf(";",startIndex);
    // Or if there is no next one...
    if (endIndex == -1) endIndex = docCookies.length;

    // Get the value
    var cookieValue = docCookies.substring(startIndex, endIndex);
    // Unescape (decode) it, and return it
    return unescape(cookieValue);

    }

    if (readCookie("myCookie") == "myValue") {
    document.write("&lt;INPUT TYPE=TEXT ...&gt;");
    } else {
    document.write("&lt;INPUT TYPE=HIDDEN ...&gt;");
    }

    //--&gt;
    &lt;/SCRIPT&gt;[/code]

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!


    [This message has been edited by kyank (edited July 12, 2000).]

  6. #6
    ********* Addict DLG_1's Avatar
    Join Date
    Jun 2000
    Location
    Texas, USA
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that is definitely a very good solution that is independant of platforms.

    THANKS!


    - Sam


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •