how can get dropdown selected value in textbox in jsp - java

i want selected value in input text field in jsp how to do please help? I am new with jsp.
<select class="leavetype" name="leavetype">
<option value="10">CL</option>
<option value="7">ML</option>
<option value="12">SL</option>
<option value="20">EL/PL</option>
<option value="5">CPL</option>
</select>
<input type="text" name="leave"/>

See this video:- https://www.youtube.com/watch?v=89rRD04QZE4
Hope so it will help you.
In jsp page you may write. ${param.leavetype}.

You can achieve through javascript by using onChange function. Within in function need to do like this document.getElementById ("leave").value = data.value;
Refer this Answer

Related

Send value from select to servlet

I want to get the value from a select to a servlet. It works but not correctly.
<select name="type" class="txtBox">
<%while (rs2.next()) {%>
<%if (!rs2.getString("states").trim().equalsIgnoreCase("inactive")) {%>
<option value="<%=rs2.getString("loancode").trim()%>">
<%=rs2.getString("loanname").trim()%>
</option>
<%}%>
<%}%>
</select>
this code is after load to browser
<select name="type" class="txtBox">
<option value="VL">veheicle loan</option>
<option value="HL">housing loan</option>
<option value="EL">education loan</option>
</select>
It works OK, but after save to DB value from combo box saved value not loancode value .saved value is loanname value.
like this pic i want to save loantype as vehicle loan.but it save as 'veh'(option name first 3 character) i want save as 'VL'(value of option).but i can't imaging how to do this please help me to do this.
*loanename,loancode,loantype is my DB column
**sorry for my bad english

html load conditional value to select tag

I try to load conditional value to a select tag based on the user's choice on a pervious form tag. it might require java or php. i am not competent in any of those two language.
the logic is explain as the following.
<form>
<input name="complaint" value="copyright" type="radio">copyright <br>
<input name="complaint" value="trademark" type="radio">trademark <br>
<input name="complaint" value="other_concern" type="radio"> other concerns
</form>
if complaint="copyright" then
<select>
<option value="image">image</option>
<option value="product">product</option>
</select>
elseif complaint="trademark" then
<select>
<option value="item">item</option>
<option value="image">image</option>
</select>
elseif complaint="other_concern"
<select>
<option value="explain">explain</option>
</select>
end if
any solution?
Heres a solution in Jquery. Add a class name to the inputs and hide the selct options by default
<input name="complaint" value="copyright" type="radio" class="complaint">
then add unique ID tags to the select options along with a css class i like to use, .addClass and .removeClass are slighty faster and more efficent than .hide() and .show() selectors
Add the css at the bottom of your css sheet
.hidden{position:absolute;width:0;height:0;overflow:hidden;visibility:0;padding:0;margin:0}
<select id="copyright" class="selectOptions hidden">
<option value="image">image</option>
<option value="product">product</option>
</select>
Finally add some JQuery You need to copy the remainder for your other hidden values
$('.complaint').click(function() {
$('.selectOptions').addClass('hidden');
var checkComplaint = $(this).val();
$('#' + checkComplaint).removeClass('hidden');
});

How Do I Make a Dropdown Menu That Places A Text In a text Field

How do i make a drop down menu that when an option is chosen it creates a text that is placed in a text box. For Example,
Dropdown menu option1 = "are good"
i want the output to be, "Waffles Are Good". Waffles Will Automatically be there and they select an option from the drop down menu and it places the text "Are Good" Onto A Text Field
<p>Waffles <span id="whatarewaffles"></span></p>
<p>
<label>What's with the waffles?
<select id="wafflemachine">
<option value="are good">they are good</option>
<option value="are delicious">they are delicious</option>
</select>
</label>
</p>
<script>
document.getElementById("wafflemachine").onchange = function() {
document.getElementById("whatarewaffles").innerHTML = this.options[this.selectedIndex].value;
};
</script>
You mean something like this?
In javascript you can use jquery to do this.
You can check my full code here https://jsfiddle.net/tmhnfL9d/
$('#selectme').change(function(){
$("#sentence").html('Waffles');
answer = $(this).val();
$("#sentence").append(answer);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="selectme">
<option value= "">Please Select</option>
<option value= " are Good">are Good</option>
<option value= " are Bad">are Bad</option>
</select>
<p id="sentence">Waffles</p>
As per my understanding I made this fiddle. Let me know is it helpful for you.
HTML
<select id="data1">
<option value="good">good</option>
<option value="too good">too good</option>
</select>
<input type="text" id="data2" value="Waffles good"/>
Jquery
$("#data1").val("good").change(function(){
var k=($("#data1").find(":selected").text());
$("#data2").val('Waffles'+k);
});

Get all select Values in Java

I have a SELECT tag in JSP page that contains few values :
<select name="selectNumber" size="3" multiple="multiple" tabindex="1">
<option value="11">eleven</option>
<option value="12">twelve</option>
<option value="13">thirette</option>
<option value="14">fourteen</option>
<option value="15">fifteen</option>
<option value="16">sixteen</option>
<option value="17">seventeen</option>
<option value="18">eighteen</option>
<option value="19">nineteen</option>
<option value="20">twenty</option>
</select>
And I want to get all that values in a Java Class.
What I have tried that :
HttpServletRequest req = (HttpServletRequest)ServletActionContext.getRequest();
String[] selectedNumbers = req.getParameterValues("selectNumber");
But that Array only contains the value I am selecting, and If I don't select any value it contains null. But I want all the option values of the select Tag in java class. Any help?
I am using Struts 2 framework.
if you want to send all the Options to Your Servlet then you must first select them all using simply using Jquery
Before Submitting the Form
$("#selectNumber option").prop('selected',true);
Note #is used for Id , which i prefer if you need to use only name then try
$('[name="selectNumber"]');

Add one more option field in the Struts2 select tag

i have one struts 2 select tag like below.
<s:select list="myList" listKey="myListVal" listValue="myListDesc"></s:select>
it rendered as below
<select data-inputs="myListInput" >
<option value="myListVal1" >myListDesc1</option>
<option value="myListVal2" >myListDesc2</option>
<option value="myListVal3" >myListDesc3</option>
</select>
i want to add one more option field with null value
<option value="" ></option>
to the Option field with modification in the list.
In struts 1 it is possible like below
<html:option value=""></html:option>
like that is it possible in the struts 2
note:i couldn't able to modifiy the list before the page load in the java
There is an Attribute called emptyOption in the select tag.
It worked as below.
<s:select list="myList" listKey="myListVal" listValue="myListDesc" emptyOption="true" ></s:select>
if you want to add one more option field with null value at the begining of the list you can use headerKey & headerValue attribute of s:select tag.
Check example given below.
<s:select list="myList" listKey="myListVal" listValue="myListDesc" headerKey="0" headerValue="" ></s:select>
So the first element of your list will be empty & it's value will be 0(zero) here.
It will be render as
<select data-inputs="myListInput" >
<option value="" >0</option>
<option value="myListVal1" >myListDesc1</option>
<option value="myListVal2" >myListDesc2</option>
<option value="myListVal3" >myListDesc3</option>
</select>
You can set any value on place of 0 (zero).
Hope this will help you.

Categories