Will Javascript variables stay if I reset the form they are set from before I use them?
function gResults () {
var TestVar = myform.inputbox.value;
var url = TestVar;
document.myform.reset();
开发者_运维技巧 window.location=TestVar;
}
Assume a text box with a url in it.
Will that function always grab the form's input? Are the function's list of things always done in order and saved in memory? Or will the window.location
always go to null?
Strings are pass by value. That script would correctly set window.location to equal myForm.inputbox.value from before it was reset.
url
will get the value of TestVar
at the time the line was executed, i.e. before the call to reset()
, see this example.
But why would you reset the form if you're redirecting the page anyway?
精彩评论