Forum
Perch Forms
Hi,
I found this method of displaying multiple forms on my website and it works with regular forms but I cannot get it to work with Perch Forms. It seems like the display:none style does not work with perch forms.
Any ideas?
<script>
function changeOptions(selectEl) {
let selectedValue = selectEl.options[selectEl.selectedIndex].value;
let subForms = document.getElementsByClassName('className')
for (let i = 0; i < subForms.length; i += 1) {
if (selectedValue === subForms[i].name) {
subForms[i].setAttribute('style', 'display:block')
} else {
subForms[i].setAttribute('style', 'display:none')
}
}
}
</script>
<select onchange="changeOptions(this)">
<option value="" selected="selected"></option>
<option value="form_1">Form 1</option>
<option value="form_2">Form 2</option>
<option value="form_3">Form 3</option>
</select>
<form class="className" name="form_1" id="form_1" style="display:none">
THIS IS FORM 1
</form>
<form class="className" name="form_2" id="form_2" style="display:none">
THIS IS FORM 2
</form>
<form class="className" name="form_3" id="form_3" style="display:none">
THIS IS FORM 3
</form>
Make sure your JavaScript and Perch form ids match.
Because perch form id's are dynamic it would be hard to have the ID coded into the CSS. I would make sure each form were in a separate div and then use display:none on the containing div.
The form IDs don't need to be dynamic - you can set the prefix yourself if you need to.
Ahhh, Yes... I had forgotten this.
Hi all,
This is my form... When I place this as in the above example instead of form_1 with the display:none it does not hide. The form ID also changes when I run it on my live website but even when I match both ID's it still does not work.
If you want to set the id of the form to
conor_contact
for example, you need to use theprefix
attribute.I don't think you can use inline styles on Perch tags. So the
style
attribute isn't useful here. If you want to apply styling to#conor_contact
, why not do this in your .css file(s) where the rest of your styles are?style
attributes are not passed through fromperch:form
tags to the correspondingform
tags. Bothclass
anddata-
attributes are, so those would be a much better choice.