submitting a text search using jsoup - html

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.

Related

How to modify this HTML form to include a constant?

Here's an example of a search in our SirsiDynix Enterprise catalog using the CloudSourceOA option te=750777545
https://nyit.ent.sirsi.net/client/en_US/default/search/results?qu=html&te=750777545&rt=false%7C%7C%7C%3ECSOA%3Ctitle%7C%7C%7CTitle
I want to pass the variables from a form in libguides to the enterprise. I have a working example for searching "Everything" and a broken example for the CloudSourceOA
My Form sends the search types like title and the term that the user enters in the input field to the qu=, however, I don't know how to append the te=750777545. This value will always be set as I want the widget to always search cloudsource rather than everything.
Here's a link to my libguide for troubleshooting. I was unable to add the code successfully here.
https://libguides.nyit.edu/c.php?g=1216772&p=8899584&preview=77a637b8476d8bbe2575a12fd18e3b61
It's unclear what te or the 750777545 value is, but if you need to hardcode that to your form you can do so with a hidden input set to that value. Fair warning, without knowing what this form field is, this may not be the best approach so you'll want to consult any documentation if this is specific to an internal NYIT application.
<form action="https://nyit.ent.sirsi.net/client/en_US/default/search/results?" id="searchForm" method="&te=""get"" name="searchForm">
<h5>Search the NYIT Catalogue</h5>
<div class="searchline">
<input name="ln" type="hidden" value="en_US"><br>
<select class="dropDown" id="restrictionDropDown" name="rt">
<option value="">
All Fields
</option>
<option value="false|||TITLE|||Title">
Title
</option>
<option value="false|||AUTHOR|||AUTHOR">
Author
</option>
<option value="false|||SUBJECT|||SUBJECT">
Subject
</option>
<option value="false|||ISBN|||ISBN">
ISBN
</option>
<option value="false|||ISSN|||ISSN">
ISSN
</option>
<option value="false|||DOI|||DOI">
DOI
</option>
<option value="false|||JOURNAL|||Journal Title">
Journal Title
</option>
</select>
<input type="hidden" id="te" name="te" value="750777545">
<p><input accesskey="s" id="qu" maxlength="256" name="qu" style="width:250px;" title="Search For:" type="text" value=""><input class="button" id="searchButton" title="Search" type="submit" value="Search"></p>
</div>
</form>

How to Make HTML Form Drop-Down List Items Redirect

I'm creating a pretty basic website as a beginning web developer. I'm wondering how you can take a value from a drop-down list form in HTML, click the submit button, and have it redirect you to a new page, depending on what was chosen. Each month should be a new webpage. Here's the code:
<form action="" method="get">
<p>Month</p>
<select name="months">
<option value="march2015">March, 2015</option>
<option value="april2015">April, 2015</option>
<option value="may2015">May, 2015</option>
<option value="june2015">June, 2015</option>
<option value="july2015">July, 2015</option>
</select>
<input type="submit" value="Submit">
</form>
I'm a little unclear about what to put for the "action" attribute. I'm not using a web hosting service, I'm just viewing the file in my browser.
You need some Javascript for that.
Update your HTML like this:
<form id="form" action="" method="get">
(...)
<select name="months" onchange="update_action(this)">
(...)
</select>
(...)
</form>
And attach via <script /> tag file with following code:
JS (script.js)
var update_action = function(obj) {
var val = obj.value;
var url = /* Setup your URL here. */;
document.querySelector('#form').setAttribute('action', url);
};
Should work :)

Rendering Spring form:select Attributes

In my JSP I'm trying to use JQuery Validate on my Spring form yet the validation never runs. The problem seems to be that the Spring form select element doesn't render attributes in the DOM. Below I have a small example to make the issue clearer with Spring form "foo" and the output in the DOM (note: I have the attribute modelAttribute on my Spring form and path on each Spring select that I have not included here). Is there a way to render the specified attributes?
<form:form id="foo">
<form:select id="test" name="test" required>
<form:option value="">Select Country</option>
<form:option>US</option>
<form:option>Canada</option>
</form:select> <br />
</form:form>
<input type="submit" value="Submit" onclick='$("#foo").valid()'>
<script>
$("#foo").validate();
</script>`
DOM:
<form id="foo">
<select id="test">
<option value="">Select Country</option>
<option>US</option>
<option>Canada</option>
</select>
</form>

I'm trying to append an option value to a form action

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>

Pass value of <select> via url on form submit

I have a simple form that I want to pass the user selection via url.
<form method="GET" action="course-registration.asp">
<select>
<option value="#">--Select--</option>
<option value="courseOfferings[special_1005][item_1]=January%2030-31,%202014&course=ArcCHECK / 3DVH Product Training&date=January 30-31, 2013&description=This hands-on product training course focuses on the use of the ArcCHECK 3-dimensional beam dosimetry QA system with 3DVH software.">January 30-31, 2014</option>
</select>
<input type="submit" value="Submit">
</form>
If I alert the value of the select, it shows correctly, but it does not pass to the url when button is pressed.
You need to give a name to the select element
like <select name="dept">
<form method="GET" action="course-registration.asp">
<select name="something">
<option value="#">--Select--</option>
<option value="cof">January 30-31, 2014</option>
</select>
<input type="submit" value="Submit">
</form>
this will make your url lookblike "http://some.co/?something=manything"