Can an Option in a Select tag carry multiple values?
One way to do this, first one an array, 2nd an object:
<select name="">
<option value='{"num_sequence":[0,1,2,3]}'>Option one</option>
<option value='{"foo":"bar","one":"two"}'>Option two</option>
</select>
Can I pass multiple values in the option tag?
You cannot have Multiple values in an Option Tag.
If the Name of the Front and Back-Image only differ by the Page-number, you can use this code:
function selectFlyer(name){ selectFront(name+"pag1.png"); selectBack(name+"pag2.png");}function selectFront(imgSrc) { loadImage(imgSrc); var Dim_Slice = document.querySelectorAll(".slice"); for (var i = 0; i < Dim_Slice.length; i++) { Dim_Slice[i].style.backgroundImage = "url(" + imgSrc + ")"; }}
function selectBack(imgSrc) { loadImage(imgSrc); var Dim_Sliceb = document.querySelectorAll(".sliceb"); for (var i = 0; i < Dim_Sliceb.length; i++) { Dim_Sliceb[i].style.backgroundImage = "url(" + imgSrc + ")"; }}
<form name="Pictures"> <select name="dropPic" onchange="selectFlyer(this.value)"> <option value="Flyer1">Flyer 1</option> <option value="Flyer2">Flyer 2</option> <option value="Flyer3">Flyer 3</option> </select></form>
how to give multiple values to a select-option tag?
I think this possible with JS help, with write Events for selected option and sent list arguments for example. HTML don't understand TWICE value in the one element.
Another way it's for example in the value do something like this
echo '<option value="'.$row['driver_name'].'_'.$row['mob_no'].'">'.$row['driver_name'].'</option>';
And on the server parse result for example:
$two_values = explode('_', $_POST['driver_name']);
//$two_values will be Array with 2 items
Can selected option tag can carry multiple values using django?
In HTML you cannot have multiple values on option elements.
As the spec says:
The value content attribute provides a value for element. The value of an option element is the value of the value content attribute, if there is one, or, if there is not, the value of the element’s text IDL attribute (which may be the empty string).
If we can set multiple values that would lead to ambiguous behaviour.
You can try to create a string which contains perfume.id
and perfume.addate
joined by some special character and use this string as a value. Then you will just split it and will have both id
and addate
. However, you will need to carefully pick a special character, that would not be included in any the id
or addate
value, because your splitting will not work correctly otherwise.
option in SELECT tag with multiple values?
The value is always one, but if you serialize a JSON object, as you seem you are trying to do, inside the value
attribute, you can retrieve it later using JSON.parse()
, like so:
Javascript (using jQuery for speed, you can do vanilla)
jQuery(document).ready(function($){
$('select').on('change',function(){
var val = JSON.parse( $(this).val() );
console.log(val);
});
});
Warning: Your serialized object is not a valid JSON format, you should use double quotes instead of single ones.
Working example
Pass Multiple Values In HTML Option Tag Via PHP
I can see one way of doing it:
Add extra data to your post, separated by a known delimiter.
So, your input field would change from this:
<option value-1="music" value-2="news">News Updates</option>
Into this:
<select name="sec-cat">
<option value="music_news" >News Updates</option>
And on the server you can get the values like this:
$catRetVal = explode ('_',$POST['sec-cat']);
echo $catRetVal[0];
echo $catRetVal[1];
Is this what you are trying to do?
referencing multiple values inside an option element
I think you are looking for the attributes property:
var sel = document.getElementById('selectList');
selValue1 = sel.options[sel.selectedIndex].attributes.value1.value;
Here is a jsFiddle demonstrating how to extract these values.
Related Topics
What's the Proper Value For a Checked Attribute of an HTML Checkbox
Minimum and Maximum Value of Z-Index
Do You Put Schema Microdata Meta Tags in the HTML Body
Uri Starting With Two Slashes ... How Do They Behave
Absolute Urls Omitting the Protocol (Scheme) in Order to Preserve the One of the Current Page
Using Flex Order Property to Re-Arrange Items For Desktop and Mobile Views
Css: Control Space Between Bullet and ≪Li≫
Is Either Get or Post More Secure Than the Other
With Css, Use "..." For Overflowed Block of Multi-Lines
Is It Wrong to Change a Block Element to Inline With CSS If It Contains Another Block Element
How to Use the "Required" Attribute With a "Radio" Input Field
Are Class Names in CSS Selectors Case Sensitive
How to Get Centered Content Using Twitter Bootstrap