logo
down
shadow

How to get value from select using javascript


How to get value from select using javascript

By : Jeff Staples
Date : November 24 2020, 03:01 PM
will be helpful for those in need To get selected use $('#group_2 :selected').val();
you are making your code a little more complicated
code :


Share : facebook icon twitter icon
How to use javascript or jQuery to quickly select a preset of multi-select listbox items?

How to use javascript or jQuery to quickly select a preset of multi-select listbox items?


By : dim
Date : March 29 2020, 07:55 AM
I wish did fix the issue. So say my page has a list of indexes '1,3,4,5,9,12' and a multi-select listbox with 12 items in it. , This could do the trick:
code :
<select id="select" multiple="multiple">
    <option value="1">test 1</option>
    <option value="2">test 2</option>
    <option value="3">test 3</option>
    <option value="4">test 4</option>
    <option value="5">test 5</option>
    <option value="6">test 6</option>
    <option value="7">test 7</option>
    <option value="8">test 8</option>
    <option value="9">test 9</option>
    <option value="10">test 10</option>
    <option value="11">test 11</option>
    <option value="12">test 12</option>
</select>
indexes = [1,3,4,5,9,12]
$(document).ready(function(){
    for(i=0; i<indexes.length; i++){
        $('#select option:eq(' + (indexes[i]-1) + ')').attr('selected', 'selected');
    }
});
window.onload = function(){
    var indexes = [1,3,4,5,9,12];
    var options = document.getElementById('select').options;
    for(i=0; i<indexes.length; i++){
        options[indexes[i]-1].selected = true;
    }
}
Javascript: Disable select options in Select 2 based on Select 1

Javascript: Disable select options in Select 2 based on Select 1


By : Vikram
Date : March 29 2020, 07:55 AM
This might help you First of all, you need to bind onchange event. Then you loop over second select options and disabled/enable them based on the selected index in the first select. Note, that you don't even have to compare option values because both selectboxes has the same set of options:
code :
document.querySelector('#startDate').addEventListener('change', function() {
    var endDate = document.querySelector('#endDate');
    for (var i = 0; i < endDate.options.length; i++) {
        endDate.options[i].disabled = i < this.selectedIndex;
    }
});
<select id="startDate">
    <option value="2014-07-11">July. 11th, 2014</option>
    <option value="2014-07-25">July. 25th, 2014</option>
    <option value="2014-08-08">August. 8th, 2014</option>
    <option value="2014-08-22">August. 22th, 2014</option>
    <option value="2014-09-05">September. 5th, 2014</option>
</select>

<select id="endDate">
    <option value="2014-07-11">July. 11th, 2014</option>
    <option value="2014-07-25">July. 25th, 2014</option>
    <option value="2014-08-08">August. 8th, 2014</option>
    <option value="2014-08-22">August. 22th, 2014</option>
    <option value="2014-09-05">September. 5th, 2014</option>
</select>
Click a dynamically created select to select other dynamic content using Javascript/jQuery

Click a dynamically created select to select other dynamic content using Javascript/jQuery


By : Sravan Venkat
Date : March 29 2020, 07:55 AM
wish helps you Solution
Since the Chrome Extension is run in a sandboxed environment, it has unreliable results when trying to interact with objects in the DOM. What I needed to do was inject a script into the page which contained my change() event.
code :
var injectedCode = 
    'function changeSelect(newVal) { '+
        '$("#pageSelect").val(newVal).change();'+
    '}';
var script = document.createElement('script');
script.appendChild(document.createTextNode( injectedCode ));
(document.body || document.head || document.documentElement).appendChild(script);
$("#buttonInExtensionDiv").click(function(){
    function injectCode(code){
        var newScript = document.createElement('script');
        newScript.appendChild(document.createTextNode( code ));
        (document.body || document.head || document.documentElement).appendChild(newScript);
    }
});
How to refresh default display option in select by javascript or jquery if there is more than one select fields?

How to refresh default display option in select by javascript or jquery if there is more than one select fields?


By : AnitaaSky
Date : March 29 2020, 07:55 AM
will be helpful for those in need I've got a problem, I know how to change the selection when I have one select field, but what if there is two of them? , Try this..
$("#select1").val("2");
Select Box Validations when using scanner to scan barcode to select option aps classic javascript

Select Box Validations when using scanner to scan barcode to select option aps classic javascript


By : Francisco
Date : March 29 2020, 07:55 AM
it should still fix some issue I have a select box in a classic ASP page that contains barcode values. Users will access the page on an enterprise device that has a barcode scanner. When the page loads it focuses on the select box, and users will scan a barcode to select an item in the list. , Make the first option value blank, with Scan a barcode as the prompt.
code :
<select name='barcode' id='barcode' onkeypress='validate(event, this);'>
<option value='' selected='selected'>Scan a barcode</option>
<option value='1111'>1111</option>
<option value='2222'>2222</option>
<option value='3333'>3333</option>
<option value='4444'>4444</option>
</select>
<input type='hidden' id='bc_entered' />
<script type="text/javascript">
function validate(evt, elem)
{
    var i;
    var match = false;
    var barcode = document.getElementById('bc_entered');

    var evt = evt || window.event;
    var code = evt.keyCode || evt.which;

    if(code == 13) //scanner should append CR
    {
        for(i=0; i<elem.options.length; i++)
        {
            if(barcode.value == elem.options[i].text)
            {
                match = true;
                break;
            }
        }
        if(match)
        {
            elem.selectedIndex = i;
        }
        else
        {
            elem.selectedIndex = 0;
            alert("Barcode " + barcode.value + " not found!");
        }
    }
    else
    {
        barcode.value += code;  //Append the character to hidden field
    }
}
</script>
Related Posts Related Posts :
  • Make web service not accessible by browser?
  • Select DOM elements within template
  • How to customize angular ui-grid row background color?
  • Binding data in two respective $scope in AngularJS, how?
  • react put some props after import class
  • Variable is distributed among same components
  • switch class in jQuery/JavaScript for active/inactive state
  • How To Track Outbound Clicks Using Javascript
  • How to get total seconds elapsed since the beginning of the month?
  • Protractor: Stale element reference at "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);"
  • Access to an array inside an object
  • Reseting an JavaScript Interval with different value?
  • Learning Angular for the first time - version 2 or 4?
  • Rendering RSS feed (XML) in React with jquery, why do object values parsed from the feed seem empty?
  • Node.js xml2js http.request tag matching
  • applying texture to custom plane geometry in Threejs
  • How do I pass an Event as a function parameter in HTML written inside JavaScript variable?
  • Interface of object parameter with default value and default property
  • Does using try / catch rather than `.catch` observable operator with XHR requests reduce performance?
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org