-2

The below is my code but i want to give number for every value like this <option value="1" />vijay

But apple+ should be there because i want to assign some values using jquery thats i want to add + value as we can modify <option value="1" />vijay

but due to my template design i want to give like this <option value="1" value=vijay+/>vijay i dont think it is correct what is the correct format.

<select id="cmbColumn">
    <option value="" />Columns
    <option value="apple+" />apple
    <option value="berry+" />berry
</select>

<select id="cmbSidebar" name="cmbSidebar">
    <option value="" />Sidebars
    <option value="grapes+" />grapes
    <option value="mango+" />mango               
</select>

my main aim is to achieve for example like for all values apple+ and apple and also giving number to the values.

This is my other code but i want to give numbering to values like this but like i above said i also need grapes+ values with them

<select id="cmbsidebar">
    <option value="1" />vijay
    <option value="2"/>1004045

</select>

<select id="combo-014">
    <option value="1" />1003045
    <option value="2" />1004045

</select>
charlietfl
  • 170,828
  • 13
  • 121
  • 150
overflowstack9
  • 345
  • 2
  • 5
  • 18

2 Answers2

1

You can use data attributes to have additional values. Check below example by changing the option!

$(function() {
  $('select').change(function() {
    var $this = $(this).find("option:selected");
    var value = $this.val();
    var num = $this.attr('data-num');
    alert("Value: " + value + "\nNumber: " + num);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="cmbColumn">
  <option data-num="1" value="">Columns</option>
  <option data-num="2" value="apple+">apple</option>
  <option data-num="3" value="berry+">berry</option>
</select>

<select id="cmbSidebar" name="cmbSidebar">
  <option data-num="1" value="">Sidebars</option>
  <option data-num="2" value="grapes+">grapes</option>
  <option data-num="3" value="mango+">mango</option>
</select>
Pugazh
  • 9,453
  • 5
  • 33
  • 54
0

You can use data attributes together with the value attribute like this:

document.getElementById("options").onchange = function(e) {
  // Get the selected option element
  var target = e.explicitOriginalTarget;
  
  // Get its value
  console.info(target.getAttribute("value"));
  
  // Get its data-value
  console.info(target.getAttribute("data-value"));
}
<select id="options">
  <option value="">Sidebars</option>
  <option value="1" data-value="grapes+">grapes</option>
  <option value="2" data-value="mango+">mango</option>
</select>
xxxmatko
  • 4,017
  • 2
  • 17
  • 24