I have 2 contact forms using contact form 7 and I am trying to switch between the 2 of them using a radio button. I have tried the following with normal text but it seems to be acting up with the shortcode.
Here is what I have:
<p><input type='radio' name='contact_type' value='1' /> Sales</p>
<p><input type='radio' name='contact_type' value='2' /> Support</p>
<div id='sales' style="display: none;">[contact-form-7 id="261" title="Sales"]</div>
<div id='support' style="display: none;">[contact-form-7 id="260" title="Support"]</div>
<script type="text/javascript" src="/scripts/updatepage.js"></script>
<script type="text/javascript">
$('input[name=contact_type]').on('change', function(){
var n = $(this).val();
switch(n)
{
case '1':
$('#sales').style.display = "block";
$('#support').style.display = "none";
break;
case '2':
$('#support').style.display = "block";
$('#sales').style.display = "none";
break;
}
});
</script>
- this is all being done in-line at the moment hence no check for DOM loading.
You are mixing a Jquery obejct with javascript.
For example, the object
$('#support')
has no attribute.style.display
Try this:
The WordPress shortcode should not effect the the two parent
<div>
s, just make sure the HTML looks correct after WordPress has rendered the contact forms.Here is jquery function for that