Get selected radio item true OR false [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I was trying to get weather the radio button is selected or not by Jquery, but it always returns me false even if the id is checked
So far i tried this:
$("#opt_34709").prop('checked');
This is my HTML:
<input type="radio" id="opt_34709" value="119740" name="options[34709][]">

In this little fiddle I provided two more radio button options. Each time you click on one of the radio buttons you will be shown the value of the first radio button. I hope this helps.
$(':radio').click(function(){
console.log($("#opt_34709").prop('checked'))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" id="opt_34709" value="119740" name="options[34709][]">09<br>
<input type="radio" id="opt_34710" value="119741" name="options[34709][]">10<br>
<input type="radio" id="opt_34711" value="119742" name="options[34709][]">11

Related

How can I get the value of the checkbox in PHP? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I am trying to make a registration page for my website but when I run it; it gives error. What am I doing wrong?
<?php
//Form values
$name_value=$_POST['Name_input'];
$Username_value=$_POST['Username_input'];
$DOB_value=$_POST['DOB_input'];
$Password_value=$_POST['Password_input'];
$Phone_number_value=$_POST['Phone_number_input'];
$Python_checkbox_value=$_POST['Python_checkbox'];
$Java_checkbox_value=$_POST['Java_checkbox'];
$C_sharp_checkbox_value=$_POST['C#_checkbox'];
$HTML_checkbox_value=$_POST['HTML_checkbox'];
$Cpp_checkbox_value=$_POST['C++_checkbox'];
$R_checkbox_value=$_POST['R_checkbox'];
$swift_checkbox_value=$_POST['swift_checkbox'];
$kotlin_checkbox_value=$_POST['kotlin_checkbox'];
$JS_checkbox_value=$_POST['JS_checkbox'];
Take a look at this code :
<form method="GET">
<input type="checkbox" value="value" name="name">checkbox label</input>
<input type="submit">
</form>
<?php
if (isset($_GET["name"]))
{
echo $_GET["name"];
}
?>
As you can see when I submit the form without checking, the parameter in URI is empty because the checkbox isn't defined (I used GET method)
But when I check it, you can see the parameter is name=value

KeyPad numbers in javascript on click event [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have this created a page with numbers and textbox in top of it as you see in the picture
The element id of the textbox is t1
the question is , what's the code I should write on click event to make the numbers written on the textbox .
For example , when I click (1) three times , the textbox should have the value of ( 111 )
any advices ?
JavaScript:
function display(val)
{
document.getElementById("t1").value+=val
}
HTML:
<input type="button" value="1" onclick="display('1')"/>
<input type="button" value="2" onclick="display('2')"/>
<input type="button" value="3" onclick="display('3')"/>
And so on..
display() will call the function to display the value what has been clicked.

$(this).prop('checked') not working for checking checkbox for Jquery [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have checkboxes with HTML:
<input type="checkbox" class="selectMakeup" name="needsPartNumber">
There can be a lot of checkboxes with the same class. I want to loop through each of the checked checkboxes.
$('.selectMakeup').each(function() {
console.log($(this).html())
console.log($(this).prop('checked'))
if ($(this).prop('checked')) {
//Do Stuff
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="selectMakeup" name="needsPartNumber">
console.log($(this).html())
returns
<input type="checkbox" name="needsPartNumber">
But console.log($(this).prop('checked')) returns undefined.
This should return all checked checkboxes with a given class
$('.selectMakeup:checked').each(function() {});
If you want to check if a checkbox/radio option is "checked", you can use .is():
$('.selectMakeup').each(function(){
console.log($(this).is(":checked"));
if($(this).is(':checked')){
// Do something
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="selectMakeup" name="needsPartNumber">
-- Edit --
As the comments are suggesting, $(this).prop("checked") should return true or false, unless you're targeting an element via $(this) that isn't a radio/checkbox.

Disable only checked checkbox in a table [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
So I have been working on a system and I can't seem to solve how to disable only the checked checkbox inside a table. I have been looking everywhere but no answer. Would you mind helping me?
For example, I have three rows in my table and whenever I check a row all three checkbox will be disabled. What I want is, I only want the checked checkbox in the row to be disabled and the other two should be enabled.
You can add an event handler to your checkboxes like this:
var disable = function(event){
$(event.target).prop("disabled", true);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" onchange="disable(event)" />
<input type="checkbox" onchange="disable(event)" />
<input type="checkbox" onchange="disable(event)" />

Displaying a list of checkboxes and text field after radio is checked [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a form that has the following fields:
<div>
<input name="department" type="radio" value="1" required >
<label for="Orchestra">Orchestra</label>
</div>
<div>
<input name="department" type="radio" value="2">
<label for="Band">Band</label>
</div>
What I would like to be able to do is to display different checkboxes and comment text fields ONLY if the radio button for "Band" is checked. If this is unchecked then, the checkboxes should go away. I found several examples online, but for some reason I can't get them to work. The problem must be that I do not know Javascript or JQuery :( Any help would be appreciated.
I have tried different things that I have seen on stackOverflow and other websites, but I am so clueless about Javascript that I can't get it to work.
I've created a commented fiddle to help you accomplish what you ask, but also clue you in on what's actually going on. I recommend really diving into JavaScript/JQuery with the many resources available online, but for now, I hope my comments will help get you started.
The main takeaway here, is we use JavaScript to "listen" to whether or not the input in question is selected, not selected—based on that value, we can dictate what our view will look like—in this case, hiding or showing element(s).
JS
$(function () {
// Create selectors for relevant DOM elements
var $Department = $('input[name="department"]');
var $BandSelected = $('#BandSelected');
// Create a function that you pass
// the value of the input element in question.
// Return TRUE/FALSE based on equality to 2,
// the `value` associated with the 'Band' input
function isBandsSelected(val) {
return val == 2;
}
// Attach an event listener on `click' of inputs
$Department.click(function () {
// Assign a variable to the function that determines if the input
// we click on is 'Band' (has a value of 2)
var showBand = isBandsSelected($(this).val());
// If `showBand` returns TRUE, show our `BandSelected` div
if (showBand) {
$BandSelected.show();
// If `showBand` returns FALSE, show our `BandSelected` div
} else {
$BandSelected.hide();
}
});
});
Markup
<div>
<input name="department" type="radio" value="1" required>
<label for="Orchestra">Orchestra</label>
</div>
<div>
<input name="department" type="radio" value="2">
<label for="Band">Band</label>
</div>
<div id="BandSelected" class="hidden">
Band is selected
</div>
Demo Fiddle: http://jsfiddle.net/4x1ybqyv/

Categories