Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Colorado
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Access A Variable In A Statement

    I've got the following function:

    // function to cancel and return to account display page
    function cancel_form(formName) {
    document.formName.submit();
    }

    And the following function call:

    <input type="button" name="submitIt" value="Cancel" onclick="return cancel_form('customerSuggestion')">

    However, I get the following error when trying to use it:

    Error: 'document.formName' is null or not an object

    How do I get the function to recognize my form's name in the statement? (Without hard-coding it...)

    Thanks for the help!
    You can't win if you don't play!

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.forms[formName].submit();

    comes to mind

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this.form or even form since the browser will assume the keyword this.

    eg:
    Code:
    <script>
    // function to cancel and return to account display page
    function cancel_form(formName) {
    alert(formName.name)
    formName.submit();
    }
    </script>
    </HEAD>
    
    <BODY>
    <form name="form1" action="mailto:">
    <input type="button" name="submitIt" value="Cancel"
    onclick="return cancel_form(this.form)">
    </form>
    
    <form name="form2" action="http://google.com">
    <input type="button" name="submitIt" value="Cancel"
    onclick="return cancel_form(form)">
    </form>
    .....Willy
    Last edited by Willy Duitt; 03-19-2004 at 11:10 PM.

  • #4
    New Coder
    Join Date
    Jul 2002
    Location
    Colorado
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you both for your replies. They both work, and have given me a good piece of advice to use going down the road.
    You can't win if you don't play!


  •  

    Posting Permissions

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