Give me HTML code for a form consisting of: - Radio control with 3 options. - Name…
- User
Give me HTML code for a form consisting of:
- Radio control with 3 options.
- Name (text)
- Email (email)
- Phone (phone)
- Message (textarea)
- Submit button
- Assistant
Sure, here is the HTML code for the form you described:
<form> <label for="options">Options:</label><br> <input type="radio" id="option1" name="options" value="option1"> <label for="option1">Option 1</label><br> <input type="radio" id="option2" name="options" value="option2"> <label for="option2">Option 2</label><br> <input type="radio" id="option3" name="options" value="option3"> <label for="option3">Option 3</label><br> <label for="name">Name:</label><br> <input type="text" id="name" name="name"><br> <label for="email">Email:</label><br> <input type="email" id="email" name="email"><br> <label for="phone">Phone:</label><br> <input type="tel" id="phone" name="phone"><br> <label for="message">Message:</label><br> <textarea id="message" name="message"></textarea><br> <input type="submit" value="Submit"> </form>Please note that the
type="phone"for the phone input may not be universally supported by all browsers. You may want to consider usingtype="text"instead. - User
How can I prevent default for button click in JS?
- Assistant
To prevent the default behavior for a button click in JavaScript, you can use the
preventDefault()method on the event object. Here is an example:<!DOCTYPE html> <html> <head> <title>Prevent Default Button Behavior</title> </head> <body> <button id="myButton">Click Me</button> <script> document.getElementById("myButton").addEventListener("click", function(event) { event.preventDefault(); // Prevent the default behavior of the button click alert("Button click prevented!"); }); </script> </body> </html>In this example, when the button is clicked, the
preventDefault()method is called on the event object passed to the event listener function. This prevents the default behavior of the button click, which in this case would be to submit a form (if the button is inside a form) or to trigger any other default behavior associated with the button.