Forums

Call the function when the certain value of radio button is selected

alitvin 11 Mar, 2017
Hi.

I need to call a custom js-function when user select a value of radio button. I tried to declare a function in an external file, and also just describe it in the "JS Code" field of "Load JavaScript" action, but it is not called. What i'm doing wrong?

Joomla! 3.6.2, Chronoforms v5.
GreyHead 11 Mar, 2017
Hi alitvin ,

I can't tell from the information here. How are you trying to call it in the Load JavaScript action.

Bob
alitvin 11 Mar, 2017
I'm trying to bind the event of a choice of a particular variant of the radio button[attachment=107867_20170311111216_bind-event-jpg.jpg]
[/attachment]
Js-file, in which the function is declared, is loaded through Load JavaScript
GreyHead 11 Mar, 2017
Hi alitvin,

That looks OK to me. Please post a link to the form so I can take a quick look.

Bob
alitvin 11 Mar, 2017
Hi Bob,

Link to the form. Function defined in consultant.js and it should be called when the last option is selected.

Thank for your help.
GreyHead 11 Mar, 2017
Hi alitvin,

Your event code appears to be linked to an input with the name 'c_outdoor_what - but I don't see that name anywhere in the form?

Bob
alitvin 11 Mar, 2017
I'm sorry, I probably can not understand. You do not have the item 'c_outdoor_what' on that page?

I understood. I have a multi-page form and on a direct link the "Event switcher" gives another form. Correct path to form: go to the link, click the "СТАРТ" button, select the first option "СНАРУЖИ". Sorry for incorrect information.
GreyHead 12 Mar, 2017
Hi alitvin,

Found it thank you. The event code to call the askQuestion function is running OK as far as I can see but the askQuestion function is not being run.

It may be because you now have two copies of the function - one in the consultant.js file and the other in the form itself. I suggest that you remove one of these and see if it them works correctly.

Bob
alitvin 12 Mar, 2017
Hi Bob

I remove the one copy of the function, but it is still not called 😟

It looks like a problem in the function call code:
if($("[name='c_outdoor_what']:checked").val() == "question"){
askQuestion;
}



And it should be:
if($("[name='c_outdoor_what']:checked").val() == "question"){
askQuestion();
}


This is a bug?
GreyHead 13 Mar, 2017
Answer
Hi alitvin,

Yes that's correct - if you add the () to the function name on the element Events tab then it works OK.

I'm guessing that something must have changed as I don't recall seeing this problem before :-(

Bob
alitvin 13 Mar, 2017
Bob, thank you very much. Everything works now.
This topic is locked and no more replies can be posted.