• Javascript code snipet running multiple times

    Home » Forums » Developers, developers, developers » Web design and development » Javascript code snipet running multiple times

    Author
    Topic
    #379716

    If the user enters a valid e-mail address the first time, all is well. But if the script runs through the Validate() code multiple times, then the prompt for their name is shown multiple times. Any guidance is greatly appreciated! Attached is a portion of the code.

    Thanks,
    Kathy

    Viewing 0 reply threads
    Author
    Replies
    • #633167

      Hi Kathy,

      Try adding “var” to your username line…

      var UserName = prompt(“Please enter your first and last name”, “”);

      Do you also need to check to make sure a valid username is entered?

      If so, you’ll want to have a similar validation for the Username prompt. Of course, I’m guessing the email is required and the username is just for convenience.

      I’m curious – why not just use an HTML form instead of javascript input boxes? You can still use javascript to validate the form values, but it seems a little less intrusive to the user that way… (just my 2 cents 2cents) For an example, check out http://JohnstonData.com/contact.asp%5B/url%5D. Try changing the Reason for Contact to “Request Price Quote” and submit with a blank name or email… Javascript catches that and requires a name and email depending on which Reason is selected.

      Hope this helps

      (By the way – I’m in Indy. I was down to Bloomington to visit a friend last weekend. Small world!)

      • #633172

        Mark,
        You’ve helped me before — how cool that you’re in Indy. BTW, I like your form design!

        Adding VAR didn’t keep the code from repeating. I would have thought the code below Validate(MailAddress) wouldn’t fire until the variable MailAddress passed the validation routine. And you’re right, the user name is for convenience; we can actually tell who it is by the internal e-mail address.

        I’m pulling information from a database via ASP and adding JavaScript just to get the user’s e-mail address. Everything else is ASP.

        Thanks!
        Kathy

        • #633180

          Ahh – I see. I misunderstood from the original post.

          I’ll see if I can come up with a fix to the current process.

          In the meantime, I’m sure there are a few other Loungers that are much more JavaScript savvy than myself…

        • #633278

          OK – How’s this (see attachment)?

          It’s a little different approach, but seems to accomplish the task.

          Post back if it’s not what you need… smile

          • #633479

            Mark,
            Works like a charm! Thank you so very much for your help!!

            Kathy

    Viewing 0 reply threads
    Reply To: Javascript code snipet running multiple times

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: