How can JavaScript be used to clear multiple form fields with different values after submission?
To clear multiple form fields with different values after submission using JavaScript, you can loop through each form field and set their values to an empty string. This can be achieved by targeting each form field using its ID or class and then updating its value property to an empty string. ```javascript // Get all form fields by their IDs and clear their values document.getElementById('field1').value = ''; document.getElementById('field2').value = ''; document.getElementById('field3').value = ''; ```
Keywords
Related Questions
- What are common pitfalls to avoid when handling user input in PHP scripts to prevent errors like "Undefined index"?
- How can timestamp functions like `mktime()` be utilized in PHP scripts to handle date and time values when updating database records?
- How can PHP be used to display the next upcoming date from a MySQL database?