The code getting executed that is in the second form

Hi,

I have 2 forms in a jsp like below

<form ...>

onchange() submit the form

</form>

<form>

</form>

The problem here is ,when the form1 gets submitted,it is also

executing the code in the second form.How can I prevent

this.

Thanks

Chat

[333 byte] By [Chatfielda] at [2007-10-2 13:07:09]
# 1
What you posted doesn't give much information. Why don't you post the jsp. Enclose it in [code] and [/code] tags to make it more readable.
Gita_Weinera at 2007-7-13 10:32:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

Below is the code that is in action.How can I prevent the second

part form of being submitted when the first form is submitted.

Thanks

chat

..........................

................

<TR>

<TD width="35%" align="middle" valign="middle">

<jsp:useBean id="dbBean" scope="session" class="db.DbBean"/>

<form name="form1" action="/menu/food.jsp">

<select name="item_name" onchange="document.form1.submit()">

<option selected value="" >Choose Entry Item</option>

<%

dbBean.connect();

rs = dbBean.execSQL("select distinct item_name from item where combo_id is not null");

while(rs.next()){%>

<option value="<%= rs.getString("ITEM_NAME") %>"><%= rs.getString("ITEM_NAME") %></option>

<%

}

dbBean.close();

%>

</select>

</form>

</TD>

<form name="form4" action="/hotel/FoodMenu/order.jsp">

<%

try{

dbBean.connect();

if(session.isNew()){

rs=dbBean.execSQL("select trans_no.nextval from dual");

while(rs.next()){

transaction_no=rs.getInt(1);

session.putValue("transaction_no",transaction_no);

}

}

out.print(transaction_no);

int price_id=0;

int item_id=0;

for(int i=0;i<3;i++){

rs = dbBean.execSQL("select item.item_id,price.price_id from price,item where price.item_id=item.item_id and item.item_name='"+items[i]+"'");

while(rs.next()){

dbBean.execUpdate("insert into order_detail values(22222,1,"+item_id+","+price_id+",'nocomments')");

}

}

}catch(SQLException sqle){

out.print("\n second .."+sqle.toString());

}

dbBean.close();

%>

</form>

</BODY>

</HTML>

Chatfielda at 2007-7-13 10:32:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Are you saying that when you select an entry in form1 and that form submission is triggered (because of the selection), it is invoking food.jsp but it is also invoking order.jsp? That doesn't seem possible but form4 looks very suspicious to me. Form4 looks like it has no input fields at all and no submit button. It doesn't look like there would be any way for this form to be submitted. What is the purpose of form4?

Why don't you do the following. Bring up the page in a browser. Don't cause a form submission but select the browser "view source" option.It should show you the html source. Why don't you post the complete source.

Gita_Weinera at 2007-7-13 10:32:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...