How to split words from a dropdown select and insert it into another dropdown select

Related searches

How do i split words from a select dropdown and send it to another dropdown

Example

<select class="form-control" name="Studentabsent[courseid]" id="Studentabsent_courseid">
  <option value="">SelectCourse</option>
  <option value="20182019">20182019</option>
  <option value="20202021">20202021</option>
</select>

and send it to another select dropdown

<select class="form-control" name="year" id="year">
  <option value="">SelectCourse</option>
  <option value="2018">2018</option>
  <option value="2019">2019</option>
  <option value="2020">2020</option>
  <option value="2021">2021</option>
</select>

Appreciate the help. Thanks

You can use map() to generate the list of the year from the existing select element. Then use each() to create the options dynamically like the following way:

var list = $('#Studentabsent_courseid option').not(':first').map(function(i, o){
  return o.value.match(/.{1,4}/g);
}).get();

$.each(list, function (i, item) {
  $('#year').append($('<option>', { 
      value: item,
      text : item 
  }));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="form-control" name="Studentabsent[courseid]" id="Studentabsent_courseid">
  <option value="">SelectCourse</option>
  <option value="20182019">20182019</option>
  <option value="20202021">20202021</option>
</select>

<select class="form-control" name="year" id="year">
  <option value="">SelectCourse</option>
</select>

Dependent Drop-Down Lists in Excel with Multiple Words & Spaces , Excel dynamic data validation many words and spaces. This is an There are three column headers that we want to use as the first drop down list. To add the (Here is a link to other INDEX MATCH guides.) When you hit Using the same technique, there is also an option to display the list in separate cells. Create the first� If you haven't enabled the Developer tab yet on Word, follow these steps: Open Word 2013. Click the File tab. Select Options > Customize Ribbon. Under Customize the Ribbon, click Main Tabs. In the list, select the Developer check box, and then click OK. You can use the images below as a reference for the drop-down list for the phone number and

Use loop inside first drop down with the help of RegEx split your 1st drop down value and generate markup for next drop down and append that markup.

var html = '';
html += '<option value="">SelectCourse</option>';
$('#Studentabsent_courseid option').not(':first').each(function(index, element) {
  var str = ($(this).val());
  var spl = str.match(/.{4}/g);
  html += "<option>" + spl[0] + "</option>"
  html += "<option>" + spl[1] + "</option>"

});
$('#new').html(html);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<select class="form-control" name="Studentabsent[courseid]" id="Studentabsent_courseid">
  <option value="">SelectCourse</option>
  <option value="20182019">20182019</option>
  <option value="20202021">20202021</option>
</select>

<select id='new'>

</select>

How to Select Values from a 2nd Drop-Down List in Excel, In this lesson, I show you how to use the INDIRECT Function in Excel to create a unique set of Duration: 6:23 Posted: Nov 25, 2010 Go to the cell where you want the second dropdown list, cell G5. Go to Data Validation, select List, and in Source, paste into the Data Validation list. Click OK and you will see that the second dropdown list changes according to the chosen option for the first dropdown.

You can do it this way with jQuery.

$( document ).ready(function() {
  var list = [];
    $("#Studentabsent_courseid option").each(function()
    {
        list.push($(this).val());
    });
    $("#Studentabsent_courseid").empty();
    $("#Studentabsent_courseid").append('<option value="">SelectCourse</option>');

    for(let index of list)
      if(index.length > 4){
        $("#Studentabsent_courseid").append('<option value="'+ index.substring(0, 4) +'">'+ index.substring(0, 4) +'</option><option value="'+ index.substring(4, index.lenght) +'">'+ index.substring(4, index.lenght) +'</option>');

          
      }
    
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="form-control" name="Studentabsent[courseid]" id="Studentabsent_courseid">
<option value="">SelectCourse</option>
<option value="20182019">20182019</option>
<option value="20202021">20202021</option>
</select>

How to Make a Drop-Down List Change Depending on Selection in , This selection can further influence the values in another list by presenting in the name to help identify separate words, such as "ProductCategories," but you� If you have a data validation drop down list with large values, you need to scroll down in the list just for finding the proper one, or type the whole word into the list box directly. If there is method for allowing to auto complete when typing the first letter in the drop down list, everything will become easier.

A simple code to do same job, with pure javascript

function createNewDropDown(ele)
 {    
    var selectedValue = ele.options[ele.selectedIndex].value;
    var midSep = selectedValue.length/2
    var firstValue = selectedValue.slice(0, 4);
    var secondValue = selectedValue.slice(4, 8);

    var sel = document.getElementById("year");

    var opt = document.createElement("option");
    opt.value = firstValue;
    opt.text = firstValue;

    sel.add(opt, null);

    var opt = document.createElement("option");
    opt.value = secondValue;
    opt.text = secondValue;
    sel.add(opt, null);
 }
<html>
    <head>

    </head>

    <body>
            <select class="form-control" name="Studentabsent[courseid]" id="Studentabsent_courseid" onchange="createNewDropDown(this);">
                <option value="">SelectCourse</option>
                <option value="20182019">20182019</option>
                <option value="20202021">20202021</option>
            </select>
            <select id='year' name='year'>
                <option>Select Year</option>
            </select>
    </body>

</html>

How to make a dependent (cascading) drop-down list in Excel, First off, type the entries you want to appear in the drop-down lists, each list in a separate column. The items to appear in the first drop-down list must be one- word In the same or in another spreadsheet, select a cell or several cells in select all of the entries and press Ctrl + T or click Insert tab > Table. How do i insert a multiple selection dropdown list into my document? I have already inserted the listbox, and changed the multi-select to 2, but i have no idea what code to use. I just want the user to be able to select 1 or all options that i listed when completing the form.

Select Drop Down Item and use VLOOKUP to Return Multiple , To store the items in a table, use the Insert > Table ribbon icon. In order to create our drop-down list based on the ItemNum column of the tbl_items table, we'll I created another drop down with the three customer types. On a separate note, I realize that I would have to create a vlookup for the other� Let’s see how to achieve it. 1. First, have a check that if you can find Developer tab in your Word. If not, click File > Options, and switch to Customize Ribbon pane in Word Options. 2. Check Developer in the list of Main Tabs (under Customize the Ribbon) to enable it, and click OK to confirm the change. 3.

Then select cells where you want to insert the drop down list, and click Data > Data Validation > Data Validation, see screenshot: 3 . In the Data Validation dialog box, under the Settings tab, choose List from the Allow drop down, and then click button to select the Name list which you want to use as drop down values in the Source text box.

Now, select the cell into which you want to add a drop-down list and click the “Data” tab. In the Data Tools section of the Data tab, click the “Data Validation” button. The Data Validation dialog box displays. On the Settings tab, select “List” from the Allow drop-down list (see, drop-down lists are everywhere!).

Comments
  • So,you want to split the text 20182019 into 2018 and 2019 and these should be generated as an option in second dropdown,am i right? .if so,will there any seperator like space,"," for example: "2018 2019"
  • yes you are right i want to split the 20182019 and send it to another select dropdown