HTML drop down list output multiline - html

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

Related

Dispay text and not value HTML datalist

I use this code to make a dropdown with an input to search and list items from an array ..
<input list="homebox_id" formControlName="homebox_id"/>
<datalist id="homebox_id"
[ngClass]="{invalid: invalidInputs}">
<option *ngFor="let homebox of homeboxs" value="{{homebox.homebox_id}}">{{homebox.serial_number}}</option>
</datalist>
all is good except this code does not display serial_number but it displays the value i want to send "homebox_id"...What can i do to display the text i want?

HTML form select field adds space above element when options have a value other than ""

I have an html form element that is a <select> and whenever I add options and specify a value for the options, it adds a space/margin above the form select field. If I modify the code and set all options to value="" then the space/margin goes away.
<select id="authorizenet_cc_type" name="payment[cc_type]" class="required-entry validate-cc-type-select">
<option value="">--Please Select--</option>
<option value="">American Express</option>
<option value="">Visa</option>
<option value="">MasterCard</option>
<option value="">Discover</option>
</select>
The code above gives me:
But when I add values to each option, I get the following result:
How can I fix this to have the values set, but eliminate the space that it creates?
EDIT: It seems like it might be some sort of JavaScript code or something. When the page first loads it's OK for about 1 second, then once the placeholder info loads into all the other input fields, the space pops up.

Option value in ISML

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.

How to input text in HTML Select Tag?

I want to make input option in select tag so user can choose between options or insert different value.
Is it possible?
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
**<insert user value>**
</select>
HTML solution with "list" attribute:
<input type="text" name="city" list="citynames">
<datalist id="citynames">
<option value="Boston">
<option value="Cambridge">
</datalist>
You will have to use javascript to get the additional value. Check this post for some example code:
Jquery dynamically update "other" option in select
Select elements can't contain anything other than option or optgroup elements. Here's a ref to the spec http://www.w3.org/TR/html5/forms.html#the-select-element
You may be better off adding an option for "other" in your dropdown and then using JS to detect for that choice to dynamically show an input (below the dropdown) for a custom value.
Position an input box over the select box and remove the border of the input box. Make the length of the input box shorter than the select box so that the select box may still be used at its end.
Use the oninput event to detect input being entered in the input box. On each keystroke check for a continuing match in the select box. When a match no longer exists there is no further need for the select box.
The server will expect to receive both the text box input, if any, and the select box input, if any, and should use the select value if provided otherwise the input value if provided.

How do I create two different textareas with muliple items clickable to move between the two textareas?

I have been looking around for a couple days now and haven't found the answer. I did see this: jQuery - Copy / move text from select list to textarea which I already did, but then the problem is what if the after copying the selected drop down item to go into the text area you change your mind and want to send it back or get rid of it?
I'm not sure if it's best to use two tags or if I should use textareas. This is what I have for the field on the left:
<select size="10" name="options" variable="#available options" multiple="multiple">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
And then when options are selected and the button is clicked they are added to a list and my textarea on the right reflects that list. Should I also make the area on the right a selectable drop down similar to the one with all my options? If I do that, then how to I get it to reflect only the options I have clicked?
Sorry if this doesn't make sense. It's my first time posting here and I'm not a programmer (but learning). Thanks in advance!