Problem with JSP request
I have a simple temperature conversion program. When you click the buttons the answer flashes. Changing type="submit" to type="button" fixes that, but then the request doesn't work and the answer isn't right. What can I do here? Thanks in advance for any help.
<HTML>
<%!
public Double calc(int type, String x) {
double Tc,Tf;
if((type == 1) && (x != null) && (!x.equals("")))
{
Double C = Double.parseDouble(x);
Tf=(C)+32;
return Tf;
}
else if((type == 2) && (x != null) && (!x.equals("")))
{
Double F = Double.parseDouble(x);
Tc=(F-32);
return Tc;
}
else return 0.0;
}
%>
<BODY>
<FORM>
Celsius :
<INPUT TYPE="TEXT" NAME="Celsius" id="Celsius">
<INPUT TYPE="SUBMIT" NAME = "but_1" id="but_1" VALUE="Convert to Fahrenheit" onClick='document.getElementById("Fahrenheit").value = <%=calc(1, request.getParameter("Celsius"))%>' ></INPUT>
<br> Fahreinheit :
<INPUT TYPE="TEXT" NAME ="Fahrenheit" id="Fahrenheit" >
<INPUT TYPE="SuBMIT" NAME = "but_2" id="but_2" VALUE="Convert to Celsius" onClick='document.getElementById("Celsius").value = <%=calc(2, request.getParameter("Fahrenheit"))%>' ></INPUT>
</FORM>
</BODY>
</HTML>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks