Text box value keeps resetting after submit

Discussion in 'Javascript' started by hai.mailbox@gmail.com, Jun 23, 2008.

  1. Guest

    Hello everyone,

    I have a small problem with javascript below:

    <p>Slider Test</p>
    <div class="slider" id="slider1" tabIndex="1">
    <input class="slider-input" id="slider1_input"/>
    </div>
    <form id="slider1_form" method="get" action="/protect/control.htm">
    Value:<input type="text" name="slider1_output" id="slider1_disp"
    value="5"/>
    </form>

    <script type="text/javascript">
    var sdr1 = new Slider(document.getElementById("slider1"),
    document.getElementById("slider1_input"));

    sdr1.onchange = function ()
    {
    document.getElementById("slider1_disp").value = sdr1.getValue();
    document.getElementById("slider1_form").submit();
    };
    </script>

    I got the slider's onchange function to trigger the form GET function,
    and the web server can get the slider value properly. However, after
    that, the value of the input text box (id="slider1_disp") returns to 5
    (or whatever default value I put at the input text box). How do I
    prevent the value of the input text box to return to the default value
    (i.e. I want to keep the last value that is submitted).

    Any suggestion is welcome. Thank you in advance!
    Regards,
    James
    , Jun 23, 2008
    #1
    1. Advertising

  2. SAM Guest

    a écrit :
    > Hello everyone,
    >
    > I have a small problem with javascript below:
    >
    > <p>Slider Test</p>
    > <div class="slider" id="slider1" tabIndex="1">
    > <input class="slider-input" id="slider1_input"/>
    > </div>
    > <form id="slider1_form" method="get" action="/protect/control.htm">
    > Value:<input type="text" name="slider1_output" id="slider1_disp"
    > value="5"/>
    > </form>
    >
    > <script type="text/javascript">
    > var sdr1 = new Slider(document.getElementById("slider1"),
    > document.getElementById("slider1_input"));


    what that is supposed/expected to do ?

    > sdr1.onchange = function ()
    > {
    > document.getElementById("slider1_disp").value = sdr1.getValue();
    > document.getElementById("slider1_form").submit();
    > };
    > </script>
    >
    > I got the slider's onchange function to trigger the form GET function,
    > and the web server can get the slider value properly. However, after
    > that, the value of the input text box (id="slider1_disp") returns to 5
    > (or whatever default value I put at the input text box). How do I
    > prevent the value of the input text box to return to the default value
    > (i.e. I want to keep the last value that is submitted).
    >
    > Any suggestion is welcome. Thank you in advance!


    I suppose 'control.htm' contents your form "slider1_form" ?
    I understand you can't do the job server side.

    JS in header :
    ==============

    var v = self.location.toString().split('?')[1];
    if(v.indexOf('&')>0) {
    v = v.split('&');
    for(var i=0, n = v.length; i<n; i++)
    if(v.indexOf('slider1_disp')>=0) {
    v = v.split('=')[1];
    break;
    }
    }
    else v = v.split('=')[1];

    // if there is no other window.onload :
    window.onload = function() {
    document.getElementById("slider1_disp").value = v;
    }


    or, just before </body>

    <script type="text/javascript">
    document.getElementById("slider1_disp").value = v;
    </script>

    --
    sm
    SAM, Jun 23, 2008
    #2
    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. =?Utf-8?B?UGlrb2xvIE1vbmRv?=

    model dialog box keeps refreshing its parent window.

    =?Utf-8?B?UGlrb2xvIE1vbmRv?=, Jun 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,962
    Trevor Benedict R
    Jun 9, 2004
  2. Gnarlodious
    Replies:
    4
    Views:
    17,535
    elizas
    May 5, 2010
  3. Benjamin Joldersma

    Visible property keeps resetting to False

    Benjamin Joldersma, Oct 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    130
    Jim Cheshire [MSFT]
    Oct 18, 2003
  4. Richard Haygreen

    resetting an HTML combo box

    Richard Haygreen, Oct 1, 2004, in forum: Javascript
    Replies:
    4
    Views:
    75
    Richard Haygreen
    Oct 1, 2004
  5. Joel
    Replies:
    3
    Views:
    198
    Randy Webb
    Nov 24, 2004
Loading...

Share This Page