/    Sign up×
Community /Pin to ProfileBookmark

Global Vars seem to reset upon submit()

<%@ page import=”java.sql.*, oracle.jsp.dbutil.*, javax.servlet.http.HttpUtils” contentType=”text/html;charset=windows-1252″%>
<%@ taglib uri=”/WEB-INF/tlds/sqltaglib.tld” prefix=”sql” %>

<html>
<head>
<script language=”JavaScript”>
numm = 9;
function get_kit_brand() {
numm = document.TTT.batchBrand.selectedIndex;

var the_selected = document.TTT.batchBrand.options[numm].text;
document.TTT.test_hidden.value = the_selected;

document.TTT.submit();

alert(numm);

}
</script>

And then a bit of jsp code then:

<SCRIPT>alert(numm)</SCRIPT>

And it is back to the original value

Any clues?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@oleragDec 11.2003 — From what you have provided, "numm" will equal "9"

since "get_kit_brand()" doesn't appear to be called.

Also, when you mention that the value resets after a

"submit", do you mean that you are calling the same

page or another page???

Without your html (that your jsp is providing) it is difficult

to determine how you want your JS to behave.
Copy linkTweet thisAlerts:
@breamerauthorDec 11.2003 — TD align=left>Batch Brand: </TD>

<TD align=left> <SELECT name="batchBrand" size="1" maxlength="50" onChange="get_kit_brand()">

<sql:dbNextRow queryId="kit_brand_query">


<option>

<%= kit_brand_query.getString(1)

%>


</sql:dbNextRow>

</select>


</TD>

</TR>

it is called on a select(drop down) changing

And I am submitting back to the same form. I am trying to co-ordinate two drop down menus

Second one depends on what was selected on the first one
Copy linkTweet thisAlerts:
@oleragDec 11.2003 — OK - since your submitting to the same page, the original

assignment to the global will remain (as is apparently

happening).

To make the "next" page submission change to the value you

prefer, you could create a "hidden" object, set it via the

"kit_brand_query" function (when an item is selected from

the list), and, when the item is re-submitted, its value will

be passed and stored automatically in the "hidden" object.

Consequently, you won't need the global anymore since

the "hidden" object will now service this functionality. If the

"hidden" does not contain a value (as yet, such as the

first-time "call") its value.length() will return 0. Or, if you

prefer, you can set it to another value (such as 9).
Copy linkTweet thisAlerts:
@breamerauthorDec 11.2003 — But are hidden fields not reset upon submit as well?
Copy linkTweet thisAlerts:
@breamerauthorDec 11.2003 — I created the hidden fields and after the

submit I reset it via:

<input type="text" name="test_hidden" size=10 maxlength=30 value='<%=request.getParameter("test_hidden")%>'/>

So the submit, posts the data and then I get it again via getParameter

Thanks for the help

Man, this stuff is not client server , I'm getting old, I find this stuff kludgy

<sigh>
Copy linkTweet thisAlerts:
@oleragDec 12.2003 — Yep - sorry, forgot about telling you how to capture the

passed value. Note also that if you have multiple values

assigned to the same variable (such as multiple entries from

a selection list), you'll capture them in an array via the

"request.getParameterValues()" method.
×

Success!

Help @breamer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...