The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Displaying input when checkbox clicked
tudsy
post Dec 7 2022, 05:26 AM
Post #1


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



Hi

I am trying to display an input for an email address when a checkbox is clicked.

<script>

$.ajax('#email_consent', {
type: 'get',
dataType: 'html',
success : function(html) {


if ($('#email_consent:checked')){


$('#form').html(

<label for='email'>Enter your Email address:</label>
<input type='email' id='email' name='Email_Address' size='30' placeholder ='Your Email Address' required />

);
}
},
error: function() {
alert("Error");
}
});

</script>


#form is the id of the form (see attached)


Attached File(s)
Attached File  form.txt ( 6.71k ) Number of downloads: 66
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Dec 7 2022, 01:49 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I don't do jQuery but what you need to do is:
Place the email HTML label and input, surrounded by a div with an id, where you want it in the HTML form.
The div should be hidden either by class or style.
When the checkbox is checked/unchecked the function should show/hide the hidden div.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 10:06 AM