Message Boards Message Boards

webMathematica: Avoid reset the input in a menu with different options?

In the below jsp file the user chooses between 3 options: A, B, C. When the menu is evaluated the output is fine, but the menu reset to the initial state. For instance: If I choose B, and evaluate the ouput is B (it is OK), but the input menu resest to A, how could I get that it stays in my last election (B)?

<%@ page language="java"  %>
<%@ taglib uri="/webMathematica-taglib" prefix="msp" %>

<html>

<form name="fest" action="test.jsp" method="post">
<body>
Select a option:  

<SELECT NAME="element" SIZE="1">
<OPTION VALUE="OptionA">A
<OPTION VALUE="OptionB">B
<OPTION VALUE="OptionC">C
</SELECT>
<br>
<br>
<msp:evaluate>
MSPBlock[$$element,$$element ]
</msp:evaluate>
<input type="submit" name="btnSubmit" value="Evaluate" > 

</body>
</html>
2 Replies

So a slightly reorganized version of your code with some less loose interpretations of valid HTML(https://www.w3schools.com/js/js_reserved.asp). So a jsp page called "Test2.jsp"

<%@ page language="java"  %>
<%@ taglib uri="/webMathematica-taglib" prefix="msp" %>
<html>
<body>
<form name="drps" action="Test2.jsp" method="post">
Select a option:  
<select name="drops" size="1">
    <option value="OptionA">A</option>
    <option value="OptionB">B</option>
    <option value="OptionC">C</option>
</select>
<br /><br />
<input type="submit" name="btnSubmit" value="Evaluate" /> 
</form>
<msp:evaluate>
MSPBlock[$$drops, $$drops]
</msp:evaluate>
</body>
</html>

The "Test2.jsp" page rendered by Tomcat/webMathematica. enter image description here

webMathematica provides internal built function HTMLSelect which may help you. So a jsp page called "Test3.jsp"

<%@ page language="java"  %>
<%@ taglib uri="/webMathematica-taglib" prefix="msp" %>
<html>
<body>
<form name="drps" action="Test3.jsp" method="post">
Select a option:
<msp:evaluate>
HTMLSelect[{"A","B","C"},{"OptionA","OptionB","OptionC"}, "drops", SelectedValues -> {$$drops}]
</msp:evaluate>
<br /><br />
<input type="submit" name="btnSubmit" value="Evaluate" /> 
</form>
<msp:evaluate>
MSPBlock[$$drops, $$drops]
</msp:evaluate>
</body>
</html>

The "Test3.jsp" page rendered by Tomcat/webMathematica. enter image description here

The above is a rudimentary example, no handling of null (nil) case. If your case is more complicated, you may want to make your own function that streams out and HTML Select.

POSTED BY: Hans Michel

Thanks, it is just I was looking for.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract