Redirect depending on checkbox

jgonzalez29 31 Dec, 2011
Hello everybody,

I have a form and I want it to redirect the user to another URL depending on if it is selected or not. In another words, if checkbox is selected users will be redirected to URL1 otherwise to URL2. This is the simple code (I tried first in a test.html page annd it worked):

var url0 = "http://localhost/joomla/index.php/";
var url1 = General.master_program_selected.checked;
location.href = url0+url1;

So URL1 and URL2 will be http://localhost/joomla/index.php/0 o http://localhost/joomla/index.php/1.

If I comment line 2 (var url1) everything works correctly, joomla redirect to:
http://localhost/joomla/index.php/

When I uncomment line2 it is always redirected to ?chronoform=General&event=submit

So, When I want to use the value of General.master_program_selected.checked this code doesn't work.

General is the name of the form
master_program_selected is the name of checkbox

I wrote this code inside "events" (in wizard mode) and onclick I addedd an event "LoadJS".

Thanks for your help,
GreyHead 02 Jan, 2012
Hi jgonzalez29,

If you do this using JavaSCript in the browser then the code needs to be linked to the onChange event for the checkbox so that it gets updated when the box changes.

That said, there is no real need to do it in the browser at all, the code is simpler if you use PHP in the form ON Submit event. There's an example here for a radio button that you can adapt to a checkbox.

Bob
This topic is locked and no more replies can be posted.