SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    SitePoint Member
    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

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    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
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    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);
    }
    and keep your fingers crossed.

    If all fails, hire someone.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    SitePoint Member
    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

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    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?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    SitePoint Zealot Arkkimaagi's Avatar
    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".

  7. #7
    SitePoint Guru Vincent Puglia's Avatar
    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="">
    is your submit, you will always only get the first Validation.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  8. #8
    SitePoint Member
    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="">
    Only the first function would run, then return true, then submit the form. the second was never called. All three scripts where located in one file. First, the doBoth funciton, then the 1st validation, then the second. Should i split them up into three different files?

    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

  9. #9
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The example is up
    Where?
    And am I getting a subscription to the Washington Post for this?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  10. #10
    SitePoint Guru Vincent Puglia's Avatar
    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
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  11. #11
    SitePoint Member
    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

  12. #12
    SitePoint Guru Vincent Puglia's Avatar
    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?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  13. #13
    SitePoint Member
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •