SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
-
Aug 21, 2003, 10:04 #1
- Join Date
- Apr 2003
- Location
- Maryland
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
can you call a function from inside a script?
I am trying to piece together a bit of form validation. I can not get the two scripts to work together via onsubmit. CardVal works onclick and DataVal works onsubmit.
1. first i tried to call the CheckCardNumber(this.form) from inside the DataValidation.js after it returned true. Is that even possible? I could not figure it out...
2. i tried inserting this into the <form> tag:
onsumbit="return (subform_validator(this) && CheckCardNumber(this.form));"
is that even possible? my javascript skills are not exactly expert so forgive me if i have overlooked something extremely simple...
DataValidation.js
http://www.simeons.net/twtdesigns/ht...aValidation.js
CardValidation.js
http://www.simeons.net/twtdesigns/ht...dValidation.js
Form
http://www.simeons.net/twtdesigns/html05/start.htm
thanks,
Simeon
-
Aug 21, 2003, 10:25 #2
- Join Date
- Jun 2001
- Location
- Before These Crowded Streets
- Posts
- 9,446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you are using Mozilla or Firebird, you can look at the javascript console and see if any errors are being returned. Those usually help me debug js scripts.
Aaron
-
Aug 21, 2003, 13:06 #3
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Maybe it's a bad day for me... I haven't looked at the *.js files, so I have no idea what they validate and I really don't think I want to know.
if your skills are up to it, combine the two validations and call them from one source. Pay attention to anything that is global, eg: i, counter, formname, etc. etc. Make sure that both scripts are not attempting to use same named variables/functions
If your skills are not that good, create a function that calls the 2 in turn and returns a boolean and submit based on that boolean.Code:function doBoth() { if (firstValidation() ) retVal = secondValidation() else retVal = false; return (retVal); }
If all fails, hire someone.
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Aug 21, 2003, 16:23 #4
- Join Date
- Apr 2003
- Location
- Maryland
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Vinny,
i tried the second option. The function doBoth() will run through firstValidation, but send the form after completion of that function. Any ideas on why it won't start with secondValidation after completing first?
i looked for repeat variables and such. there are none. thanks for the advice.
simeon
-
Aug 22, 2003, 16:11 #5
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi simeon,
what do the validations do? Are either of them returning anything other than a boolean? Why are you using 2 validations?
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Aug 23, 2003, 06:55 #6
- Join Date
- Mar 2002
- Location
- Lappeenranta, Finland
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Vincent, it seems that he's using some ready component to check for form fields, and then another function to check if other stuff is ok.
Also, both of these return boolean value and the form gets submitted if the first one is "true" when he wants them both to be "true".
-
Aug 24, 2003, 09:33 #7
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
As long as this:
Code:<form onsubmit="return subform_validator(this);" name="subform" method="post" action="">
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Aug 25, 2003, 05:36 #8
- Join Date
- Apr 2003
- Location
- Maryland
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Vinny,
I tried writing out the function you mentioned before. then i rewrote the form tag like this:
Code:<form onsubmit="return doBoth(this);" name="subform" method="post" action="">
Arkkimaagi basically summed up what the validations both do. One script makes sure that the billing and address info form fields contain valid information. The second makes sure that the credit card information is valid. i could not find a script that did both so, i tired to merge two.
The example is up so you can see the functionality of both scripts. One coincides with the onsubmit, and one is tied to an onclick event.
Thanks for the help,
simeon
-
Aug 25, 2003, 12:00 #9
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The example is up
And am I getting a subscription to the Washington Post for this?
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Aug 25, 2003, 12:13 #10
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
from what I gather from the form, you have to buttons: validateCards and submit (which validates the fields) Do either of them return false at any point?
you want the Card to be validated first; then the fields. Easiest way: set up a global var
var isOk = true;
then validate the card:
function cardValidation(cardno)
{
...validation code...
if (validation fails) isOk = false;
}
validate form fields
function formValidation(formobj)
{
if (!isOk) return false;
....validation code...
}
it's ugly, but it works
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Sep 3, 2003, 08:06 #11
- Join Date
- Apr 2003
- Location
- Maryland
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Vinny,
i have not had a chance to work on this for awhile, but thanks for the idea. i don't think i am going to get this complicated client side.
thanks again,
simeon
-
Sep 3, 2003, 11:23 #12
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi simeon,
guess that means no Post, huh?
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Sep 3, 2003, 11:38 #13
- Join Date
- Apr 2003
- Location
- Maryland
- Posts
- 21
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hehe sorry vinny ... no post ... because this project is for the washington times. if i was able to get you a subscription i would. i do not think i have that kind of pull with this project.
thanks for all the help,
simeon
Bookmarks