logo
down
shadow

Do something if element equals value and is checked


Do something if element equals value and is checked

By : TheKoceru
Date : November 22 2020, 04:01 AM
To fix the issue you can do You're setting the value, not selecting. Try this in your if statement instead:
code :
if($("input.delivery_radio_option[value=49]").is(":checked")) {...}


Share : facebook icon twitter icon
Which way to test if an element is checked is better? .is(':checked') or .prop('checked')

Which way to test if an element is checked is better? .is(':checked') or .prop('checked')


By : user3183287
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , They both end up checking the same thing.
If you're using 1.6.0 or higher, prop('checked') is the most direct jQuery way. jQuery doesn't have to parse and process a selector to figure out what to do.[Note below]
code :
if (x[0].checked) { /* ... */ }
if (x[0] && x[0].checked) { /* ... */ }
Add checked to element if its attribute value equals to given string

Add checked to element if its attribute value equals to given string


By : user2571133
Date : March 29 2020, 07:55 AM
will be helpful for those in need , You don't need an if.
code :
$("input[data-custom='Something1']").attr( 'checked', true );
Hide if box is not checked, show if box is checked and dropdown value equals "Other"

Hide if box is not checked, show if box is checked and dropdown value equals "Other"


By : cyberartech
Date : March 29 2020, 07:55 AM
wish helps you Remove $('#otherBox').show();, and add the two lines of code commented below:
code :
$('#honor').change(function() {
  if (!this.checked) {
    $('#location_dropdown').hide();
    $('.form label').hide();
    $('#otherBox').hide(); //ADD THIS
  } else {
    $('#location_dropdown').show();
    $('.form label').show();
    $('#otherBox').toggle($('#location_dropdown').val() === 'Other');  //ADD THIS
  }
});
// hide otherBox
$('#otherBox').hide();

// show OtherBox if other selected
$('#location_dropdown').change(function() {
  $('#otherBox').toggle(this.value == 'Other');
});

$('#honor').change(function() {
  if (!this.checked) {
    $('#location_dropdown').hide();
    $('.form label').hide();
    $('#otherBox').hide();
  } else {
    $('#location_dropdown').show();
    $('.form label').show();
    $('#otherBox').toggle($('#location_dropdown').val() === 'Other');
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<input name="honor" id="honor" checked="checked" type="checkbox"><label for="tribute_show_honor_fieldsname">Check for yes</label>

<div class="form">


  <label for="location_dropdown"> Location: </label>


</div>

<select name="location_dropdown" selected="selected" id="location_dropdown" size="1">
  <option value="Chicago Center">Chicago Center</option>
  <option value="Columbia">Columbia</option>
  <option value="Lower Manhattan">Lower Manhattan Hospital</option>
  <option  value="Other">Other</option>
</select>
<br />
<input name="otherBox" id="otherBox" value="" maxlength="255" type="text">
checkbox value checked if its value equals to 1

checkbox value checked if its value equals to 1


By : xtrafrancyz
Date : March 29 2020, 07:55 AM
may help you . You were pretty close, but checked attribute is for JS object, not Jquery. For JQuery you set it's attribute "checked" to checked:
code :
$('.preference').each(function(e){
    if($(this).val() == 1){
        $(this).attr("checked", "checked");
    }
});
DOM does not show element.input.checked when checkbox checked with ng-checked

DOM does not show element.input.checked when checkbox checked with ng-checked


By : superspades
Date : March 29 2020, 07:55 AM
To fix the issue you can do I use ng-checked to check a checkbox by default when a modal loads and meets a certain condition. However, when I do if ( item.checked) on that item, it will return false. , Only use ng-model and value instead:
Related Posts Related Posts :
  • function not called after a change event
  • How to set a PHP session value as selected onclick on a drop down list
  • scrollIntoView does not include border
  • Javascript number comparison not correct
  • how to fix google map center location in vue js
  • Replace integer in a for loop with string
  • Replace nested JavaScript Object data item with dynamically created path?
  • Cannot remove item from shopping cart in React Redux reducer
  • How to import all images from a folder in ReactJS?
  • How to enforce Webpack 4 to detect and recompile only files that were changed
  • How to use arrow functions with main class 'this' properties?
  • Dynamically decide which Fetch response method to use
  • SVGRenderer with OrbitControls shows two SVG elements on opposite sides
  • JS nesting problem, variable comes back unidentified any way
  • An Alternative to <script> tag if resource don't get loaded
  • Javascript for loop behaviour in arrays
  • How to display two web content on same browser alternatively on click without reloading it?
  • How to call function inside the inner.html
  • React progress bar with each click
  • Copy text to clipboard from hidden input is not working in jQuery
  • How to populate all the array values to a single index in javascript
  • Checkbox input staying checked?
  • Change string on each loop iteration
  • React Native Fetch Requests are not getting sent to my Node Js backend for some users
  • jQuery Validation Add Method Regex Number with Parentheses
  • display json data in bootstrap card using jquery
  • What prevents abuse of Firebase's createUserWithEmailAndPassword?
  • Karma + Jasmine (Angular Testing): Where should I define mock classes and test variables?
  • Call() method fails to generate output in javascript
  • Obj iteration dynamically - javascript
  • How to convert nested array to normal array and change types?
  • Javascript copy to clipboard only works if I have a breakpoint
  • Changing global variable by user input via function
  • different CSS style class on page load for mobile and desktop
  • JavaScript - Daterangepicker, isInvalidDate method enabling only one day
  • Javascript, Jquery: get element by two attr?
  • JavaScript colour changer doesn't work properly
  • Stop next execution of Rxjs observer?
  • Remove rules required from an input date
  • Format text input value with javascript
  • jQuery closest() in .this element is not working
  • Connect to postgresdb using typescript from nodejs server
  • MarkerWIthLabel maps library: this.setValue is not a function
  • Wrap all elements inside a specific div using JS (JQ works)
  • how to append data using ajax posts and datatables are not working?
  • Reactive Angular Material Data Table
  • How to update styles on child component onPress in react native
  • Grouping javascript array items based on their properties with AngularJS
  • Simplify nested if/else with repeated results?
  • Can we map over two arrays at same time in js?
  • How to send javascript values as params without backslash
  • Remove parent div class if child div has a specific value
  • Rewrite actionscript to javascript
  • Show alert message if value not selected in dropdown in jquery
  • How to get path directory from FileReader()?
  • how to pick different API calls depending on the drop down option
  • Redirect to URL after form submit in React
  • Javascript array displays twice
  • Moving an element smoothly to its new position without manually setting its position
  • Vue.js, Router importing template vue file
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org