SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit button not working after calling script

    i have a normal form validation script
    function validate()
    {
    if (document.Form1.name.value =="")
    {
    alert("Enter name.....")
    document.getElementById('name).focus()
    return false;

    }
    return true;
    }
    and on submit button i have called the script
    onclick="javascript:return validate();"

    as long as the fields are empty i get the proper alerts , but i am not able to click on submit
    even if i click nothing happens
    if i remove onclick="javascript:return validate();" i am able to click it

  2. #2
    SitePoint Member
    Join Date
    May 2009
    Location
    London
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.getElementById('name).focus()
    you are missing ' around name. also, if you have id="name" and name="name", why do you refer to it via document.Form1.name and then by getElementById?

    also, you may want to move the validation away from the click event, people may press their enter key, which will trigger a form submit w/o calling your function first.

    do onsubmit= on the form instead or better yet, in a window.onload, do form.onsubmit = function() { ... } and don't leave any inline js in your code.


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
  •