Option value in ISML - html

I have a dropdown list (values populated from an object) from which the value selected goes on to the next page. However if that value is selected then another property of that object should go on to the next page.
My current code is:
<select name="ElementName" class="dropdown"
id="ElementsDropDownList">
<isloop iterator="ELEMENTS">
<option value="#ELEMENTS:ElementName#"><isprint
value="#ELEMENTS:ElementLabel#">
</option>
</isloop>
</select>
I want something like :
<select name="ElementName" class="dropdown"
id="ElementsDropDownList">
<isloop iterator="ELEMENTS">
<option value="#ELEMENTS:ElementName#"><isprint
value="#ELEMENTS:ElementLabel#">
</option>
<input type="Hidden" name="extraField" id="extraFieldUUID" value="<isprint
value="#ELEMENTS:ElementValue#">">
</isloop>
</select>
Here input field inside the loop is not working.

You can't have an input element inside of a select element. It would have to be separate:
<select name="ElementName" class="dropdown" id="ElementsDropDownList">
<isloop iterator="ELEMENTS">
<option value="#ELEMENTS:ElementName#">
<isprint value="#ELEMENTS:ElementLabel#">
</option>
</isloop>
</select>
<input type="Hidden" name="extraField" id="extraFieldUUID" value="<isprint value="#ELEMENTS:ElementValue#">">
However, clearly this won't work in your case because this is outside the loop. You'd need another loop, which means every ElementValue value would be included in the form. That's... no good.
It sounds like what you're trying to achieve is to have a select with two values. It doesn't really do that, pretty much by design. I can think of two options at the moment:
Include a hidden input outside the select element as shown above, but don't set a value for it. Include the list of possible values in JavaScript (as a hash table of some sort, most likely, using the ElementName as the key). Then attach an event handler to the select element's change event which sets the hidden input value based on the newly selected value.
Or, include both values in the select as delimited strings and parse them back out to separate values on the receiving page. Maybe something like:
(I'm completely guessing on the syntax, since I don't know anything about the templating tool you're using.) Then the code on the receiving page would receive some delimited string, something like:
"SomeElement|123"
That code would then need to parse that string into its two component values.

Related

How to change the value in the case of multiple options?

I'm developing a web application using Angular 6. I used the library bootstrap-select to implement a combo-box (with additional possibilities to customize). I have a problem: when I set the multiple attribute, graphically the behavior is right (all the selected strings appear inside the input box, together). The problem is that the value connected with my ngModel (used to get the data with 2-way binding) it's always only one (and always corresponds to the first value displayed inside the box, although there are other values in it!). This is the code:
<select
class="form-control selectpicker show-tick"
data-width="200px"
multiple
title="my_title"
name = "name"
[(ngModel)] = "value"
(ngModelChange) = "onChange($event)"
>
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="2">Value 3</option>
</select>
This is the result (graphically it's exactly as I would like):
But, as you can see, with each click to add a new value, the value object is always and only associated with 1 (because Value 1 is the first in the list and doesn't seem to matter that the other two values are present). The console log (object value):
How can I solve this problem?
The problem is that you are using a multi select version for jquery. You could do some tricks to make it work, but it will not be quite elegant
Also why use jquery in angular? You always have to try to avoid it
Angular handles the bindings in another way.
I recommend you use this library ng-select
Demo

HTML drop down list output multiline

Can any one tell me how I can get the output of a dropdown to be more than one line?
I have an array that has a list of names and against each name a list of there children for example
I want users to be able to through the drop down list select a name and then it displays a list of there children
<form name="form" onsubmit="CheckForm()">
<select name="myOptions" onchange="document.form.showValue.value=this.value">
<option value="">Select a link</option>
<option value="Link1","link2">Description1</option>
<option value="Link2">Description3</option>
<option value="Link3">Description3</option>
<option value="Link4">Description4</option>
</select>
<input type="text" name="showValue">
</form>
I wanted to give more of an example of what I am after. So I have the following lists :
Cars = Ford,Dodge,Fiat
Fruits = Apple Banana, Orange
Colours = red, orange, green
I want a drop down list from which i can pick "cars","fruits","Colours". When one is picked in the drop down the results appear as a list in a right hand pane.
So i am not looking for multiply levels of drop-down lists, just a single dropdown, but where in the HTML the value is a single word, i want the value to be a list of words.
You should probably change your input to a textarea as text inputs are inherently 1 line. Also your option values have to be a single value, so you can do something like the following where I've put your Link1 and Link2 in the value for Description 1 and separated them with
Line Feed and 
 Carriage Return in order to put them on different lines in the text area.
Of course you could also use a value like value="Link1,Link2 and use the replace method in javascript to swap out the comma for the line feed and carriage return if you wish.
select,
textarea {
vertical-align:top;
}
<form name="form" onsubmit="CheckForm()">
<select name="myOptions" onchange="document.form.showValue.value=this.value;">
<option value="">Select a link</option>
<option value="Link1
link2">Description1</option>
<option value="Link2">Description3</option>
<option value="Link3">Description3</option>
<option value="Link4">Description4</option>
</select>
<textarea name="showValue"></textarea>
</form>
Or if I misunderstood and you just want a comma separated list of words to appear in your text input without them being on different lines, then just alter your original code, and change that first option to:
<option value="Link1,link2">Description1</option>
You could use a dropdown in a dropdown in bootstrap.
here is a link to a post where the author does the same thing.
It's basicly a list in a list, you no longer use select options.
Make sure you have bootstrap imported in your HTML and it should work.
To get the value of the dropdown, simply use Jquery to go through each <li> and check for the selected one.
Hopes it helps !
Nic

Knockout binding with multiple values for each option in select

In a form I have a select box with several options, each representing a report with various variables which influence the rest of the form. Some reports require a start date, others an end date, some require both. I have bound the requirements for each of the reports to the option-elements like this:
<select data-bind="value: ReportId">
<option value="ID" data-hasStartDate="BOOL" data-hasEndDate="BOOL">Report name</option>
</select>
<input data-bind="visible: hasStartDate" />
<input data-bind="visible: hasEndDate" />
with ID being the id of the report and BOOL being either true or false. I use knockout to data-bind the value of the select-box to the reportId. But I could not figure out how to bind the hasStartDate and hasEndDate-values to a Knockout observable in order to show the appropriate form elements.
Even with custom bindings, I needed a normal jQuery onChange-event in order to apply the values to the Knockout-values hasStartDate and hasEndDate. Is it possible to do it entirely with Knockout itself?
Have you tried using the options binding for select boxes?
You also can't bind knockout using data-whatever="some value". You always use data-bind, like so: data-bind="bindingtype: value".
Edit:
That being said... If you want to get the data from a selected option in a <select> element, I would use the following jQuery:
$("select").on('change', function() {
var selectedData = $(this).find(":selected").data("stuff");
});
You can then use selectedData and apply this to a knockout view model.
Working example in a fiddle: http://jsfiddle.net/RZq6Q/4/

Auto-append items from a select list

I have a list of different items within a select multiple list and I want to auto-append to a form that a user submits.
HTML of category multiple select list:
<select name="category[]" size="4" multiple="multiple" id="group">
<option value='7'>Faculty</option>
<option value='8'>Staff</option>
<option value='6'>Students</option>
</select>
I want to do something like:
<input type="hidden" name="category[7,8]" />
This will automatically assign the submission to the appropriate selected list items from within category[], without them ever seeing it.
This is stored within a database, so I need to accomplish it this way.
I know this does not work, but this should give you an idea of what I am trying to do.
A successful multiple-select control just gets submitted as having multiple values. E.g., if you selected "Faculty" and "Staff" in your list, what gets submitted is something like:
category[]=7&category[]=8
You can replicate this (at least in Firefox, haven't tested elsewhere) with two hidden inputs:
<input name="category[]" value="7" type="hidden"/>
<input name="category[]" value="8" type="hidden"/>
I believe this could be accomplished using a Javascript library (such as jQuery) to handle the change on the Selections and append/update the items in your hidden field. You could then also use Ajax to update your database with the selection when necessary.
Your specific requirements might not allow for the above though. Some additional information would be helpful for those viewing such as what backend you're using (php, asp.net, or if it is just static html) and if you are currently using javascript (or a library) to assist you in any other tasks.
I'll try to check back on updates to see if I can be of more specific help. (Note: I think I'm too low of reputation to be able to post this as a comment at the moment so had to do an answer instead.)

how to submit a form without losing values already selected at the same form

I am using jstl with dropdown lists.
When i click submit button i success the specification but values int dropdownlists are reinitialized.
So I want to submit form without loosing the values already selected in the form because I need to stay always at the same level in the form.To be more clear, user choose a value from ddl and click edit button to show other options and fill them at the same form without loosing what he has selected.
I have tried to deal like that...
<form action="myjsp.jsp" method="post">
<input type="Submit" value="Edit">
...but it doesn't work.
Thank you for your help.
You need to preset the inputs with the request parameter values. You can access parameter values in EL by ${param.name}. Basically:
<input type="text" name="foo" value="${param.foo}">
Note that this is XSS sensitive. You always need to sanitize the user inputs. You can use the JSTL functions taglib for this.
<input type="text" name="foo" value="${fn:escapeXml(param.foo)}">
In case of dropdowns rendered by HTML <select> element, it's a bit trickier. You need to set the selected attribute of the HTML <option> element in question. You can make use of the ternary operator in EL to print the selected attribute whenever the option value matches the request parameter value.
Basic example:
<select name="foo">
<c:forEach items="${options}" var="option">
<option ${param.foo == option ? 'selected' : ''}>${option}</option>
</c:forEach>
</select>