javasript problem - submiting

  • Thread starter Bartosz Wegrzyn
  • Start date
B

Bartosz Wegrzyn

Please look at my code.
I do validation of my form before I submit it.

I want to be able to to press one form button without running validating
script.
I just want to go directly to my php script.

I tried to do this
onclick="document.form1.submit()" but than the button value is not posted
and my php script is not working.

Also I tried to remove the onSubmit handler on my form and than I add this
to all my 3 buttons that will run with validation.


<input type="button" name="select" value="save" on click="return
check(this);document.form1.submit()"It is not working I get error that Java
does not support that object or method.Also the value save is not
submitted.Is there any way to fix this
 
J

Jeff Thies

Please look at my code.
I do validation of my form before I submit it.

Do this instead:

<form onsubmit="return checkForm()" ...>

Have checkForm return true if all is good and return false if there is
an error.

This will let you use a normal submit button and will let the form
work if javascript is disabled.

Jeff
 
J

Jeff Thies

Jeff said:
Do this instead:

<form onsubmit="return checkForm()" ...>

I've reread your post and I think I misunderstood what you wanted. I
think you want a submit button that bypasses the onsubmit validation

Try this

<form onsubmit="return checkForm()" ...>
<input type="submit" value="normal" >
<input type="submit" value="bypass" onclick="bypass='1'">


var bypass;
function checkForm(){
if(bypass){return true;}
....
normal form check code ...

Jeff
 
B

Bartosz Wegrzyn

I like the idea,but I am having problems with passing the bypass value to
the script.

I have onclick="bypass='1'"
and in my script I have

var bypass
if (bypass) {return true;}

my function...

shoutnot it be
if (bypass==1) {return true;}

Because this is not working.

Bart,
 
J

Jeff Thies

Bartosz said:
I like the idea,but I am having problems with passing the bypass value to
the script.

I have onclick="bypass='1'"
and in my script I have

var bypass
if (bypass) {return true;}

my function...

shoutnot it be
if (bypass==1) {return true;}

Either way. 1 is true, 0 or undefined is false.

Here's my little test page:

<html>
<body>
<script type="text/javascript">
var bypass;
function checkForm(){
if(bypass){alert('go');return true;}else{
alert('no go');return false;
}
}
</script>
<form onsubmit="return checkForm()" action="somewhere.htm">
<input type="submit" value="normal" >
<input type="submit" value="bypass" onclick="bypass='1'">
</form>
</body>
</html>

Jeff
 
L

Lasse Reichstein Nielsen

Bartosz Wegrzyn said:
I like the idea,but I am having problems with passing the bypass value to
the script.

I have onclick="bypass='1'"

It really should be
onclick="bypass=true;"
No need to use the string '1' to represent true, when there is a perfectly
good boolean value.
and in my script I have
var bypass

The "var bypass" should be outside the function, as a global variable.
You might want to initialize it:
var bypass = false;
It is not important, but it makes the code easier to read (you can see
that it holds a boolean that is initially false).
if (bypass) {return true;}

This should work. The condition of an if statement is converted to a
boolean, and a non-empty string ('1') is converted to true.
The values that are converted to false are
false, null, undefined, "" (empty string), 0, and NaN (not-a-number).
my function...

shoutnot it be
if (bypass==1) {return true;}

No. If you want to compare to the string, it should be
if (bypass == '1') {return true;}
It is just simpler to use
onclick="bypass = true;"
and then just test
if (bypass) {return true;}
Because this is not working.

If it still isn't workig, try inserting an
alert(bypass)
just before the if statement, and see what value it has.

/L
 
V

Vjekoslav Begovic

Bartosz Wegrzyn said:
Please look at my code.
I do validation of my form before I submit it.

I want to be able to to press one form button without running validating
script.
I just want to go directly to my php script.

Try this:

<form method="get" action="whatever.php" onsubmit="return checkForm()">
<input type="submit" value="normal" >
<input type="button" value="bypass" onclick="this.form.submit()">
</form>

Vjekoslav
 
B

Bartosz Wegrzyn

Either way. 1 is true, 0 or undefined is false.

Here's my little test page:

<html>
<body>
<script type="text/javascript">
var bypass;
function checkForm(){
if(bypass){alert('go');return true;}else{
alert('no go');return false;
}
}
</script>
<form onsubmit="return checkForm()" action="somewhere.htm">
<input type="submit" value="normal" >
<input type="submit" value="bypass" onclick="bypass='1'">
</form>
</body>
</html>

Jeff

Thanks I put the bypass var inside the function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top