SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript form woes

    Hi there,

    My Javascript knowledge is low to nil so please excuse my ignorance.

    I am using an <a href to submit a form but as I have multiple forms i want to reuse the function:

    Code:
     <script language="JavaScript"><!--
     function formSubmit($account) {
     	document.lcdc.submit();
     }
     //--></script>
    Clearly the name of the form will change depending on which one is being submitted so I need to replace 'lcdc' with $account. If someone would explain how to go about doing this I'd be immensly grateful.

    Azaar

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    
    function formSubmit($account)
    {
        document.forms[$account].submit();
        return false;
    }
    
    </script>
    <a href="#null" onclick="return formSubmit('lcdc')">submit</a>

    Dollar-sign variable names are legal, but unusual, in JavaScript - probably because of the likelihood of confusion with PHP vars (or Perl scalars, if you've been drinking). Just fyi.

    Using Form.submit() does not call the Form's onsubmit handler, so if you're using it to invoke a validator, you'll need a different approach.
    ::: certified wild guess :::

  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am simple attempting to the form submit, no validator is being used.

    Is the line return false; necessary ? What does it do ?

  4. #4
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This does, by the way, work perfectly.

    Thank you.

    Jack

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you added that last bit....

    http://www.quirksmode.org/js/events_early.html
    ::: certified wild guess :::

  6. #6
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your very comprehensive answer.

    Jack


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
  •