views:

71

answers:

3

hey there,

as you can see, i have to functions first to check if all forms are not empty and the second function is to verify the captcher, when i combine them together both work at the same time, i want to first to verify the first function, when that function returns true then the other function starts,

here is the code that i used on form

<form  action="reg.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit=" Checking(this); return jcap();" >

As you can see both function execute at the same time

so i tried this

<form  action="reg.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit=" if(Checking(this) == true ){ return jcap();}" >

is bypass both

i also tried this

<form  action="reg.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit=" return(Checking(this) && jcap(this));" >

and it bypassed jcap function

+1  A: 

Combine both of them in a function:

function checkMyForm() {
  if(check_fields() == true) {
    if(check_captha() == true) {
        return true;
    }
  }
  return false;
}
Soufiane Hassou
hey there, i tried it but it bypass both this what i did`function checkMyForm() {if(Checking() == true) {if(jcap() == true){return true;}}return false;}`and on the form`<form action="reg.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit=" return(checkMyForm());" >`
Mahmoud
+2  A: 

It look like that Checking() doesn't have a valid return value. The script might have errored and block the processing. Update the function accordingly. E.g.

function Checking(form) {
    if (form is valid) {
        return true;
    } else {
        return false;
    }
}

This way the third approach should work.


That said (and unrelated to the actual problem), I'd try to follow the JavaScript coding conventions (functions start with lowercase) and also give the functions a bit more sensible name, e.g. checkCaptcha() and checkForm().

BalusC
hey there, thank you, but a problem occurs when i user this function `function checkAll(form) {if(checkForm(form)== true){if(jcap(form) == true){return true;}}else{ return false;}}` if i used jcap in the begining everything works smooth but the send button wont work, if i keept it like this everything works smooth but when it reaches to verification nothing happenes
Mahmoud
If the button doesn't work, then it means that the function didn't return `true`. I'd say, run a JS debugger to track the code execution step by step, e.g. [Firebug](http://getfirebug.com). If you want more assistance, you'll really need to update your question to include a self contained and executabele example, with the *minimum* amount of needed code to reproduce the very same problem, so that we can copy'n'paste'n'run it.
BalusC
@BalusC hey there after trying for an hour on try to catch the error i found out that i missed entering `return false` at the end of `if statment` thanks again
Mahmoud
A: 

No your onsubmit syntax is wrong.

Try this

function checkForm() {
    if(Checking() && jcap())
        return true;
    return false;
}

and your form:

<form action="reg.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return checkForm();">
Sherman