Dropdown default values return null? - html

I have html in my JSP which ask simple questions, as well as having drop-down boxes for users to select their responses. I also set default responses as well incase they decide to just hit next however I always get null returned. JSP:
<div id="startQrtQuestion" align="left">1) When did you first arrive here?</div>
<div id="startQrtResponse" align="left">
<select name="quarterStart">
<option value="summer">Summer Quarter</option>
<option value="fall" selected="selected">Fall Quarter</option>
</select>
</div>
<div id="programQuestion" align="left">2) What program are you taking?</div>
<div id="programResponse" align="left">
<select name="programSelect">
<option value="bscs" selected="selected">BSCS</option>
<option value="bstm">BSTM</option>
<option value="bsgd">BSGD</option>
<option value="bswd">BSWD</option>
</select>
</div>
<div id="extendedQuestion" align="left">3) Will you be staying extra quarters?</div>
<div id="extendedResponse" align="left">
<div name="extendedStayResponses">
<input type="checkbox" name="extendedStay" id="extendedStay"/>Yes
</div></br>
<div id="extendedFullTime" style="display:none">
Full Time:<select name="extraFullQuarters">
<option value="0" selected="selected">0</option>
<option value="1">1</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>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>(Taking 12 Credits or More)
</div></br>
<div id="extendedPartTime" style="display:none">
Part Time:<select name="extraPartQuarters">
<option value="0" selected="selected">0</option>
<option value="1">1</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>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
</div>
This is all wrapped in a form that will call the post method in my servlet. However when I retrieve those values like so:
String startQuarter = request.getParameter("quarterStart");
String programSelect = request.getParameter("programSelect");
String extendedStay = request.getParameter("extendedStay");
I get null pointer exceptions. Is the value not automatically set to what I have as my default selected option?
Am I not accessing these inputs correctly?

I found out it wasn't any of this code. But another set of code in my group's project.
It turned out to be a session attribute that's suppose to be set, but isn't.

it might be your request object is null.Check it once.

Related

How to require a selection in my select element on my signup form [duplicate]

This question already has answers here:
How do I make a field required in HTML?
(16 answers)
Closed 2 months ago.
<label for="select-choice">Birthday:</label>
<select name="select-choice" id="select-choice">
<option value="0" selected disabled>Month</option>
<option value="january">Jan</option>
<option value="february">Feb</option>
<option value="march">Mar</option>
<select name="birthday-day" id="day">
<option value="0" selected disabled>Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<select name="birthday-year" id="year">
<option value="0" selected disabled>Year</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
The Sign Up or Register page is okay but I could not validate the birthday, When I try filling it on a browser I expect it to demand or require birthday option, every other input option was demanding or requiring me to input an information but if I purposely did not fill the birthday and hit the submit button it will go through just like that, please how do I validate the birthday using HTML?
You just need to add "required" to each of your selects and then just add an empty value instead of a "0" value. When you press a button, it will detect it has no value and will automatically make the select required.
<form>
<label for="select-choice">Birthday:</label>
<select name="select-choice" id="select-choice" required>
<option value="">Month</option>
<option value="january">Jan</option>
<option value="february">Feb</option>
<option value="march">Mar</option>
</select>
<select name="birthday-day" required>
<option value="">Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="birthday-year" id="year" required>
<option value="">Year</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
<button>submit</button>
</form>

How select POST values from different select options?

For example, I have 3 different select options:
<select name="FirstOption">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<select name="SecondOption">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<select name="ThirdOption">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
So, when I click a button, I want to get all the values of all 3 select options and insert the values into the database.
Right now, I'm using this button with a href tag but looks like it's very wrong:
Reserve
What's the best way to do this?
Wrap the selects inside a form and put a submit button.
Add your ID as hidden fields.
Your HTML code should now be something like this :
<form method="post" action="../reservation-confirmation">
<select name="FirstOption">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<select name="SecondOption">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<select name="ThirdOption">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<input type="hidden" value="" name="tour_id" >
<button type="submit" name="submit'> Submit </button>
</form>
On the server-side, process the responses by targeting
if(isset($_POST['submit']))
$FirstOption$=$_POST['FirstOption']
$SecondOption$=$_POST['SecondOption']
$ThirdOption$=$_POST['ThirdOption']
... //Add them into your database.
Remember to use prepared statements.

Fill online form (dropdown) with python

how can I fill an online form with python (preferably with the requests library)?
On the website http://carsalesbase.com/european-car-sales-data/alfa-romeo/alfa-romeo-giulia/
there are four forms in total. Three are looking more or less identical.
I want to fill one of these three. It is a form with two dropdown menus.
<form action="http://carsalesbase.com/" class="search-form" method="get" role="search">
<input class="" id="hide-value" name="hide-value" type="hidden" value="1"/>
<select class="kelas1" id="brand-option" name="brand-option">
<option value="0">Select Brand</option>
<option value="82"> Group</option> <option value="17">Alfa Romeo</option> <option value="1">Alpina</option> <option value="249">Alpine</option> <option value="2">Aston Martin</option> <option value="67">Audi</option> <option value="68">Bentley</option> <option value="4">BMW</option> <option value="259">Borgward</option> <option value="8">Brilliance</option> <option value="69">Bugatti</option> <option value="27">Cadillac</option> <option value="75">Caterham</option> <option value="29">Chevrolet USA</option> <option value="28">Chevrolet-Daewoo</option> <option value="13">Chrysler</option> <option value="48">Citroën</option> <option value="54">Dacia</option> <option value="63">Daihatsu</option> <option value="14">Dodge</option> <option value="12">DR Motor</option> <option value="160">DS</option> <option value="18">Ferrari</option> <option value="19">Fiat</option> <option value="87">Fisker </option> <option value="24">Ford</option> <option value="33">Great Wall</option> <option value="34">Honda</option> <option value="30">Hummer</option> <option value="35">Hyundai</option> <option value="51">Infiniti</option> <option value="89">Isuzu</option> <option value="60">Jaguar</option> <option value="15">Jeep</option> <option value="36">Kia</option> <option value="3">Lada</option> <option value="70">Lamborghini</option> <option value="20">Lancia</option> <option value="23">Lancia-Chrysler</option> <option value="61">Land Rover</option> <option value="85">Landwind</option> <option value="64">Lexus</option> <option value="45">Lotus</option> <option value="83">Mahindra</option> <option value="21">Maserati</option> <option value="78">Maybach</option> <option value="40">Mazda</option> <option value="88">McLaren</option> <option value="9">Mercedes-Benz</option> <option value="41">MG</option> <option value="5">Mini</option> <option value="44">Mitsubishi</option> <option value="84">Morgan</option> <option value="52">Nissan</option> <option value="31">Opel/Vauxhall</option> <option value="47">Perodua</option> <option value="49">Peugeot</option> <option value="71">Porsche</option> <option value="46">Proton</option> <option value="91">Qoros</option> <option value="55">Renault</option> <option value="6">Rolls Royce</option> <option value="42">Rover</option> <option value="58">Saab</option> <option value="90">SAIC MG</option> <option value="72">Seat</option> <option value="73">Skoda</option> <option value="10">Smart</option> <option value="38">SSangYong</option> <option value="56">Subaru</option> <option value="57">Suzuki</option> <option value="62">Tata</option> <option value="86">Tesla</option> <option value="65">Toyota</option> <option value="74">Volkswagen</option> <option value="26">Volvo</option>
</select>
<select class="kelas1" id="model-option" name="model-option">
<option value="0">Select Model</option>
</select>
<input name="css-go" type="submit" value="Go"/>
</form>
I cannot find any good resource explaining how to do that :(
Who can help?
Thanks!
You cannot click on stuff with the requests library, but what you can do to get the data is mimic the HTTP request made after a form is submitted.
Use Chrome Network tools or Fiddler to analyze all of the requests your browser sends to the server when you submit a form. In this case, when submitting a form with the car brand as Tesla and the car model as Model X, we can see the request's method, which is of type GET, the base URL, and the required parameters.
We can use this information to simulate a webpage form submit and get the data that way:
import requests
params = {
"hide-value": 1,
"brand-option": 86,
"model-option": 2129,
"css-go": "Go"
}
html = requests.get("http://carsalesbase.com/", params=params).text
print(html)
I would use selenium, it lets you script what you would do as a user manually.
Here's a description of how to select elements on a webpage.
This answer explains how to select an option from a dropdown.

Options in select field only appearing after switching tab

I have a problem with a <select> in my code. As you can see in the picture when I reach this point in the checkout the options are hidden in a strange way.
When I just switch the tab and go back everything is fine.
The code is:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'payone_iframe_min.js?' + window.location.search.substring(1);
document.body.appendChild(script);
<select id="cardexpiremonth" style="width: 113px;">
<option value="0"></option>
<option value="1">1</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>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
I just can't figure out why this happens or how I can resolve this. Do you guys have any ideas?
There shouldn't be anything wrong with this. I tested in Chrome and Firefox. Maybe it is because of <option value="0"></option> because it is empty. but that should work.
<select id="cardexpiremonth" style="width: 100px;">
<option value="1">1</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>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>

How to link page like href="#page_3" in select option in intel xdk?

<select id="byplanname" name="byplanname" style="display:none;">
<option value="Select Plan Name" multiple="multiple">Select Plan Name</option>
<option value="815" href="#page_3">815</option>
<option value="816">816</option>
<option value="816">817</option>
<option value="818">818</option>
<option value="820">820</option>
<option value="821">821</option>
<option value="822">822</option>
<option value="823">823</option>
<option value="904">904</option>
</select>
The href="#page_3" is not working ,Please tell me proper linking in intel xdk..thanx
Try something like this:
<select id="byplanname" name="byplanname" onchange="location = this.options[this.selectedIndex].value;">
<option value="google.com">815</option>
<option value="google.com">816</option>
<option value="google.com">817</option>
<option value="google.com">818</option>
<option value="google.com">820</option>
<option value="google.com">821</option>
<option value="google.com">822</option>
<option value="google.com">823</option>
<option value="google.com">904</option>
</select>
For using #page_3 you will have to put in your URL before that so it would be website.com/#page3 in the value field
JSFiddle:
http://jsfiddle.net/fqB3Z/