HighDots Forums  

Javascript onClick question

Javascript JavaScript language (comp.lang.javascript)


Discuss Javascript onClick question in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Mtek
 
Posts: n/a

Default Re: Javascript onClick question - 06-01-2008 , 10:01 PM






On Jun 1, 9:49*pm, Dan Rumney <danrum... (AT) 77617270mail (DOT) net> wrote:
Quote:
Here you go, and thanks!!

function formvalidation(thisform) {
* * if (emptyvalidation(thisform.CustName.value,"Customer Name is
empty")==false) {thisform.CustName.focus(); return false;};
* * if (emailvalidation(thisform.CustEmail.value,"Illegal E-
mail")==false) {thisform.CustEmail.focus(); return false;};

* * if (thisform.CellPhone.value==null || thisform.CellPhone.value==""
|| thisform.CellPhone.value==" ") {
* * * *thisform.CellPhone.value="000-000-0000";
* * } else {
* * * *if (phonevalidation(thisform.CellPhone.value,"Please enter a
valid cell phone")==false) {
* * * * * thisform.CellPhone.focus(); return false;
* * * *};
* * };
* * thisform.submit();
}

Change "thisform.submit()" to "return true"

However, Reading you original post again, you wrote:

*> <a class="save_menu"
*
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
*> * * document.Detail_Screen.submit();">Update</>a

[snip]

*> At the end of the javascript validation routine, we have this:
*
*> thisform.submit();
*
*> So, the form seems to submit, but not the way we want it to. *We want
*> it to execute the validation routine first.

So, I think you're saying "Why isn't validation performed when the user
clicks on Update?"

So, I believe this is an accurate description of what's happening. I've
looked for something to back it up, but all I can find are unreferenced
comments on the web.

The onSubmit Event Handler is is used to execute specified JavaScript
code whenever the *user* submits a form.

I believe the problem you have is that Javascript aclling the submit()
function is *not* the same as the user submitting the form. Thus the
onSubmit handler is not invoked.

In fact, this is why you calling submit() in your onSubmit handler does
not cause an infinite loop.

The resolution would be an explicit call to formvalidation()
... something like:

a class="save_menu"
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
formvalidation(document.Detail_Screen) &&
document.Detail_Screen.submit();">Update</>a>- Hide quoted text -

- Show quoted text -

Wow Dan! Almost perfect. After it displays the error message though,
it opens a blank page with the word 'false' on it. Also, now when it
calls the email validation function, I get an error: "entered.value
has no properties"

function emailvalidation(entered, alertbox) {
apos=entered.indexOf("@");
dotpos=entered.value.lastIndexOf(".");
lastpos=entered.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-
dotpos<2)
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}

Thanks for everyone's help so far.

John



Reply With Quote
  #12  
Old   
Mtek
 
Posts: n/a

Default Re: Javascript onClick question - 06-01-2008 , 10:10 PM






On Jun 1, 9:49*pm, Dan Rumney <danrum... (AT) 77617270mail (DOT) net> wrote:
Quote:
Here you go, and thanks!!

function formvalidation(thisform) {
* * if (emptyvalidation(thisform.CustName.value,"Customer Name is
empty")==false) {thisform.CustName.focus(); return false;};
* * if (emailvalidation(thisform.CustEmail.value,"Illegal E-
mail")==false) {thisform.CustEmail.focus(); return false;};

* * if (thisform.CellPhone.value==null || thisform.CellPhone.value==""
|| thisform.CellPhone.value==" ") {
* * * *thisform.CellPhone.value="000-000-0000";
* * } else {
* * * *if (phonevalidation(thisform.CellPhone.value,"Please enter a
valid cell phone")==false) {
* * * * * thisform.CellPhone.focus(); return false;
* * * *};
* * };
* * thisform.submit();
}

Change "thisform.submit()" to "return true"

However, Reading you original post again, you wrote:

*> <a class="save_menu"
*
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
*> * * document.Detail_Screen.submit();">Update</>a

[snip]

*> At the end of the javascript validation routine, we have this:
*
*> thisform.submit();
*
*> So, the form seems to submit, but not the way we want it to. *We want
*> it to execute the validation routine first.

So, I think you're saying "Why isn't validation performed when the user
clicks on Update?"

So, I believe this is an accurate description of what's happening. I've
looked for something to back it up, but all I can find are unreferenced
comments on the web.

The onSubmit Event Handler is is used to execute specified JavaScript
code whenever the *user* submits a form.

I believe the problem you have is that Javascript aclling the submit()
function is *not* the same as the user submitting the form. Thus the
onSubmit handler is not invoked.

In fact, this is why you calling submit() in your onSubmit handler does
not cause an infinite loop.

The resolution would be an explicit call to formvalidation()
... something like:

a class="save_menu"
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
formvalidation(document.Detail_Screen) &&
document.Detail_Screen.submit();">Update</>a>- Hide quoted text -

- Show quoted text -

Thanks Dan.

When I put your code in and submit the form, I get the validation
error message I am supposed to, but then the page changes with only
the word 'false' on it.

Also, when it executes the routine to validate the email, I get this
"entered.value has no properties"

function emailvalidation(entered, alertbox) {
apos=entered.value.indexOf("@");
dotpos=entered.value.lastIndexOf(".");
lastpos=entered.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-
dotpos<2)
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}

Thanks again for your help.

John


Reply With Quote
  #13  
Old   
Mtek
 
Posts: n/a

Default Re: Javascript onClick question - 06-01-2008 , 10:25 PM



On Jun 1, 9:49*pm, Dan Rumney <danrum... (AT) 77617270mail (DOT) net> wrote:
Quote:
Here you go, and thanks!!

function formvalidation(thisform) {
* * if (emptyvalidation(thisform.CustName.value,"Customer Name is
empty")==false) {thisform.CustName.focus(); return false;};
* * if (emailvalidation(thisform.CustEmail.value,"Illegal E-
mail")==false) {thisform.CustEmail.focus(); return false;};

* * if (thisform.CellPhone.value==null || thisform.CellPhone.value==""
|| thisform.CellPhone.value==" ") {
* * * *thisform.CellPhone.value="000-000-0000";
* * } else {
* * * *if (phonevalidation(thisform.CellPhone.value,"Please enter a
valid cell phone")==false) {
* * * * * thisform.CellPhone.focus(); return false;
* * * *};
* * };
* * thisform.submit();
}

Change "thisform.submit()" to "return true"

However, Reading you original post again, you wrote:

*> <a class="save_menu"
*
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
*> * * document.Detail_Screen.submit();">Update</>a

[snip]

*> At the end of the javascript validation routine, we have this:
*
*> thisform.submit();
*
*> So, the form seems to submit, but not the way we want it to. *We want
*> it to execute the validation routine first.

So, I think you're saying "Why isn't validation performed when the user
clicks on Update?"

So, I believe this is an accurate description of what's happening. I've
looked for something to back it up, but all I can find are unreferenced
comments on the web.

The onSubmit Event Handler is is used to execute specified JavaScript
code whenever the *user* submits a form.

I believe the problem you have is that Javascript aclling the submit()
function is *not* the same as the user submitting the form. Thus the
onSubmit handler is not invoked.

In fact, this is why you calling submit() in your onSubmit handler does
not cause an infinite loop.

The resolution would be an explicit call to formvalidation()
... something like:

a class="save_menu"
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
formvalidation(document.Detail_Screen) &&
document.Detail_Screen.submit();">Update</>a>- Hide quoted text -

- Show quoted text -

Hi Dan,

Your suggestion seems to work. I had to change a few things. But
when I submit the form, it something fails the validation, it gives
the proper error message, but then a new page appears with only the
word 'false' on it........

On another note, I do not understand why sometimes I can refer to a
parameter by name, and other times I need parameter.value.........

Thanks again!!!

John


Reply With Quote
  #14  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Javascript onClick question - 06-02-2008 , 01:33 AM



Peter Michaux wrote:
Quote:
On Jun 1, 4:53 pm, Dan Rumney <danrum... (AT) warpmail (DOT) net> wrote:
FORM name='Detail_Screen' action="savedata.php" METHOD="POST"
onsubmit='return formvalidation(this)'
The problem is that the formvalidation routine is not being fired.
I'm at a loss here. Can anyone help us with this? At the end of the
javascript validation routine, we have this:
thisform.submit();
formvalidation should return TRUE or FALSE, depending on whether the
form's content is valid, or not.

JavaScript will type convert the return value of the onsubmit handler
to be a boolean. [...]
How would you know?


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
  #15  
Old   
Dan Rumney
 
Posts: n/a

Default Re: Javascript onClick question - 06-02-2008 , 10:21 AM



On Jun 1, 11:25 pm, Mtek <m... (AT) mtekusa (DOT) com> wrote:
Quote:
On Jun 1, 9:49 pm, Dan Rumney <danrum... (AT) 77617270mail (DOT) net> wrote:



Here you go, and thanks!!

function formvalidation(thisform) {
if (emptyvalidation(thisform.CustName.value,"Customer Name is
empty")==false) {thisform.CustName.focus(); return false;};
if (emailvalidation(thisform.CustEmail.value,"Illegal E-
mail")==false) {thisform.CustEmail.focus(); return false;};

if (thisform.CellPhone.value==null || thisform.CellPhone.value==""
|| thisform.CellPhone.value==" ") {
thisform.CellPhone.value="000-000-0000";
} else {
if (phonevalidation(thisform.CellPhone.value,"Please enter a
valid cell phone")==false) {
thisform.CellPhone.focus(); return false;
};
};
thisform.submit();
}

Change "thisform.submit()" to "return true"

However, Reading you original post again, you wrote:

a class="save_menu"

href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
document.Detail_Screen.submit();">Update</>a

[snip]

At the end of the javascript validation routine, we have this:

thisform.submit();

So, the form seems to submit, but not the way we want it to. We want
it to execute the validation routine first.

So, I think you're saying "Why isn't validation performed when the user
clicks on Update?"

So, I believe this is an accurate description of what's happening. I've
looked for something to back it up, but all I can find are unreferenced
comments on the web.

The onSubmit Event Handler is is used to execute specified JavaScript
code whenever the *user* submits a form.

I believe the problem you have is that Javascript aclling the submit()
function is *not* the same as the user submitting the form. Thus the
onSubmit handler is not invoked.

In fact, this is why you calling submit() in your onSubmit handler does
not cause an infinite loop.

The resolution would be an explicit call to formvalidation()
... something like:

a class="save_menu"
href="javascript:document.Detail_Screen.action='sa vedata.php?screen=EDIT';
formvalidation(document.Detail_Screen) &&
document.Detail_Screen.submit();">Update</>a>- Hide quoted text -

- Show quoted text -

Hi Dan,

Your suggestion seems to work. I had to change a few things. But
when I submit the form, it something fails the validation, it gives
the proper error message, but then a new page appears with only the
word 'false' on it........
Try:
<a class="save_menu"
href="javascript:function()
{document.Detail_Screen.action='savedata.php?scree n=EDIT';
formvalidation(document.Detail_Screen) &&
document.Detail_Screen.submit();}">Update</a>

Or, better still
<span class="save_menu"
onClick="function(){document.Detail_Screen.action= 'savedata.php?
screen=EDIT';
formvalidation(document.Detail_Screen) &&
document.Detail_Screen.submit();}">Update</span>

Or, style a submit button as Peter suggests...

Quote:
On another note, I do not understand why sometimes I can refer to a
parameter by name, and other times I need parameter.value.........

Probably best to start a new post for that question


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.