My form has a custom element like below, created using custom ajax:
<select jwcid="testtest <at> Any">
<option value="x">California -- CA</option>
<option value="y">Colorado -- CO</option>
<option value="z">Connecticut -- CN</option>
</select>
After the form is submitted, how do I get the value of this custom html element?
cycle.getPage().getComponents().get("testtest") ?
If I understand you correctly, you have a form element generated not by Tapestry, but by something else.
First of all, jwcid has no place in your HTML code, it's only used in Tapestry component templates. Second, the select element must have a name attribute or else your browser won't submit it at all:
<select name="name-of-element">
...
</select>
To get the submitted value on the server side, use cycle.getParameter("name-of-element") in your page/component class.
Related
I have defined a select(drop down) in my jsp page. When user will select one of these options i want to display some text boxes. I will use jsp tags to display those textboxes. But I don't know how can i get value of select tag in jsp on the same page. Here is my code:
<div class="col2" >
<select class="textbox" id="noo" name="noo" style="margin-top:10px;" required>
<option value="">Select</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<%
int noo=
%>
What should i write after = to get the selected value in variable?
This is possible if you use JSTL. You would need to add the jstl.jar file to your lib folder but then the selected value in the variable would be obtained using
${param.name}
JSP pages compile at server side not client side. So,its not possible that you select an option value and take action on it.
Yes, this similar thing you can do by JQuery or JavaScript.
If you really want to take support of server side code than ajax can help you.
Send selected value to servlet by ajax set response in session or request and iterate session or request in jsp .
JSP is a server side language. Whole html code will be generated before it sends a response to web browser.
So If you want to change something with respect to the value selected by user,
you must be using a client side scripting language like javascript.
Or submit value to server and generate a new page with respect to based on value submiteted.
There are two options:
To submit the form and get the attributes in another jsp or servlets and then return the value using the request.setAttribute(). After which you can get the attributes in the jsp part to display
You can use jquery that is get the value of the select tag after an event occurs e.g after selection e.g
var data = $('#noo').find(":selected").text();
Then display the data using a class or id selector.e.g
$('p').val(data)
I am working on a web applet. I am using JDBC to connect to a psql database, in which I am running a query to return. Right now I have a drop down list that will help determine how the query will be structured. My drop down list options are set up like this:
<option value="Location A">Location A</option>
Is there anyway that I can pass this value into my java function which header looks like:
<%
out.print("HOW DO I PRINT THE ABOVE VARIABLE);
%>
Regards,
Sudo!!
if your html is like
<select name='foobar'>
<option value='0'>0</option>
<option value='0'>1</option>
</select>
When submitted to your JSP, normally you can do
request.getParameter("foobar");
i have a question when i try to capture the value of dropdown list from jsp file to servlet.
<select name="extraroom">
<c:if test="${booking.roomType ne 'single'}">
<c:forEach var="i" begin="0" end="${booking.count}">
<option value="<c:out value="${i}"/>"><c:out value="${i}"/></option>
</c:forEach>
</c:if>
</select>
i use Integer.parseInt(request.getParameter("extraroom"))
i have many drop down lists according to different roomType.
but the result in java servlet always get the value of the first dropdown lists...
what should i change in servlet?
Thank you.
For a select to be retrieved by a server the select has to
be inside a form and
have a unique name identifier inside (it; best the identifier is unqiue across the entire DOM tree)
<td>Branch</td>
<td>
<select name="branch" type="text">
<option value="0">Select Branch</option>
<option value="CE">CE</option>
<option value="IT">IT</option>
</td>
<td>Batch</td>
i.e if i have branch field in my jsp form
so my branch firld contains 2 inputs as 1.CE & 2.IT.
So when i click on CE ,so it have to show me A1,A2,....A5 & when i click on IT, it will have to show B1...B5 from which we can select any one of the field.
So, pls help me for above program.
Here is my code.
Pls help me what code should i write in "Batch" field""
you have to register onChange() event of the branch and call an javascript function which will populate the batch field accordingly.
I am new to a Java environment and JSP. My question is, is is possible to detect the value of a select dropdown option and create a small if statement depending on this value?
For example:
<select id="my_select">
<option value="-1">Option 1</option>
<option value="0">Option 2</option>
</select>
<c:if test="${id eq -1}">
Show this
</c:if>
<c:if test="${id gt -1}>
Show this
</c:if>
Thanks guys!
No, you have to first realize the lifecycle of the JSP. The output is formed on the server and sent to the client. Then the client performs some actions and possibly submits a form back to the server.
In your case you have two options:
use javascript
submit the form holding the dropdown, and depending on ${param.id} show one or the other