Forums

show/hide textfield in multipageform

emrahsevgi 23 Dec, 2018
Hi;
I have a multipageform. I am trying to show/hide a text field which is in 2nd page according to 1st page radiogroup. I read https://www.chronoengine.com/faqs/2645-how-can-i-showhide-a-textarea-when-a-checkbox-is-clicked and I preapeared a custom code event on load event (first event) after display_section1 event. My custom code event is like this:

<script type="text/javascript">
var checkbox_id, textarea_id, checkbox, textarea, div;
/* edit the next two lines to match the ids of the elements in your form */
checkbox_id = 'tur[0]';
textarea_id = 'myname';

window.addEvent('domready', function() {
checkbox = $(checkbox_id);
textarea = $(textarea_id);
div = $(textarea_id+'_container_div');
div.dissolve();
showHide();
checkbox.addEvent('click', showHide);
});

function showHide() {
if ( checkbox.checked ) {
div.reveal();
textarea.disabled = false;
} else {
div.dissolve();
textarea.value = '';
textarea.disabled = true;
}
}
</script>

But this is not work.

Thanks for your help.
GreyHead 24 Dec, 2018
1 Likes
Hi emrahsevgi ,

Which version of ChronoForms re you using?

A multi-page form is normally submitted to the server between pages so your JavaScript will not work, you need to show/hide the text field in the Load event for the second page.

Bob
emrahsevgi 24 Dec, 2018
Hi

Thanks for your reply. I am using v6. I understood that I will use javascript on second page. I used javascript on second page after event loader. I used my custom code' s (Javascript code) name instead of event name. But it does not work. I am newbie on chronoform. I can not learn setup sections events at the moment. Does my javascript code work with radiogroup and does my code wrong?

thanks
healyhatman 24 Dec, 2018
Answer
1 Likes
If you really really want to use javascript to do what you're trying to do, you need to read up on Semantic-UI, the framework CF uses.

https://semantic-ui.com/introduction/getting-started.html

OR you could just use the field Events built in to Chronoforms, which would be much easier. Read the manual, and look at the demo forms.
This topic is locked and no more replies can be posted.