473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

canceling the submition of a form

i have a form made up of 2 file inputs and a submit button..
the imputs are to upload images, namley jpeg's for a e-greatings thing im
working on.
this only works with jpegs so i have a script that will check the value of
the imput tag to make sure it ends with .jpg, .jpeg.

this works fine on the jubmit button using

onclick="myHandler(this)"

it works fane that it alerts the user that only jpegs are valid but then
when the alert
has been ok'd it continues to submit the form to my php script.

how can i get this to cancle the submit action?

cheers

Greg Brant
Jul 20 '05 #1
7 2950
Lee
"greg said:

i have a form made up of 2 file inputs and a submit button..
the imputs are to upload images, namley jpeg's for a e-greatings thing im
working on.
this only works with jpegs so i have a script that will check the value of
the imput tag to make sure it ends with .jpg, .jpeg.

this works fine on the jubmit button using

onclick="myHandler(this)"

it works fane that it alerts the user that only jpegs are valid but then
when the alert
has been ok'd it continues to submit the form to my php script.

how can i get this to cancle the submit action?


Don't user the onclick handler of the submit button.
That's not even supported in all browsers.
Use the onSubmit handler of the form, itself, and have
it return true, if the form is to be submitted, and
false if not:

<form action="whatever" onsubmit="return myHandler(this)">

Jul 20 '05 #2
hi,

thanks for the reply.. i tried this once but there was somthing i could not
understand

i was returning true or false but whatever i had it was still going to the
action="" URL

im using ie6 on win xp

cheers
"Lee" <RE**************@cox.net> wrote in message
news:bg********@drn.newsguy.com...
"greg said:

i have a form made up of 2 file inputs and a submit button..
the imputs are to upload images, namley jpeg's for a e-greatings thing im
working on.
this only works with jpegs so i have a script that will check the value ofthe imput tag to make sure it ends with .jpg, .jpeg.

this works fine on the jubmit button using

onclick="myHandler(this)"

it works fane that it alerts the user that only jpegs are valid but then
when the alert
has been ok'd it continues to submit the form to my php script.

how can i get this to cancle the submit action?


Don't user the onclick handler of the submit button.
That's not even supported in all browsers.
Use the onSubmit handler of the form, itself, and have
it return true, if the form is to be submitted, and
false if not:

<form action="whatever" onsubmit="return myHandler(this)">

Jul 20 '05 #3
so heres my script

function checkExt(file1, file2) {
alert("hello");
files = Array(file1, file2);

if (files[0] == "" && files[1] == ""){
alert("Please select a file or browse our gallery");
return false;
}else{
return true;
}
}

and on the form tag i have

<form action="designer2.php?upload=1" method="post"
enctype="multipart/form-data" name="uploadForm" target="_top"
id="uploadForm" onSubmit="return checkExt(this.userFile1.value,
this.userFile2.value)">

and i dont even get the
alert("hello");

it just submits

cheers

"Lee" <RE**************@cox.net> wrote in message
news:bg********@drn.newsguy.com...
"greg said:

i have a form made up of 2 file inputs and a submit button..
the imputs are to upload images, namley jpeg's for a e-greatings thing im
working on.
this only works with jpegs so i have a script that will check the value ofthe imput tag to make sure it ends with .jpg, .jpeg.

this works fine on the jubmit button using

onclick="myHandler(this)"

it works fane that it alerts the user that only jpegs are valid but then
when the alert
has been ok'd it continues to submit the form to my php script.

how can i get this to cancle the submit action?


Don't user the onclick handler of the submit button.
That's not even supported in all browsers.
Use the onSubmit handler of the form, itself, and have
it return true, if the form is to be submitted, and
false if not:

<form action="whatever" onsubmit="return myHandler(this)">

Jul 20 '05 #4
Then you are most likely generating a JavaScript error somewhere along the way.
Change the onsubmit button to be:

onsubmit="return (false && checkExt(this.userFile1.value,
this.userFile2.value));"

then check the lower-left corner of IE for a yellow !, or type "javascript:" (no
quotes) into the Address bar of Mozilla/Netscape 7. If there are any errors,
they will be reported.

greg brant wrote:
so heres my script

function checkExt(file1, file2) {
alert("hello");
files = Array(file1, file2);
Why do you put both files into an array and then access the individual
elements?
if (files[0] == "" && files[1] == ""){
if (file1 == "" && file2 == "") {
alert("Please select a file or browse our gallery");
return false;
}else{
return true;
}
}

and on the form tag i have

<form action="designer2.php?upload=1" method="post"
enctype="multipart/form-data" name="uploadForm" target="_top"
id="uploadForm" onSubmit="return checkExt(this.userFile1.value,
this.userFile2.value)">

and i dont even get the
alert("hello");

it just submits

cheers

"Lee" <RE**************@cox.net> wrote in message
news:bg********@drn.newsguy.com...
"greg said:

i have a form made up of 2 file inputs and a submit button..
the imputs are to upload images, namley jpeg's for a e-greatings thing im
working on.
this only works with jpegs so i have a script that will check the value ofthe imput tag to make sure it ends with .jpg, .jpeg.

this works fine on the jubmit button using

onclick="myHandler(this)"

it works fane that it alerts the user that only jpegs are valid but then
when the alert
has been ok'd it continues to submit the form to my php script.

how can i get this to cancle the submit action?


Don't user the onclick handler of the submit button.
That's not even supported in all browsers.
Use the onSubmit handler of the form, itself, and have
it return true, if the form is to be submitted, and
false if not:

<form action="whatever" onsubmit="return myHandler(this)">


--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5
Grant Wagner <gw*****@agricoreunited.com> writes:
Change the onsubmit button to be:

onsubmit="return (false && checkExt(this.userFile1.value,
this.userFile2.value));"


The would be equivalent to
onsubmit='return false;"
In Javascript, the "&&" operator is "short-circuit". If the first operand
is false, then the second isn't evaluated, since we already know that the
result must be false.

Try
onsubmit="return (false && alert('this is not happening'));"
and see (not) that it is indeed no happening.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
Lasse Reichstein Nielsen wrote:
Grant Wagner <gw*****@agricoreunited.com> writes:
Change the onsubmit button to be:

onsubmit="return (false && checkExt(this.userFile1.value,
this.userFile2.value));"


The would be equivalent to
onsubmit='return false;"
In Javascript, the "&&" operator is "short-circuit". If the first operand
is false, then the second isn't evaluated, since we already know that the
result must be false.

Try
onsubmit="return (false && alert('this is not happening'));"
and see (not) that it is indeed no happening.

/L


You're right of course, it should have been:

onsubmit="return (checkExt(this.userFile1.value, this.userFile2.value) &&
false);"

Since he isn't sure the function is even being called, it necessary to halt
the onsubmit event unconditionally so he can see the error(s), if any.

onsubmit="checkExt(...); return false;" would work just as well.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #7
thanks guys
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:3F***************@agricoreunited.com...
Lasse Reichstein Nielsen wrote:
Grant Wagner <gw*****@agricoreunited.com> writes:
Change the onsubmit button to be:

onsubmit="return (false && checkExt(this.userFile1.value,
this.userFile2.value));"
The would be equivalent to
onsubmit='return false;"
In Javascript, the "&&" operator is "short-circuit". If the first operand is false, then the second isn't evaluated, since we already know that the result must be false.

Try
onsubmit="return (false && alert('this is not happening'));"
and see (not) that it is indeed no happening.

/L


You're right of course, it should have been:

onsubmit="return (checkExt(this.userFile1.value, this.userFile2.value) &&
false);"

Since he isn't sure the function is even being called, it necessary to

halt the onsubmit event unconditionally so he can see the error(s), if any.

onsubmit="checkExt(...); return false;" would work just as well.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html

Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Scott Phelps | last post by:
How can I make an input box (or other objects) disabled or greyed out and still have them submit in the form? Thanks
4
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if...
0
by: Jitu | last post by:
<form runat=server id=myform> <AT_COMMON:SitePage id="DefaultPage" runAt="Server"> <itemTemplate> <AT:UsersRegistration id="Registration" RunAt="Server" UserFormName="Users/Users/UserForm.ascx"...
1
by: Lance | last post by:
I want to prevent a form from closing when the user clicks the form's Close button in the form's ControlBox (i.e., the button with the "X" in the upper-right corner of the form). Instead, I just...
6
by: Kevin | last post by:
I come up with these questions during the day, do some research, and then look for experienced users' input. 1. In Access, we already know it's pretty much an automatic save if you enter data. ...
1
by: sahay | last post by:
Retain a visitor-specified value in a select option after page submition
0
by: rcarmich | last post by:
I am having an issue canceling a beginReceive call on a timeout. For example, the following function: public int ReadBytes(Socket theSock, byte arr, int startByte, int length, int timeout) {...
2
TonFrere
by: TonFrere | last post by:
Hello, I'm building a solution using Visual Studio Windows Forms and I'm coding in C#. I have a windows form with databinded textboxes, comboboxes and a datagrid. Everything works fine until a...
0
by: gervo | last post by:
I have built a series of email forms in flash MX. using perl. the forms work for some people but not all and I was hoping some one could help me out. Here is the Actionscript on the send button ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.