Using Javascript code

vj vjmazcu 19 Sep, 2008
I want to use javascript code. In the javascript code there is a "alert (msg)" and "return false" when the condition is false, and the execution don´t stop here.

What sentence I have to put in the javascript code for to stop the form code execution when the condition is false?

Thank you very much.
vj vjmazcu 19 Sep, 2008
Sorry, problem solved.

Thanl you very much
Max_admin Max_admin 19 Sep, 2008
Great, one idea is to make onsubmit function at the form tag and make it return false.

Regards

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
vj vjmazcu 22 Sep, 2008
Can you show me an example.

Thanks very much
vj vjmazcu 22 Sep, 2008
I validate all the my fields, but I want to check that one of chechbox group is checked at least. For this I did an javascript, but if the javascript code is true, send the form without the validation that offer the component. If don´t put the javascript code, the users can send me with all the checkboxes with checked=false.

The code of the javascript is the next

function checkform(){

if ((!document.ChronoContact_Peticion_cafes.Agua.checked) && (!document.ChronoContact_Peticion_cafes.Cafes.checked) && (!document.ChronoContact_Peticion_cafes.Pastas.checked) && (!document.ChronoContact_Peticion_cafes.Zumos.checked) && (!document.ChronoContact_Peticion_cafes.Infusiones.checked)) {


alert('Debes marcar un servicio al menos');


}
else document.ChronoContact_Peticion_cafes.submit();

}
Max_admin Max_admin 22 Sep, 2008
Hi,

if this works for you then that's fine, my idea is to add onsubmit="return checkform(this);" in the form tag attachment

then the JS code will look like this :

function checkform(form){
if(form.name.value == ''){ return false; }
return true;
}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
vj vjmazcu 23 Sep, 2008
I´m sorry but this solution don´t work. I put the tag "<form onsubmit="return checkform(this)">" in line 1 to form html code, and in javascript there is a function "checkform(form)" and never is in execution. I don`t know that is problem-

Thank you
Gr GreyHead 23 Sep, 2008
Hi vjmazcu,

You must not put <form> tags in the form code as CF adds them automatically and you end up with two sets.

Instead put the code onsubmit="return checkform(this);" in the Form Tag attachment box on the General tab for your form.

Bob
vj vjmazcu 24 Sep, 2008
Thank you very much Bob and Max, the problem is solved. Now the form work correctly.

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