input in a text box still appear after page refresh for IE but notFF, Chrome, Opera

Discussion in 'Javascript' started by albert kao, Apr 7, 2010.

  1. albert kao

    albert kao Guest

    I want to keep the value of the user input (e.g. text box value)
    displayed after page refresh by a javascript.
    The following test web page is used.
    The alerts appear before and after the page refresh as expected on all
    browsers (FF, Chrome, Opera & IE).
    The input value in a text box still appear after page refresh for IE
    but not FF, Chrome, Opera.
    Please help to make it work for FF, Chrome, Opera.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <link rel="stylesheet" type="text/css" media="all" href="css/
    style.css" />
    <meta http-equiv="Content-Type" content="text/html;
    charset=UTF-8" />
    <title>Cookie</title>
    </head>

    <body>
    <div>
    <br>
    Rows Per Page
    <input type="text" name="rowsPerPage" id="rowsPerPage" />
    <input type="submit" value="savevalue" onClick="savevalue()">
    </div>
    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript" src="js/Cookie.js"></script>
    <script type="text/javascript">
    Cookie.init({name: 'mydata'});

    function savevalue() {
    var rowsPerPageElem =
    document.getElementById("rowsPerPage");
    alert('rowsPerPageElem.value ' + rowsPerPageElem.value);
    Cookie.setData('rowsPerPage', rowsPerPageElem.value);

    window.location.reload(true);
    var rowsPerPage = Cookie.getData('rowsPerPage');

    alert(' rowsPerPage ' + rowsPerPage);

    var rowsPerPageElem =
    document.getElementById("rowsPerPage");
    rowsPerPageElem.value = rowsPerPage;
    }
    </script>
    </body>
    </html>
    albert kao, Apr 7, 2010
    #1
    1. Advertising

  2. albert kao

    Thomas Allen Guest

    Re: input in a text box still appear after page refresh for IE butnot FF, Chrome, Opera

    On Apr 7, 1:28 pm, albert kao <> wrote:
    >             window.location.reload(true);


    The field value will persist if you do not pass true to reload call.
    Also, you probably want the savevalue function to return false so that
    the form is not actually submitted.

    Thomas
    Thomas Allen, Apr 7, 2010
    #2
    1. Advertising

  3. Re: input in a text box still appear after page refresh for IE but not FF, Chrome, Opera

    Thomas Allen wrote:

    > On Apr 7, 1:28 pm, albert kao <> wrote:
    >> window.location.reload(true);

    >
    > The field value will persist if you do not pass true to reload call.


    Not guaranteed.

    > Also, you probably want the savevalue function to return false so that
    > the form is not actually submitted.


    That would be the case if the return value of savevalue() would be returned
    to an `onsubmit' handler of a form, but there is none here which is the
    problem.


    PointedEars
    --
    Danny Goodman's books are out of date and teach practices that are
    positively harmful for cross-browser scripting.
    -- Richard Cornford, cljs, <cife6q$253$1$> (2004)
    Thomas 'PointedEars' Lahn, Apr 7, 2010
    #3
  4. Re: input in a text box still appear after page refresh for IE but not FF, Chrome, Opera

    albert kao wrote:

    > I want to keep the value of the user input (e.g. text box value)
    > displayed after page refresh by a javascript.
    > The following test web page is used.
    > The alerts appear before and after the page refresh as expected on all
    > browsers (FF, Chrome, Opera & IE).
    > The input value in a text box still appear after page refresh for IE
    > but not FF, Chrome, Opera.
    > Please help to make it work for FF, Chrome, Opera.


    0. RTFM, STFW, RTFFAQ: <http://jibbering.com/faq/#posting> pp.
    1. Make it Valid HTML: <http://validator.w3.org/>
    2. Lose Prototype.js and probably Cookie.js, too.
    3. Use the `onload' attribute of the `body' element to fill the controls
    with the cookie data.
    4. Add a server-side fallback.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Apr 7, 2010
    #4
  5. albert kao

    JR Guest

    Re: input in a text box still appear after page refresh for IE butnot FF, Chrome, Opera

    On Apr 7, 2:28 pm, albert kao <> wrote:
    > I want to keep the value of the user input (e.g. text box value)
    > displayed after page refresh by a javascript.
    > The following test web page is used.
    > The alerts appear before and after the page refresh as expected on all
    > browsers (FF, Chrome, Opera & IE).
    > The input value in a text box still appear after page refresh for IE
    > but not FF, Chrome, Opera.
    > Please help to make it work for FF, Chrome, Opera.
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html>
    >    <head>
    >       <link rel="stylesheet" type="text/css" media="all" href="css/
    > style.css" />
    >       <meta http-equiv="Content-Type" content="text/html;
    > charset=UTF-8" />
    >       <title>Cookie</title>
    >    </head>
    >
    >    <body>
    >       <div>
    >          <br>
    >          Rows Per Page
    >          <input type="text" name="rowsPerPage" id="rowsPerPage" />
    >          <input type="submit" value="savevalue" onClick="savevalue()">
    >       </div>
    >       <script type="text/javascript" src="js/prototype.js"></script>
    >       <script type="text/javascript" src="js/Cookie.js"></script>
    >       <script type="text/javascript">
    >          Cookie.init({name: 'mydata'});
    >
    >          function savevalue() {
    >             var rowsPerPageElem =
    > document.getElementById("rowsPerPage");
    >             alert('rowsPerPageElem.value ' + rowsPerPageElem.value);
    >             Cookie.setData('rowsPerPage', rowsPerPageElem.value);
    >
    >             window.location.reload(true);
    >             var rowsPerPage = Cookie.getData('rowsPerPage');
    >
    >             alert(' rowsPerPage ' + rowsPerPage);
    >
    >             var rowsPerPageElem =
    > document.getElementById("rowsPerPage");
    >             rowsPerPageElem.value = rowsPerPage;
    >          }
    >       </script>
    >    </body>
    > </html>


    Use the IE's 'autocomplete' attribute, e.g.

    <input autocomplete="off" ...>

    --
    JR
    JR, Apr 8, 2010
    #5
    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. cjl
    Replies:
    1
    Views:
    10,495
    Michael Winter
    Oct 31, 2005
  2. Prakhar
    Replies:
    3
    Views:
    305
    Default User
    Jul 19, 2007
  3. Øyvind Granberg

    iframe in ie & ff & Chrome & Opera

    Øyvind Granberg, Dec 5, 2008, in forum: HTML
    Replies:
    5
    Views:
    11,843
    Øyvind Granberg
    Dec 6, 2008
  4. cjl
    Replies:
    7
    Views:
    178
    Thomas 'PointedEars' Lahn
    Oct 30, 2005
  5. 123Jim
    Replies:
    6
    Views:
    182
    123Jim
    May 8, 2011
Loading...

Share This Page