HighDots Forums  

Text box value keeps resetting after submit

Javascript JavaScript language (comp.lang.javascript)


Discuss Text box value keeps resetting after submit in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hai.mailbox@gmail.com
 
Posts: n/a

Default Text box value keeps resetting after submit - 06-23-2008 , 10:32 AM






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

Reply With Quote
  #2  
Old   
SAM
 
Posts: n/a

Default Re: Text box value keeps resetting after submit - 06-23-2008 , 12:23 PM






hai.mailbox (AT) gmail (DOT) com a écrit :
Quote:
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 ?

Quote:
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[i].indexOf('slider1_disp')>=0) {
v = v[i].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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.