JSP Dropdown from postgresql - postgresql

I'm very very new to jsp and postgresql and I want to add a dropdown menu to my jsp file.
There is table with Names and Numbers and all I want is getting the names displayed in the drop down
This is what I got so far. An empty dropdown with the right numbers of rows (4 as I have only for rows in my table) is displayed but no names!
<sql:query
dataSource="${db}"
var="result">
select name from customer
</sql:query>
<select>
<c:forEach
var="result"
items="${result.rows}">
<option value=${param.name}>${param.name}
</option>
</c:forEach>
</select>
Thanks for any help in advance!
PS: i tried to find an answer but all the answers were about mysql but we are using psql :/

Your option list has the right number or options but they're empty because the variable param doesn't exist.
You have:
<c:forEach var="result" items="${result.rows}">
<option value=${param.name}>${param.name}</option>
</c:forEach>
var is the variable to be created from items, so you don't want it named the same as the items list. This is where you should be creating the variable param. It should be:
<c:forEach var="param" items="${result.rows}">
<option value='<c:out value="${param.name}"/>'><c:out value="${param.name}"/></option>
</c:forEach>
You should probably also do it like <option value='${param.name}'> since the field name is probably text rather than numeric.

Related

I want to have a select and input field in react with all the options in my JSON file or mongodb database

I have to provide a dropdown in my form with a large number of options in it but the selected options are to be shown at various places so i have to store the selected option or its id at database too.
<FormGroup>
<Label htmlFor="category">Category</Label>
<select innerRef={input => (this.category = input)} id="select" class="form-control" >
<option value="0">Please select</option>
<option value="1">Mobiles</option>
<option value="2">Television</option>
<option value="3">Washing Machines</option>
</select>
</FormGroup>
This is the gist of the form type i want, there will be other categories in somewhere around 25. I cant have 25 options opening in dropdown. I want to have something like select and input type in dropdown. Also i want to store the option selected by the user and then display it somewhere else.

AutoHotKey: How to get list of available values from drop down list?

I am trying to automate a website to get data. Usually if I know in advance what are the possible value from the drop down list, I can hard code them in my script.
But if I don't know what are the values, is there an elegant way to dynamically obtain the drop down list values?
Working sample from: https://autohotkey.com/boards/viewtopic.php?t=15574
select name="ConnectDTO.EvaluationGroupId" id="ConnectDTO_EvaluationGroupId" style="width: 260px;" required="yes" data-val-number="The field Evaluation Group must be a number." data-val="true"><option value="">Please Select</option>
<option value="4">ccpdmanagement</option>
<option value="7">AM Northern</option>
<option selected="selected" value="3">cwplanning</option>
<option value="1">mnplanning</option>
<option value="2">msplanning</option>
<option value="9">LCC</option>
<option value="6">powerquality2</option>
<option value="8">AM Southern</option>
<option value="5">tcoqueries</option>
</select>
When my script arrived on the page after loadIE(wb), is there a way to "get" the list of selection - such as ccpdmanagement, AM Northern etc...?
I know how to select them once the option is known in advance only.
pwb.document.getElementById("ConnectDTO_EvaluationGroupId").Focus()
pwb.Document.GetelementById("ConnectDTO_EvaluationGroupId").value := "1"
Thanks.
I found a solution here: https://autohotkey.com/boards/viewtopic.php?t=35467
Althought the Author stated he has a problem with the code (stated not work for some reason).
But for my purpose - to retrieve the list of all the drop down list option. It worked fine.
myDropDownList := wb.document.getElementById("your_dropdown_ID")
loop % myDropDownList.length
{
test := myDropDownList[A_Index-1].value
MsgBox %test%
}

Angular 2: How to get the selected value from different options of a form?

I would like to use a <select> in a form to let the user being able to update values among different <option>. I have used the technique from the guide here: https://angular.io/docs/ts/latest/guide/forms.html. Here is the sample I am talking about:
<div class="form-group">
<label for="type">Type :</label>
<select class="form-control" [(ngModel)]="order.type" ngControl="type">
<option *ngFor="#type of types" [value]="type">{{type}}</option>
</select>
</div>
In my order-details.component I have got an updateOrder() which calls the updateOrder() from myApp.services.
My problem is when I am trying to send the data from the form to the back-end: all the parts with an <input> are OK, but not those with <select> (it returns the original values, and not the one selected).
Does anyone have encountered this or a similar problem?
Thanks for your help!
There is a way to get the value from different options.
check this plunker
component.html
<select class="form-control" #t (change)="callType(t.value)">
<option *ngFor="#type of types" [value]="type">{{type}}</option>
</select>
component.ts
this.types = [ 'type1', 'type2', 'type3' ];
this.order = {
type: 'type1'
};
callType(value){
console.log(value);
this.order.type=value;
}
Been tackling this problem for a few hours.
Checked in the (incomplete) documentation to find an item in the NgSelectOption page called "ngValue"
Not sure if this is the intended use but it seemed to work fine.
So instead of using
[value]="item"
Use:
[ngValue]="item"
Just use ngModel on the select and ngModelChange event if you want to do something when it changes.
In fact I can't reproduce your problem. I created a plunkr with a very simple form with an input and a select. When I submit the form, I have actual values in the bound object. See this plunkr: https://plnkr.co/edit/5C3agW7QZfcrdt88QzSh?p=preview.
Feel free to tell me if I didn't correctly understand your problem.
Thierry
If you have static, hard-coded values for the select tag like below:
<select #quantity>
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
<option value="four">4</option>
<option value="five">5</option>
</select>
You can do the following:
#ViewChild('quantity') quantity: ElementRef;
console.log(this.quantity.nativeElement.value); // will print value of the currently selected option

Zend_Form_Element_Select setValue is selecting more than one option

I am using Zend 1.11.10 and I am trying to set a value in a dropdown list. My code is:
$state = new Zend_Form_Element_Select("mytest");
$state->setLabel("mytest")
->setName("mytest");
$state->addMultiOption('Pear','PE');
$state->addMultiOption('Banana','BA');
$state->addMultiOption('Orange','OR');
$state->addMultiOption('Kiwi','KI');
$state->setValue('Banana');
$this->addElement($state);
The problem is that the generated HTML code is:
<select id="mytest" name="mytest" style="opacity: 0;"><option value="PE">Pear</option><option selected="selected" value="BA">Banana</option><option selected="selected" value="OR">Orange</option><option selected="selected" value="KI">Kiwi</option></select>
It is making "selected" all options after "Banana". Is this a bug in Zend?
Looks to me like you're using a non-standard FormSelect view helper. For starters, your <option> value attribute and text values are reversed and you have no label attributes.
Eg, for
$state->addMultiOption('Pear','PE');
the generated markup should be
<option value="Pear" label="PE">PE</option>
I'd also hazard a guess that there's some JavaScript playing with the DOM due to the opacity style attribute.
Using your code exactly I get:
<select name="mytest" id="mytest">
<option value="Pear" label="PE">PE</option>
<option value="Banana" label="BA" selected="selected">BA</option>
<option value="Orange" label="OR">OR</option>
<option value="Kiwi" label="KI">KI</option>
</select>
this is also with 1.11.10. Are you using custom form classes or anything else that might be affecting it?

cfselect problem

I theory seems to be the answer to the pre populated selectbox issue.
<cfselect name = "regions" query = "getRegions" selected="10" value="id" display="name" ></cfselect>
this is what it outouts
<option value="8">Dumfries & Galloway</option>
<option value="9">Dundee City</option>
<option value="10" selected="selected">East Ayrshire</option>
<option value="11">East Dunbartonshire</option>
but my option 10 is not selected automatically. The html looks ok any reason why?
Thanks,
R.
If you are using Firefox then that is probably the reason, because it keeps form values persistent across page reloads. You can use a different browser, or add something to the query string like ?abc=123.