jQuery Forms and Inputs

1. Getting and Setting Input Values

You can use val() to get or set values of input fields.


<input type="text" id="nameInput" placeholder="Enter your name">
<button id="getName">Get Name</button>
<p id="nameOutput"></p>

2. Form Validation

Basic form validation can be done by checking if fields are filled or match a pattern.


<form id="myForm">
  <input type="email" id="email" placeholder="Enter your email" required>
  <button type="submit">Submit</button>
</form>
<p id="formMsg"></p>

3. Enabling and Disabling Form Elements

You can use prop() to enable or disable form elements.


<input type="text" id="disableInput">
<button id="toggleBtn">Disable/Enable</button>

4. Checkbox and Radio Handling

You can check whether a checkbox or radio button is selected using :checked.


<label><input type="checkbox" id="subscribe"> Subscribe</label>
<button id="checkSubscribe">Check Status</button>
<p id="subscribeStatus"></p>

If you have any questions, feel free to ask. Thank you for reading!

Thankyou!