Text box value keeps resetting after submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hai.mailbox@gmail.com

    Text box value keeps resetting after submit

    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_inp ut"/>
    </div>
    <form id="slider1_for m" method="get" action="/protect/control.htm">
    Value:<input type="text" name="slider1_o utput" id="slider1_dis p"
    value="5"/>
    </form>

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

    sdr1.onchange = function ()
    {
    document.getEle mentById("slide r1_disp").value = sdr1.getValue() ;
    document.getEle mentById("slide r1_form").submi t();
    };
    </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_di sp") 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
  • SAM

    #2
    Re: Text box value keeps resetting after submit

    hai.mailbox@gma il.com 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_inp ut"/>
    </div>
    <form id="slider1_for m" method="get" action="/protect/control.htm">
    Value:<input type="text" name="slider1_o utput" id="slider1_dis p"
    value="5"/>
    </form>
    >
    <script type="text/javascript">
    var sdr1 = new Slider(document .getElementById ("slider1"),
    document.getEle mentById("slide r1_input"));
    what that is supposed/expected to do ?
    sdr1.onchange = function ()
    {
    document.getEle mentById("slide r1_disp").value = sdr1.getValue() ;
    document.getEle mentById("slide r1_form").submi t();
    };
    </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_di sp") 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_fo rm" ?
    I understand you can't do the job server side.

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

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

    // if there is no other window.onload :
    window.onload = function() {
    document.getEle mentById("slide r1_disp").value = v;
    }


    or, just before </body>

    <script type="text/javascript">
    document.getEle mentById("slide r1_disp").value = v;
    </script>

    --
    sm

    Comment

    Working...