Check if Radio Button is clicked (Selected) - Smarty Template

#1

I have defined radio button in smarty template:

<input type="radio" name="AcceptTerms" value="Ja/Nein"/>
So, I need to check if the Radio button is selected, to assign variable with value ‘Ja’, if not assign with ‘Nein’.

So, can someone help me how to check if the radio button is checked/selected in smarty template (.tpl)?

Thank you.

#2

with regular javascript

#3

Yes, I will find which radio button is selected with javascript. But how I will assign smarty variable?

#4

Here is my code:
Ja/Nein
[{oxscript add="$(’#AcceptTerms’).change( function() { var variable = ‘Ja’;
console.log(variable);
});"}]

And when I am clicking the button, in console log, ‘Ja’ is printed.

So, my problem now is how to assign this value to smarty variable, because I have to send it into controller.

#5

this is nopt how it works
You need some basic knowledge about how web sites work: backend, frontend, server and client side scripts and on which side the particular scripting language is executed.

#6

google --> “Check if Radio Button is checked”

#7

I know that, but I faced with problems how to assign variable in smarty template depending of radio button selection…

#8

Smarty is PHP running on the server, JS lives in the Browser on the client. There is no direct connection.
You have to put the value into an input field (using JS), which then gets submitted to the controller.

#9

Yes, I am doing in that way right now.
This feature I need in the third step during the checkout when payment method is choosen.
I have to give opportunity to the client to Accept or Not accept to be used his personal information.

So, maybe I can add input field inside the form that is submitted when ‘Next Step’ button is pressed…

#10

I created a new form, passed data to controller and everything works fine.
But, I have one more problem:
If I am trying to use existing button ‘Continue to next Step’ for submitting my form it’s not working because in the first lines of the form, there are some class and functions defined:

            <input type="hidden" name="cl" value="[{ $oViewConf->getActiveClassName() }]">
            <input type="hidden" name="fnc" value="validatepayment">

But I need to use also my owns:

    <input type="hidden" name="cl" value="accept_terms" />
    <input type="hidden" name="fnc" value="acceptingTerms" />

So, with my own form and button it’s working. But I need to work this when ‘Continue to next Step’ button is pressed in their form.

Can I define my own two lines in their form or there is another way?
Please for suggestions.

Thanks.

#11

I solved the problem with using AJAX that send radio buttuon value to the controller when it’s clicked.

Thanks for your help!