I need a jquery selector that allows me to
find input (select/option) dropdown - where name of SELECT is ACTC and - selected value is ABC
I think it's something like:
myTmpl.find("input[name='ACTC']").val('ABC');
I don't really see the application in what you're trying to do. Why not just get the current value of the select box with the name 'ACTC' and test to see if it's 'ABC'?
var selectBox = $('select[name="ACTC"]');
var selectValue = $(selectBox).val();
if (selectedValue == 'ABC'){
// use the 'selectBox' variable as it references your <select> element
}
else{
// do something else or nothing at all
}
The selector for the <option> tag would be:
$('select[name="ACTC"] option[value="ABC"]');
If you want to see if the option with value "ABC" is selected you could check like so:
// if the following line of code > 0 then the option is selected
$('select[name="ACTC"] option[value="ABC"]:selected').length;
If you actually wanted to mark the specific option as selected you would do this:
$('select[name="ACTC"] option[value="ABC"]').attr({selected:true});
If you just want to find the <select> box with the selected value of "ABC" (mind you this would only be necessary if you had multiple select boxes with the same name):
$('select[name="ACTC"] option[value="ABC"]:selected').closest('select');
This will get the currently selected value from a Select/option that has a class name of 'ACTC' if the value is 'ABC'
$(document).ready(function() {
$("input").click(function() {
if ( $('.ACTC option:selected').val() == 'ABC') {
alert("ABC Selected");
}
else
{
alert("ABC not select");
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With