CheckBox Value

Hi,
What is the best way to get the value of a checkbox by the name of “BatchFailed”?
I tried following codes based on JQuery suggestion but all of them return undefined

$("input[name='x_BatchFailed[]']:checked").val()
----------
$("input[name='x_BatchFailed']:checked").val()
---------
$("input[name='BatchFailed[]']:checked").val()
--------
$("input[name='BatchFailed']:checked").val()
--------
$("input[name='x_BatchFailed[]']").prop( "checked" ) 
----------
$("input[name='x_BatchFailed']").prop( "checked" ) 
---------
$("input[name='BatchFailed[]']").prop( "checked" ) 
--------
$("input[name='BatchFailed']").prop( "checked" )

What is the type of the field? You may post your table schema (CREATE TABLE …) including some records example (INSERT INTO …) so others could comprehend the situation and try straightforward.

You should right click the element in your browser and inspect the HTML to find out the correct CSS selector, see Inspect HTML element and add your own CSS styles.

Hi, thanks. I can find if it is checked or not with the following command:
$(“#x_BatchFailed”).prop(“checked”)but I can not get the proper value.
$(“#x_BatchFailed”).val()
always return ‘1’ if it is checked or uncheckedCREATE TABLE test (
id int(2) NOT NULL AUTO_INCREMENT,
BatchFailed tinyint(1) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;and it is a checkbox in the PHPMaker with Value=1 Lable=Yes and Value=0 Lable No

mishanian wrote:

$(“#x_BatchFailed”).val()
always return ‘1’ if it is checked or unchecked

You may read :checked Selector.

Thanks a lot, it is working with your suggestion as the following command:$(“#x_isFailed:checked”).val()I have a similar question for Radio Button. I will write it in a separate reply

Hi again, to get the radio button “MyRadio” for the following sample table:CREATE TABLE test (
id int(2) NOT NULL AUTO_INCREMENT,
isFailed tinyint(1) DEFAULT NULL,
MyRadio int(1) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;it is user defined with the following value, labels: value:1 label:One , value:2 label: two
when I used

$("#x_MyRadio:checked").val()

it returned undefined. I believe $(“#x_MyRadio:checked”) is a correct JQuery selector.
please correct me.

for your information, this is source code

 <div id="r_MyRadio" class="row">
        <label id="elh_test_MyRadio" class="col-sm-2 col-form-label ew-label">My Radio</label>
        <div class="col-sm-10"><div>
<span id="el_test_MyRadio">
<template id="tp_x_MyRadio">
    <div class="form-check">
        <input type="radio" class="form-check-input" data-table="test" data-field="x_MyRadio" name="x_MyRadio" id="x_MyRadio">
        <label class="form-check-label"></label>
    </div>
</template>
<div id="dsl_x_MyRadio" class="ew-item-list"></div>
<selection-list hidden
    id="x_MyRadio"
    name="x_MyRadio"
    value=""
    data-type="select-one"
    data-template="tp_x_MyRadio"
    data-target="dsl_x_MyRadio"
    data-repeatcolumn="5"
    class="form-control"
    data-table="test"
    data-field="x_MyRadio"
    data-value-separator=", "
    ></selection-list>
<div class="invalid-feedback">Incorrect integer - My Radio</div>
</span>
</div></div>
    </div>

mishanian wrote:

I believe > $(“#x_MyRadio:checked”) > is a correct JQuery selector.

It is incorrect. The “#x_MyRadio” selector only select the first element with that id, you need to select all the radio buttons with “:check” for that field.arbei wrote:

You may read > :checked Selector> .

You may try this in Startup Script of Add/Edit Page:

$('#x_MyRadio').change(function(){
	ew.alert("Selected Radio Button value: " + $(this).attr("value"));
});

If you want to get the selected value, for example in Edit Page, then simply try this in Startup Script, too:ew.alert("Radio Button selected: " + $(‘#x_MyRadio’).val());

I really appreciate your answers:

$('#x_MyRadio').val()

works like a charm.
thanks

arbei wrote:

The “#x_MyRadio” selector only select the first element with that id, you need to select all the radio buttons with “:checked” for that field.