logo
down
shadow

Disable Checkbox on Certain Date? JavaScript


Disable Checkbox on Certain Date? JavaScript

By : Vaibhav Kumar
Date : October 17 2020, 03:08 PM
hop of those help? I'm trying to see if I can disable a checkbox on a form on two certain days of the week, say if I want the checkbox disabled on Monday and Friday. I have the code written to return a day value as a number, then convert it to a day(name). The code I have been altering was disabling all input checkboxes onLoad that have a certain class applied to them, so I've been altering that to see if I can write an If/Else statement, but can't seem to get it right. Any ideas what I can change this to, so it will work?
code :
<script>
window.onload = function () { 
    var d = new Date();
    var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
    document.getElementById("demo").innerHTML = days[d.getDay()];
    // if (days== 'Monday') {
    if (days[d.getDay()]== 'Tuesday') {
        document.querySelectorAll(".sum").forEach(function(actual) {
            actual.disabled=true;
        });
    }   
}
</script>

<p style="margin: 20px;">Today is <span id="demo"></span>!</p>
<input style="margin: 20px 0 20px 20px;" value="50" type="checkbox" class="sum" data-toggle="checkbox" name="item"> Item 1 (Not availalbe Mondays/Fridays)


Share : facebook icon twitter icon
How to disable a checkbox based on date using php?

How to disable a checkbox based on date using php?


By : Adrien Dorsaz
Date : March 29 2020, 07:55 AM
this one helps. I have iterated a table based on my query result... I have a column lastDate it contains a date value like 01/24/2010... Now i have to check the date value with the current date if currentdate is less than or equal to lastDate i have to enable the checkbox else disable it..... Any suggestion how it can be done in php... , i tried this and it worked..
code :
<input type="checkbox" name="group" id="group" value="<?=$row['dAssignment_id']?>" 
                <?php 
                $dd=$row['dDate'];
                if($dd=='')
                {

                }
                else
                {
                $str = $dd;
                $dd = strtotime  ( $str );
                    if((date('m/d/Y')) <= (date('m/d/Y',$dd)))
                    {
                       echo 'enabled';
                    }
                     else
                     {
                       echo 'disabled';
                     }
                }

                 ?> onclick="checkdisplay(this);"> 
Disable checkbox having different date

Disable checkbox having different date


By : Ronak Gupta
Date : March 29 2020, 07:55 AM
Any of those help , Check out this code..
code :
$(document).ready(function(){
$("input[type=checkbox]").change(function() {
	//alert($(this).attr("rel"));
	$due_date = $(this).attr("rel");
	$id = $(this).val();
    
    var $check = false;
    
	if($(this).is(':checked')){
		$("input[type=checkbox]").each(function(){
			if($(this).val()!=$id){
				if($(this).attr("rel")==$due_date){
					$(this).prop('disabled',false);
				}else{
					$(this).prop('disabled',true);
				}
			}
		});
	}else{
		$("input[type=checkbox]").each(function(){
            if($(this).val()!=$id & $(this).is(':checked')){
                $check = true;
            }
		});
        if(!$check){    
            $("input[type=checkbox]").each(function(){
               $(this).prop('disabled',false);
            });
        }
	}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" 
                 id="1" 
                 name="invoice_id[]" 
                 rel="10-15-2014" 
                 value="1">
		<input type="checkbox" 
                 id="2" 
                 name="invoice_id[]" 
                 rel="10-15-2014" 
                 value="2">
		<input type="checkbox" 
                 id="3" 
                 name="invoice_id[]" 
                 rel="10-16-2014" 
                 value="3">
		<input type="checkbox" 
                 id="4" 
                 name="invoice_id[]" 
                 rel="10-17-2014" 
                 value="4">
How to disable anPHP disable and clear textbox when checkbox is unchecked. Check/uncheck checkbox depending on database

How to disable anPHP disable and clear textbox when checkbox is unchecked. Check/uncheck checkbox depending on database


By : Md.reza Naqvi
Date : March 29 2020, 07:55 AM
it helps some times When manipulating boolean attributes such as checked, disabled, multiple, you should be using .prop() instead of .attr() or .removeAttr(). Some other suggested improvements:
Use this.checked instead of $(".dedstat").is(":checked"), so that it is context specific Use the ID selector instead of class You can chain your jQuery methods, so you can both disable the input and empty its value at the same time Listen to the change event instead of click for elements
code :
$("#dedstat").change(function() {
  if (this.checked) {
    $("#deductto").prop("disabled", false)
  } else {
    $("#deductto")
      .prop("disabled", true)
      .val('');
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="dedstat" id="dedstat">
<input type="text" name="deductto" id="deductto">
// Method to conditionally enable/disable input
var updateTextInput = function(el) {
  if (el.checked) {
    $("#deductto").prop("disabled", false)
  } else {
    $("#deductto")
      .prop("disabled", true)
      .val('');
  }
}

// Call method when change event is fired from checkbox
$("#dedstat").change(function() {
  updateTextInput(this);
});

// Call method on DOMready, pass DOM node (not the jQuery object)
updateTextInput($('#dedstat')[0]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="dedstat" id="dedstat">
<input type="text" name="deductto" id="deductto">
<input type="checkbox" name="dedstat" id="dedstat" <?php echo $dedstat == 1 ? 'checked' : ''; ?>>
How to insert today's date and disable input if checkbox is checked using javascript

How to insert today's date and disable input if checkbox is checked using javascript


By : user2990807
Date : March 29 2020, 07:55 AM
help you fix your problem You need to assign the value to the date input. I've commented an alternate way and added extra code that resets the value when checkbox is checked again, Consider the following:
code :
function onCheck(checkbox) {
  var dateElement = document.getElementById('date');
  dateElement.disabled = checkbox.checked;
  if (checkbox.checked) {
    //dateElement.value = new Date().toISOString().substr(0, 10);
    dateElement.valueAsDate = new Date();
  }
  else
    dateElement.value = '';
}
Check if New Student<br>
<input type="checkbox" id="myCheck" name="New_Student" onclick="onCheck(this);">
<!--If checkbox is checked date box is disabled-->

<br>

<legend>Enrollment Data</legend>
<label for="sel1">Select Date of Enrollment:</label><br>
<input type="date" name="Enrollmentday" value="EnrollDate" id="date" onchange="checkDate(this);">
<!--Gets today's date and puts it as max-->
Javascript Enabled input type when checkbox checked and disable when checkbox unchecked

Javascript Enabled input type when checkbox checked and disable when checkbox unchecked


By : Júnio Branco
Date : March 29 2020, 07:55 AM
it should still fix some issue = is assignment (setting the value of a variable), so if (i = true) sets i to true and then branches into the if block. To do a comparison, normally you'd use == or ===, but with booleans, that's never necessary; just check the value directly:
Related Posts Related Posts :
  • Use html link to open javascript modal
  • Check if text input is not empty
  • How do I validate start time and end time using select
  • Form submit is not prevented when trying to integrate VueJS with SemanticUI
  • Should i install node and npm if i am not a node programme but i want to use bower?
  • ng-view does not get the data from href?
  • THREE.js - Graphical Glitch with an imported model
  • ViewModel current state to JSON
  • How to stop multiple row highlighting
  • Custom input element in native form
  • Angular service unable to execute function
  • Enable/disable input field depending on array length in Angular 1.5
  • Angular Load Json Error
  • how is dart compiled into javascript?
  • How to create dynamic radio button using javascript
  • Nodejs/Express - Error: Can't set headers after they are sent
  • javascript remove all elements :Uncaught SyntaxError: Unexpected identifier
  • onchange event of text box not working if i change text value dynamically
  • Determine the position of the view port scroll bar
  • Uploading file on site from DropBox
  • How to change the legends from vertical view to horizontal view?
  • Recursive function to create a tree
  • How to apply my class from css to checkbox?
  • If statement on every case within switch
  • checking JSON Data contains media or not..?
  • Binding a list with deviders to the DOM AngularJS
  • Extra blank space is including in dynamic dropdown in angularjs
  • How do I only update one value of my reducer in Redux?
  • Display embedded PDF in Internet Explorer 11 from binary string or base64
  • Convert String to nested array of characters
  • Angular 2 HTTP get handling 404 error
  • Single page with multiple states controlled by URL
  • call prototype method inside callback function of prototype method
  • How To Put Values Dynamically
  • I have custom google map multiple markers.when i am using reverse geolocation for multiple marker
  • Use casperjs to get all links from a page
  • Modify url path without redirection
  • Jquery "hasClass" not working
  • how to change col-span when a data is added to html table cell
  • Stopping links inside of a table from marking table row as selected
  • Angular 1.4 ng-if and ng-repeat to menu
  • Sending a list of checkboxes via Ajax to Django
  • ng-model not updated from controller to view
  • Node command is not working in cmd after installing node on windows?
  • Delay part of the funcion execution JavaScript and exit function
  • JS addition game: how do I display 4 possible answers, 3 of them are random and 1 is the correct answer ? (Codepen inclu
  • getting perplexed about this code, not seeing any thing wrong, but not printing out what i'm expecting
  • Ajax.beginForms MVC Partial View
  • Mouse-wheel direction not working
  • vanilla js remove id box
  • How to change text to upper case or lower case depending on string length in Angular 1.5?
  • issues with autocomplete inputs values
  • Angular 2/Typescript Delete Object On Button Click
  • Angular 2 ngFor can't show one object by index
  • The HTML Form of my website don't send the infos anywhere
  • Returning value from one method to second in callback within object
  • KonvaJS: How to serialize object with custom property?
  • What are the reasons for use static contextTypes = {} in react components?
  • element.changedTouches[0] error undefined. Chrome bug?
  • Focus issue of cursor on Internet Explorer
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com