Hidden field value with spaces in jsp [duplicate] - servlets

I have a strange issue with dropdown boxes in jsp/servlet. Here it is...
<select name="locdropdown" onchange="javascript:change()" >
<%
for(LocationDO locationDO : locationList){%>
<option value=<%=locationDO.getLocationName().trim()%>><%=locationDO.getLocationName().trim()%></option>
<%} %>
</select>
values displayed are:
BI Sholingar
BI Mahindra City
BI Sanand
Rolltec_DTA
Aztec Auto Ltd
BI Gurgoan
and here is how I try to read it in servlet.
String locclasses = req.getParameter("locdropdown");
System.out.println(locclasses);
assume I select Aztec Auto Ltd then expected output from servlet is same right. But output is Aztec. similarly, if I select BI Sanand, the actual output that comes is BI
Can someone help please

You need to quote the value.
<option value="<%=locationDO.getLocationName().trim()%>">
The space is namely a HTML attribute separator. A browser with a bit decent syntax highlighter would already have hinted it when you have checked the generated HTML by rightclick page > View Source.
<option value=Aztec Auto Ltd>
versus
<option value="Aztec Auto Ltd">

As said by BalusC in his answer the problem is with your value assignment.
Modify your code as :
<select name="locdropdown" onchange="javascript:change()" >
<%
for(LocationDO locationDO : locationList)
{%>
<option value="<%=locationDO.getLocationName().trim()%>" >
<%=locationDO.getLocationName().trim()%>
</option>
<%}
%>
</select>
Hope this helps.

Related

Unable to scrape information from website using IMPORTHTML

I'm attempting to copy the information from a website directly into my Google Sheets for some analysis. Below is the HTML element from the said website.
<div><span id="diodia" style="display: inline-block;">Διόδια<span style="color:red;">*</span>: <strong>19.35€</strong> </span><span id="showHideTolls" style="display: inline-block;"><span id="tollsVehicle"><select id="selectSth" style="background: url(https://vriskoapostasi.gr/images/car.png) left no-repeat;width:45px;-webkit-appearance: menulist"><option value="0" selected="selected"></option><option value="1">Αυτοκίνητο</option><option value="2">Δίκυκλο</option>
<option value="3">Αυτοκινούμενο υψ>2.7μ μηκ>5μ</option><option value="4">Λεωφορείο θέσεις>39</option>
<option value="5">Φορτηγό 2 άξονες</option><option value="6">Φορτηγό 3 άξονες</option>
<option value="7">Φορτηγό αξ>=4</option>
</select></span><span id="messageTolls"></span><span> <input type="checkbox" id="isTollSelected"></span></span></div>
What I want to get is the 19.35€ price located in the div above.
I use IMPORTHTML as follows:
=IFERROR(IMPORTHTML(A1, "//*[#id='diodia']/strong"), 0) # Where A1 holds the website link
But every time I get 0 because the content is empty. Why is that happening? Is there any workaround that I'm missing?
Thanks you in advance.

How to set drop down display none when any specific option selected using CSS

I am using a asp.net screen to enter the data as we as I also want to use same screen as red-only mode to view only for some users.
I have drop down in my screen that default selected index is 0 and text is 'Please Select' these drop downs are not mandatory so in edit mode user may not select any value for drop downs so default value would be 'Please Select' but when user open a same screen in read-only mode to view the saved data I want to hide those drop-down which are having default value as 'Please Select' but by using CSS. I have an option using jquery but I am looking a way by using css if it is possible. I have two css file that I am changing dynamically for read-only mode and edit mode.
I got some css as follows, in same way I am looking solution for my issue.
<!DOCTYPE html>
<html>
<head>
<style>
select [value=two][selected=selected] {
display:none
visibility:hidden;
}
</style>
</head>
<body>
<th>Show This Drop down</th>
<select id="ddlNumber">
<option value="-1">Please Select</option>
<option value="one">one</option>
<option value="two" selected="selected">two</option>
<option value="three">three</option>
<option value="four">four</option>
</select>
<br>
<br>
<th>Hide This Drop down by css</th>
<select id="ddlAlpha">
<option value="-1" selected="selected">Please Select</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
</select>
</body>
</html>

Selenium with Safari: can't select option from select input

I'm using Selenium with Mink to automatically register in a number of our websites.
To do that you have to select your birth date from three select inputs. I just use select-option with the xpath of the select field and the value of the option I want.
It works fine in Firefox and Chrome but in Safari, with some of the pages it works and with others nothing happens. There's no exception or anything, it just doesn't do anything with the select fields and then the rest of the test fails because the registration didn't work.
The CSS of the select fields is like this:
<select name="Signup:Birthday[day]" size="1" class=" date_day" id="Birthday">
<option value="" selected="selected">---</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
.......
</select>
I am using xpath //*[#id="Birthday"] and option 3 but in Safari it just does nothing.
public function selectState($option, $name) {
$page = $this->getSession()->getPage();
$selectElement = $page->find('xpath', '//*[#id="Birthday"]');
$selectElement->selectOption($option);
}
Any ideas?
You can try:
JavascriptExecutorUtils
.setSelectedOptionByDisplayValue(driver, webSeleniumElement.getWebElement(), "texte");
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].onchange();", webSeleniumElement.getWebElement());

Symfony crawler select tag attributes from dropdown

I need to target "selected" attribute in drop down menu so I can compare if item marked as selected is the item what I need to have selected.
Can you help me with methods, what I can use for this ?
<option value="Title" selected>Title</option>
<option value="First Name">First Name</option>
<option value="Middle Name">Middle Name</option>
Thank you :)
I've found an answer finally -
$crawler->filter('option[selected]')->attr('value');
works for me :)
Maybe something like that (not tested)
$target = $crawler->filterXPath('//.../option/#selected')->text();
or
$target = $crawler->filterXPath('//.../option')->attr('selected')->text();

asp.net mvc3/4 request.form to return the selected value and the selected text from selectlist

How would I get in my controller, the text part of Request.Form["StandID"]
<div class="editor-field">
<select id="StandID" name="StandID">
<option value=""/>
<option value="3">Mark</option>
<option value="5" Selected>Brian</option>
<option value="6">Ian</option>
<option value="7">Vin</option>
</select>
</div>
So in my controller, Request.Form["StandID"] = 5
Is it possible to retrieve the text (I know this isn't posted as part of the form - is there a way to do that)?
So I could like to return "Brian" - as well as the ID of 5?
Thank you,
Mark
No. HTML will only post the value to the controller. However, you could make your value be something like "5 - Brian" and then have your text be "Brian". Then you would have to parse the value to get the real value from it.
as an alternative you could use hidden input field to store your text value. The downside is you have to place your value into this hidden field with javascript (on selected change or on form submit), but pros is you will have separated field for value, so you don't have to parse it on server side and you can avoid possible problems with naming.

Resources