more than one submit button to change differnently

[nobr]i have two buttons on one form, one needs to read save the changes and change page

the other needs to refresh the page and increment a varable

i looked at creating two forms, but the data required for the second button is within the scope of the first button, is there a way to assign the jstl varable to another form from within another?

the var i need to increment

<c:set var="rows" value="1" />

the two buttons

<INPUT TYPE=SUBMIT VALUE="+">

<br> </br>

<INPUT TYPE=SUBMIT VALUE="Save">

[/nobr]

[693 byte] By [h1400046a] at [2007-11-26 15:25:34]
# 1
Why not one form with two buttons that post to a servlet that then processes based on the button clicked.
tolmanka at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thanks... ok how do i go about creating a servlet?
h1400046a at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

try this example:

<%@ page contentType="text/html;charset=windows-1252"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>untitled</title>

<script language="javascript">

function submitForm(process){

if(process=="add"){

var val = document.myForm.hiddenField.value;

document.myForm.hiddenField.value = parseFloat(val)+1;

document.myForm.submit();

}else{

document.myForm.action="save.jsp";

document.myForm.submit();

}

}

function setHidden(){

document.myForm.hiddenField.value='<%=request.getParameter("hiddenField")!=null?request.getParameter("hiddenField"):"0"%>';

document.myForm.textField.value=document.myForm.hiddenField.value;

}

</script>

</head>

<body onload="setHidden()">

<form name="myForm">

<input type="text" name="textField"/>

<input type="hidden" name="hiddenField" value="0" />

<input type="button" value="+" onclick="submitForm('add')"/>

<input type="button" value="Save" onclick="submitForm('save')" />

</form>

</body>

</html>

jgalacambraa at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

that works but how do you place the value of the hidden field

<input type="text" name="hiddenField" value="0" />

into

<c:set var="rows" value=" " />

h1400046a at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
alternativly is it possible to set the jstl varable from the javascript code?im really stuck on this.. any help be great!
h1400046a at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

><input type="text" name="hiddenField" value="0" />

The value from this hidden field will be accessible via a request parameter:

In a servlet you can get it with request.getParameter("hiddenField")

with EL, ${param.hiddenField.

Your <c:set> tag then becomes:

<c:set var="rows" value="${param.hiddenField"/>

>alternativly is it possible to set the jstl varable from the javascript code?

No, you cannot affect JSP/JSTL from javascript code.

- JSP/Java runs on the server.

- It generates an HTML page that gets sent to the client.

- Java stops running

- javascript runs on the client (button click events etc)

The only way to run java again is to submit a request either by

- clicking a link

- submitting a form

- using AJAX

evnafetsa at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

thanks

but i have now realised i have a error on the page when it loads caused by the set hidden function

the error is

document.myForm.textField is null or not an object

? any ideas?

function setHidden(){

document.myForm.hiddenField.value='<%=request.getParameter("hiddenField")!=null?request.getParameter("hiddenField"):"0"%>';

document.myForm.textField.value=document.myForm.hiddenField.value;

}

</script>

<body onload="setHidden()">

<FORM name="myForm" METHOD=POST ACTION="workexp.jsp">

<input type="text" name="hiddenField" value="0" />

h1400046a at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
>document.myForm.textField is null or not an objectDo you have an input component on your form with the name "textField" ? I can see "hiddenField", but not "textField".<input type="text" name="textField" value="0" />
evnafetsa at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
good point in the javascript it should read hiddenFieldthanks alot for your help i have to working now :)
h1400046a at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
thnx to evnafets for the explanation..
jgalacambraa at 2007-7-8 21:41:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...