Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Add and remove required attribute based on whether it is visible or hidden

$('#Additional-Attendees').on('change', function() {
  var v = $(this).val() == "No" ? 0 : +$(this).val();

  var after = $(".additional-attendees:eq(" + v + ")").nextAll(".additional-attendees").addBack();
  var before = $(".additional-attendees:eq(" + v + ")").prevAll(".additional-attendees")
  $.each(before, function() {
    $(this).show();
    $('input[id*="First-Name"]',this).prop("required", true)
    $('input[id*="Last-Name"]',this).prop("required", true)
    $('input[id*="Email"]',this).prop("required", true)
  });
  $.each(after, function() {
    $(this).hide();
    $('input[id*="First-Name"]',this).prop("required", false).val("")
    $('input[id*="Last-Name"]',this).prop("required", false).val("")
    $('input[id*="Email"]',this).prop("required", false).val("")
    $('input[type="checkbox"]:checked',this).prop('checked', false).trigger('change');
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Save multiple radios checked on LocalStorage 
Javascript :: ngrx let 
Javascript :: Render JOSN in frontend 
Javascript :: access language in request express 
Javascript :: How to change a key value pair within a nested json structure C# 
Javascript :: how to set the x and y axis title in plotly express bar 
Javascript :: Any array in JSON object is not empty 
Javascript :: Node.js and Express session handling - Back button problem 
Javascript :: yaml request body json 
Javascript :: lerp two values 
Javascript :: Third Example of Event Delegation In JavaScript 
Javascript :: javascript get multiple attributes 
Javascript :: react state based router 
Javascript :: javascript get next month name 
Javascript :: javascript object access time complexity 
Javascript :: testing code through local server using express.js 
Javascript :: force browser reload page from server javascript 
Javascript :: phaser add camera 
Javascript :: Create Built-in AbortController Object 
Javascript :: Assigning A Property The Return Value Of A Function In Class 
Javascript :: Toggle image onclicking parent 
Javascript :: on submit success jquery 
Javascript :: onclick readmore and readless react js 
Javascript :: How to Loop Through an Array with a for…of Loop in JavaScript 
Javascript :: Backbone With Express 
Javascript :: Backbone Template Simple Example 
Javascript :: java script return array 
Javascript :: jquery equivalent of number_format( 
Javascript :: mounting in react 
Javascript :: how to take input from user in javascript console 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =