Hi I'm trying to invoque a servlet from a JSP page, what I want to do is to pass a parameter, well 2 parameters, but one of them is not static, it's the result of a select, this is my code:
<form>
<select name="tipoReporte" id="tipoReporte">
<option value="0" selected>Seleccione el tipo de reporte que desea ver:</option>
<option value="sem">Semanal</option>
<option value="2hrs">Cada dos horas</option>
</select>
</form>
As you see, the user will choose an option and depending on it, my servlet will do different things, here's the code to pass my parameters to my servlet:
<a target=_blank href="servlet1?cmd=graphic_jetta&tipoReporte= ¿what should I pass? ">
<img src="images/je1.png" width="200" height="100" id="je" onmouseover="changeImage('images/je1.png', 'images/je2.PNG', 'je')" onmouseout="changeImage('images/je1.png', 'images/je1.png', 'je')"/>
</a>
Then on the servlet I use the request.getParameter() method, but my problem is that I don't know how to pass this value in the code above. For instance, the first parameter doesn't give me problem cause is static, but the second one is my problem.
I'm new in web developing, so I would appreciate your patience and help, thank you!!
Create a JavaScript function for submitting:
function submit() {
var tipoReporte = document.getElementById('tipoReporte').value;
window.location.assign('servlet1?cmd=graphic_jetta&tipoReporte=' + tipoReporte);
}
and replace the link with:
<a target=_blank onclick="submit()">
or avoiding that, you can make the image part of the form:
<form action="servlet1">
<select name="tipoReporte" id="tipoReporte">
<option value="0" selected>Seleccione el tipo de reporte que desea ver:</option>
<option value="sem">Semanal</option>
<option value="2hrs">Cada dos horas</option>
</select>
<input type="hidden" name="cmd" value="graphic_jetta">
<input type="image" src="images/je1.png">
</form>
Related
Some datalists are not viewed properly. Only the initial value of the input is proposed in the datalist.Where is my fault ?
I generate with php and data from Amazon, Google and French BnF (National Library) some datalists so that the user may choose his proper information.
It works most of the time (95%). But I get issues with some datalists. Only one option is viewed, the initial value of the input.
Code 1:
<input id="author" name="item_author" value="Sophie de Ségur" onchange="javascript:submit();" list="data_author">
<datalist id="data_author">
<option value="Comtesse de Ségur">Amazon</option>
<option value="Comtesse de Ségur">BnF</option>
<option value="Sophie Rostopchine de Ségur">Google</option>
<option value="Sophie de Ségur">BnF</option>
<option value=" Bertall">BnF</option>
</datalist>
Result code 1:
Only fourth option viewed (initial value of input).
Example 2:
<input id="author" name="item_author" value="Catherine Ard" onchange="javascript:submit();" list="data_author">
<datalist id="data_author">
<option value="Mickael Wiles">Amazon</option>
<option value="[textes par Catherine Ard]">BnF</option>
<option value="Catherine Ard">BnF</option>
</datalist>
Result code 2:
Only last option viewed (initial value of input)
Example 3:
<input id="publisher" name="item_publisher" value="Gallimard jeunesse" onchange="javascript:submit();" list="data_publisher">
<datalist id="data_publisher">
<option value="Editions Gallimard">Amazon</option>
<option value="Gallimard jeunesse">BnF</option>
</datalist>
result code 3:
Only last option viewed (initial value of input)
In all 3 examples, when I click on the arrow at the right of the input (on chrome), I expect to get a menu with all options.
But I get only the option that is the value of the input.
Problem is linked to autocomplete of "input" with its initial value, an autocomplete that can't be switched "off".
So solution in the context of "onchange="javascript:submit();"" is to use 2 "input".
First "input" with datalist, value="" and onmousedown="value = '';" in the short width "input".
Second "input" with the initial value.
NB1: Depending on the "form" context, you may use two different "name" for the two "input" (and processed them in PHP or JS).
NB2: cause of width constraint (nicer and smaller MMI), I prefer an "input" with a datalist rather than a "select".
Solution for example 1:
<input id="author" name="item_author" onchange="javascript:submit();" list="data_author" onmousedown="value = '';" style="width:5vmin;">
<datalist id="data_author">
<option value="Comtesse de Ségur">Amazon</option>
<option value="Comtesse de Ségur">BnF</option>
<option value="Sophie Rostopchine de Ségur">Google</option>
<option value="Sophie de Ségur">BnF</option>
<option value=" Bertall">BnF</option>
</datalist>
<input id="author" name="item_author" value="Sophie de Ségur" onchange="javascript:submit();">
Thanks to:
Bryan Dellinger: https://stackoverflow.com/users/2744722/bryan-dellinger for his proposal ;
analysis in: How to turn off autocomplete while keep using datalist element in html ;
"binary" j08691: https://stackoverflow.com/users/616443/j08691 (in memory of the binary reverse engineering of my "Sharp PC 1245" in the 80's).
Extending #Franck's answer - He is absolutely right about the initial value causing the behaviour of only one option showing up.
Just offering my solution to this - on focus you can get the value, set it as a placeholder and clean the field - so it is still visible but the datalist works just fine.
With jQuery it would be something along these lines;
my_input.focus(function(){
var initial_value = $(this).val()
$(this).val("")
$(this).attr("placeholder", initial_value)
...
)}
This question already has an answer here:
Not send GET variable on submit if dropwdown not selected
(1 answer)
Closed 5 years ago.
I have a GET form to select a search filter.
<form action="" method="get">
<select name="filter">
<option value="">no filter</option>
<option value="1">filter1</option>
<option value="2">filter2</option>
</select>
<input type="submit" value="Search"/>
</form>
If the user selects filter1, the url will be /search?filter=1, but if he chooses no filter, the url will be /search?filter=
I want it to be /search
How can I tell the form to only submit non-default values?
you can use javascript or jquery to do this.
Set an id to select list and perform javascript onchange event. if user will select no filter then name attribute will be remove so the filter type will not be the part of search but if user will select filter1 or filter 2 then name of select list will be filter so it will be showing in search variables.
<form action="" method="get">
<select id="filter" name="filter">
<option value="">no filter</option>
<option value="1">filter1</option>
<option value="2">filter2</option>
</select>
<input type="submit" value="Search"/>
</form>
<script>
$("#filter").change(function(){
if($(this).val()==''){
$(this).removeAttr("name"); // if no filter selected
}else{
$(this).attr("name","filter"); // if filter 1 or filter 2 selected
}
});
</script>
I think you can write your submit function! So you can do as the following code:
1) change the type of input from submit to button and add the onclick property to point to your submit function;
2) there, you check for the value of select item, and if it is not selected, not to send any default value.
3) using an empty form and change its method to POST.
Follow an example code:
<html>
<head>
<script type="text/javascript" >
function mySubmit() {
var url="/search";
if (document.myForm.filter.value>0) {
url=url+"?filter="+document.myForm.filter.value;
}
document.mySubmitForm.action=url;
document.mySubmitForm.submit();
}
</script>
</head>
<body>
<form name="mySubmitForm" action="" method="post"> </form>
<form name="myForm" >
<select name="filter">
<option value="">no filter</option>
<option value="1">filter1</option>
<option value="2">filter2</option>
</select>
<input type="button" value="Search" onclick="javascript:mySubmit();"/>
</form>
</body>
</html>
try
<option value="0">no filter</option>
and put validations on it
Im pretty sure you can't. You're submitting that data and no value is still a value.
Just use correct validation to check if filter is empty.
I wonder if it is possible to use both enctype="multipart/form-data" and a select multiple. Here is the drill:
I have this html file (test.html):
<form action="action.asp" method="post" enctype="multipart/form-data" name="form1">
<select multiple name="prof">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<input type="submit" value="Ok" name="Ok">
</form>
When I select any of those options on my list, my action page doesn't show anything (action.asp):
<%
dim prof
prof = request.form("prof")
response.write prof
%>
But if I remove the enctype="multipart/form-data" in test.html, then it works.
The problem is that I am using an asp upload file component that requires this enctype="multipart/form-data". Any sugestions?
Thanks in advance.
Finally found a bug on FileUploader class. The mcolFormElem Dictionary variable does not add the name/value pairs if already exist on the collection for the <select multiple> element, I have added the below code and working fine.
If Not mcolFormElem.Exists(LCase(sInputName)) Then
mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
else
dim tempKeyVal
tempKeyVal=mcolFormElem.item(LCase(sInputName))
mcolFormElem.Remove(LCase(sInputName))
mcolFormElem.Add LCase(sInputName), tempKeyVal&","&CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
end if
if your using enctype="multipart/form-data" it must be because you are uploading a file. if you upload a file you should be using a upload component if you do you could use :
Set yourUploadComponent =
CreateObject("Your.UploadComponentClassString")
sFormValue =yourUploadComponent.Form.Item("prof").Value
I'm trying to append an option value to a form action, using method get. Submit sends the form request but isn't attaching the select option to the action?
So when the form is submitted it should use >
https://url.here.com?domain= users search here + selected option?
Thanks in advance.
<form action="https://url.here.com?domain=" method="get">
<div class="just-arrived-search">
www.<input type="search" name="domain" placeholder="Search" />
<select>
<option value="">All</option>
<option value=".bike">.bike</option>
<option value=".clothing">.clothing</option>
<option value=".guru">.guru</option>
<option value=".holding">.holdings</option>
<option value=".plumbing">.plumbing</option>
<option value=".singles">.singles</option>
<option value=".venture">.ventures</option>
</select>
<button class="btn-new" type="submit">Register Domain</button>
</div>
</form>
UPDATE: Since you edited your initial post to more clearly explain what you are attempting to achieve, here is a simple solution to your issue.
Use JavaScript to append the selected value to the domain before it submits. Change the button to have an onclick attribute as oppose to making it submit the form.
Add this JavaScript to your head section (or wherever you want, but convention is typically the HEAD section or bottom of the body):
<script type="text/javascript">
function submitForm() {
var ext = document.getElementById('ext');
var selected_opt = ext.options[ext.selectedIndex].value;
// Add own code to handle "All" here
var domain = document.getElementById('domain');
// Append selected option
domain.value = domain.value + selected_opt;
// Submit form
document.getElementById('myForm').submit();
}
</script>
And this is the updated HTML code to go along with it:
<form action="https://url.here.com" method="get" id="myForm">
<div class="just-arrived-search">
www.<input type="search" id="domain" name="domain" placeholder="Search" />
<select id="ext">
<option>All</option>
<option>.bike</option>
<option>.clothing</option>
<option>.guru</option>
<option>.holdings</option>
<option>.plumbing</option>
<option>.singles</option>
<option>.ventures</option>
</select>
<button class="btn-new" onclick="submitForm();">Register Domain</button>
</div>
</form>
I have a piece of html code which represents a part of a website that is supposed to be the search widget for a directory of a faculty in a university
<div id="right_column" class="content_main">
<div class="searchbox">
<form method="POST" action="/faculty/directory_search/" id="searchform">
<h4>Search the Directory</h4>
<input type="text" name="searchterms" value="" />
<select name="category" class="dropdown"> <option value="all" selected="selected">All Categories</option> <option value="Faculty">Faculty</option> <option value="Staff">Staff</option> <option value="Visitors">Visitors</option> <option value="Full time">Full time</option> <option value="Visiting">Visiting</option> <option value="Special Appointment">Special Appointment</option> <option value="Biological Sciences">Biological Sciences</option> </select>
<input type="hidden" name="sort" value="asc" />
<input type="submit" class="submit" value="Search directory" />
<a class="button" href="/faculty/index/desc" id="sortbutton">Sort Alphabetically</a>
</form>
<script type="text/javascript">
$('#searchform').ready(function(){
$('#sortbutton').click(function(){
$('input[name="sort"]').val('desc');
$('#searchform').submit();
return false;
});
});
</script>
</div>
I am trying to input the name "john" and submit the search using jsoup using the following java code (intended for android but it's overall the same java code as for a regular java app)
Document doc = Jsoup.connect("http://www.qatar.cmu.edu/directory/").data("searchterms", "john").post();
However, I keep getting the same page as just "http://www.qatar.cmu.edu/directory/" with no search submitted. I noticed that in the html code there is the submit input type. I'm wondering if I had to submit the search. If so, how can it be done?
I believe you are performing a POST request to the page containing the form, not the forms endpoint. This should work:
Document doc = Jsoup.connect("http://www.qatar.cmu.edu/faculty/directory_search/").data("searchterms", "john").data("sort", "asc").data("category", "all").post();
It makes the POST request directly to the forms endpoint.