Radio button multidimensional array
I am working with radio buttons.
<input type="radio" value="1" name="report[1][AP]">
<input type="radio" value="2" name="report[1][AP]">
<input type="radio" value="1" name="report[1][DCI]">
<input type="radio" value="2" name="report[1][DCI]">
<input type="radio" value="1" name="report[2][AP]">
<input type="radio" value="2" name="report[2][AP]">
<input type="radio" value="1" name="report[2][DCI]">
<input type="radio" value="2" name="report[2][DCI]">
If report[1][AP] is checked then report[1][DCI] also should be checked, OR If report[1][DCI] is checked then report[1][AP] also should be checked.
Similarly;
if report[2][AP] is checked then report[2][DCI] also should be checked, OR if report[2][DCI] is checked then report[2][AP] also should be checked.
What should I do?
I am using this:
$('input[type="radio"]').on('click', function(){
var found = $(this).attr('name');
var founds = found.substring(0, found.indexOf(']'))+"]";
$("input[type="+founds+"]").prop('required',true);
});
Error: Syntax error, unrecognized expression: input[type=report_time[1]]
jquery html arrays radio-button
add a comment |
I am working with radio buttons.
<input type="radio" value="1" name="report[1][AP]">
<input type="radio" value="2" name="report[1][AP]">
<input type="radio" value="1" name="report[1][DCI]">
<input type="radio" value="2" name="report[1][DCI]">
<input type="radio" value="1" name="report[2][AP]">
<input type="radio" value="2" name="report[2][AP]">
<input type="radio" value="1" name="report[2][DCI]">
<input type="radio" value="2" name="report[2][DCI]">
If report[1][AP] is checked then report[1][DCI] also should be checked, OR If report[1][DCI] is checked then report[1][AP] also should be checked.
Similarly;
if report[2][AP] is checked then report[2][DCI] also should be checked, OR if report[2][DCI] is checked then report[2][AP] also should be checked.
What should I do?
I am using this:
$('input[type="radio"]').on('click', function(){
var found = $(this).attr('name');
var founds = found.substring(0, found.indexOf(']'))+"]";
$("input[type="+founds+"]").prop('required',true);
});
Error: Syntax error, unrecognized expression: input[type=report_time[1]]
jquery html arrays radio-button
"also should be checked"... means should be "Required". must be checked.
– Shahrukh Raza
Nov 1 '15 at 9:53
add a comment |
I am working with radio buttons.
<input type="radio" value="1" name="report[1][AP]">
<input type="radio" value="2" name="report[1][AP]">
<input type="radio" value="1" name="report[1][DCI]">
<input type="radio" value="2" name="report[1][DCI]">
<input type="radio" value="1" name="report[2][AP]">
<input type="radio" value="2" name="report[2][AP]">
<input type="radio" value="1" name="report[2][DCI]">
<input type="radio" value="2" name="report[2][DCI]">
If report[1][AP] is checked then report[1][DCI] also should be checked, OR If report[1][DCI] is checked then report[1][AP] also should be checked.
Similarly;
if report[2][AP] is checked then report[2][DCI] also should be checked, OR if report[2][DCI] is checked then report[2][AP] also should be checked.
What should I do?
I am using this:
$('input[type="radio"]').on('click', function(){
var found = $(this).attr('name');
var founds = found.substring(0, found.indexOf(']'))+"]";
$("input[type="+founds+"]").prop('required',true);
});
Error: Syntax error, unrecognized expression: input[type=report_time[1]]
jquery html arrays radio-button
I am working with radio buttons.
<input type="radio" value="1" name="report[1][AP]">
<input type="radio" value="2" name="report[1][AP]">
<input type="radio" value="1" name="report[1][DCI]">
<input type="radio" value="2" name="report[1][DCI]">
<input type="radio" value="1" name="report[2][AP]">
<input type="radio" value="2" name="report[2][AP]">
<input type="radio" value="1" name="report[2][DCI]">
<input type="radio" value="2" name="report[2][DCI]">
If report[1][AP] is checked then report[1][DCI] also should be checked, OR If report[1][DCI] is checked then report[1][AP] also should be checked.
Similarly;
if report[2][AP] is checked then report[2][DCI] also should be checked, OR if report[2][DCI] is checked then report[2][AP] also should be checked.
What should I do?
I am using this:
$('input[type="radio"]').on('click', function(){
var found = $(this).attr('name');
var founds = found.substring(0, found.indexOf(']'))+"]";
$("input[type="+founds+"]").prop('required',true);
});
Error: Syntax error, unrecognized expression: input[type=report_time[1]]
jquery html arrays radio-button
jquery html arrays radio-button
edited Nov 20 '18 at 2:54
j08691
166k20189212
166k20189212
asked Nov 1 '15 at 9:52


Shahrukh RazaShahrukh Raza
2819
2819
"also should be checked"... means should be "Required". must be checked.
– Shahrukh Raza
Nov 1 '15 at 9:53
add a comment |
"also should be checked"... means should be "Required". must be checked.
– Shahrukh Raza
Nov 1 '15 at 9:53
"also should be checked"... means should be "Required". must be checked.
– Shahrukh Raza
Nov 1 '15 at 9:53
"also should be checked"... means should be "Required". must be checked.
– Shahrukh Raza
Nov 1 '15 at 9:53
add a comment |
1 Answer
1
active
oldest
votes
Try something like this..
$('input[type="radio"]').on('click', function(){
var namePattern = /([a-z]*)([[0-9]])([[A-Z]*])/i;
var found = $(this).attr('name').match(namePattern);
var required = '[AP]';
if(found[3] === '[AP]') {
required = '[DCI]';
}
var reqButtonName = found[1] + found[2] + required;
var reqButtonWithValue1 = $('[name="' + reqButtonName + '"]')[0];
// $(reqButtonWithValue1).prop('checked', 'checked');
$(reqButtonWithValue1).prop('required', 'required');
});
This will check the radio button [DCI]/[AP] with value=1
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33460952%2fradio-button-multidimensional-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try something like this..
$('input[type="radio"]').on('click', function(){
var namePattern = /([a-z]*)([[0-9]])([[A-Z]*])/i;
var found = $(this).attr('name').match(namePattern);
var required = '[AP]';
if(found[3] === '[AP]') {
required = '[DCI]';
}
var reqButtonName = found[1] + found[2] + required;
var reqButtonWithValue1 = $('[name="' + reqButtonName + '"]')[0];
// $(reqButtonWithValue1).prop('checked', 'checked');
$(reqButtonWithValue1).prop('required', 'required');
});
This will check the radio button [DCI]/[AP] with value=1
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
|
show 4 more comments
Try something like this..
$('input[type="radio"]').on('click', function(){
var namePattern = /([a-z]*)([[0-9]])([[A-Z]*])/i;
var found = $(this).attr('name').match(namePattern);
var required = '[AP]';
if(found[3] === '[AP]') {
required = '[DCI]';
}
var reqButtonName = found[1] + found[2] + required;
var reqButtonWithValue1 = $('[name="' + reqButtonName + '"]')[0];
// $(reqButtonWithValue1).prop('checked', 'checked');
$(reqButtonWithValue1).prop('required', 'required');
});
This will check the radio button [DCI]/[AP] with value=1
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
|
show 4 more comments
Try something like this..
$('input[type="radio"]').on('click', function(){
var namePattern = /([a-z]*)([[0-9]])([[A-Z]*])/i;
var found = $(this).attr('name').match(namePattern);
var required = '[AP]';
if(found[3] === '[AP]') {
required = '[DCI]';
}
var reqButtonName = found[1] + found[2] + required;
var reqButtonWithValue1 = $('[name="' + reqButtonName + '"]')[0];
// $(reqButtonWithValue1).prop('checked', 'checked');
$(reqButtonWithValue1).prop('required', 'required');
});
This will check the radio button [DCI]/[AP] with value=1
Try something like this..
$('input[type="radio"]').on('click', function(){
var namePattern = /([a-z]*)([[0-9]])([[A-Z]*])/i;
var found = $(this).attr('name').match(namePattern);
var required = '[AP]';
if(found[3] === '[AP]') {
required = '[DCI]';
}
var reqButtonName = found[1] + found[2] + required;
var reqButtonWithValue1 = $('[name="' + reqButtonName + '"]')[0];
// $(reqButtonWithValue1).prop('checked', 'checked');
$(reqButtonWithValue1).prop('required', 'required');
});
This will check the radio button [DCI]/[AP] with value=1
edited Nov 2 '15 at 13:25
answered Nov 1 '15 at 10:03
SachinSachin
7871716
7871716
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
|
show 4 more comments
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
should not checked automatically... I want to make other radio buttons required.
– Shahrukh Raza
Nov 1 '15 at 10:06
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
and its only working when i click on [AP].... this is not what I want.
– Shahrukh Raza
Nov 1 '15 at 10:07
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
you just need another function that can handle [DCI] click event.
– Sachin
Nov 1 '15 at 10:08
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
what do you mean by required ? that wasn't your question..
– Sachin
Nov 1 '15 at 10:09
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
I have unified both the click handlers... I am not sure about what you mean by making other radio buttons required
– Sachin
Nov 1 '15 at 10:27
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33460952%2fradio-button-multidimensional-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"also should be checked"... means should be "Required". must be checked.
– Shahrukh Raza
Nov 1 '15 at 9:53