parameters not entering function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    #1

    parameters not entering function?

    I keep getting a runtime error stating that this
    document.adddea ler.dealertoadd .value = dealer; is null or not an
    object. I've rewritten the Function everyway I could think of, and
    couldn't find any thread examples of my problem.

    Here is my Function;

    <Script language="JavaS cript">
    <!--//hide
    function AddDealer(deale r) {
    document.adddea ler.dealertoadd .value = dealer;
    document.adddea ler.submit();

    }
    //-->
    </script>

    This calls the Function;

    <input type="button" value="Make This My Dealer"
    onClick="AddDea ler('<%=(iwDeal erCode(x))%>'); " name="button">

    When the code breaks and I bring up Microsoft Debugger it shows a
    value in the parameter. I would appreciate any pointers on this.

    Regards,

    Andrew
  • kaeli

    #2
    Re: parameters not entering function?

    In article <1c2bec22.03112 50737.58189557@ posting.google. com>,
    webmaster@dakot acollectibles.c om enlightened us with...[color=blue]
    > I keep getting a runtime error stating that this
    > document.adddea ler.dealertoadd .value = dealer; is null or not an
    > object. I've rewritten the Function everyway I could think of, and
    > couldn't find any thread examples of my problem.
    >
    > Here is my Function;
    >
    > <Script language="JavaS cript">
    > <!--//hide
    > function AddDealer(deale r) {
    > document.adddea ler.dealertoadd .value = dealer;[/color]

    Where in the code is the text input with the name set to dealertoadd?
    I see one with a name of button. But not
    name="dealertoa dd"
    which is what better be there for the code above to run. :)
    [color=blue]
    > <input type="button" value="Make This My Dealer"
    > onClick="AddDea ler('<%=(iwDeal erCode(x))%>'); " name="button">[/color]

    I'm thinking you named this wrong.

    --
    ~kaeli~
    Suicide is the most sincere form of self-criticism.



    Comment

    • Michael Winter

      #3
      Re: parameters not entering function?

      Andrew wrote on 25 Nov 2003:

      <snip>
      [color=blue]
      > <Script language="JavaS cript">[/color]

      You don't need to use the language attribute, but you *must* use the
      type attribute. Change the above to:

      <SCRIPT type="text/javascript">
      [color=blue]
      > <!--//hide[/color]

      There is no need to hide SCRIPT element contents with SGML comments.
      [color=blue]
      > function AddDealer(deale r) {
      > document.adddea ler.dealertoadd .value = dealer;[/color]

      You don't say it, but it's clear that 'adddealer' is a form and
      'dealertoadd' is a form control. It is better to use this syntax (it
      works across more browsers):

      document.forms['adddealer'].elements['dealertoadd'].value = dealer;

      May I also suggest that you use hyphens (-), underscores (_), or
      capitalisation to make your identifiers more readable. Be aware that
      if you use hyphens, you must use the collection syntax (above) to
      access the element, or it will be interpreted as the subtraction
      operator.
      [color=blue]
      > document.adddea ler.submit();[/color]

      This can be changed, likewise:

      document.forms['adddealer'].submit();
      [color=blue]
      > }
      > //-->[/color]

      You can remove that.
      [color=blue]
      > </script>
      >
      > This calls the Function;
      >
      > <input type="button" value="Make This My Dealer"
      > onClick="AddDea ler('<%=(iwDeal erCode(x))%>'); " name="button">[/color]

      Please don't show server-side elements of your script. They mean
      nothing to us. Instead, indicate what /would/ be there after an
      interpreter has parsed it.

      Couldn't you have found a better name for your button other than
      'button'? Identifiers should have meaningful names. Something like
      'button' can lead to the terrible habit of naming everything
      'button1', 'button2', 'button3', etc.

      The only other things to check (as you didn't show them here), is
      that a form exists with the name, 'adddealer', and a control exists
      with the name, 'dealertoadd'.

      Hope that helps,
      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

      Comment

      • A Lexiewa

        #4
        Re: parameters not entering function?

        Thanks for the enriching reply.

        I've changed my code as you suggested and am still getting the same
        error. I have a hidden form that I forgot to add in my origial post.
        This is what I have now.

        <SCRIPT type="text/javascript">

        function AddDealer(deale r) {
        document.forms['adddealer'].elements['dealertoadd'].value = dealer;
        document.forms['adddealer'].submit();
        }
        </SCRIPT>

        <form name="adddealer " action="registe r2.asp" method="POST">

        <input type="hidden" name="dealertoa dd" value="">
        <input type="button" value="Make This My Dealer"
        onClick="AddDea ler(2479);" name="CustDeale r">

        Thanks again!



        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Lee

          #5
          Re: parameters not entering function?

          Andrew said:[color=blue]
          >
          >I keep getting a runtime error stating that this
          >document.addde aler.dealertoad d.value = dealer; is null or not an
          >object.[/color]

          When asking for help with an error message stating that some
          object doesn't exist, you should include enough code to show
          us that it actually does exist.

          Comment

          • Michael Winter

            #6
            Re: parameters not entering function?

            A Lexiewa wrote on 25 Nov 2003:
            [color=blue]
            > Thanks for the enriching reply.
            >
            > I've changed my code as you suggested and am still getting the
            > same error. I have a hidden form that I forgot to add in my
            > origial post. This is what I have now.[/color]

            <snipped code>

            That's strange, because what you showed* worked in both IE 6 and
            Opera 7.22. Is the error /exactly/ the same as before, or has it
            changed?

            A common problem that people seem to run into is using method names
            as control names - the most common one is calling a submit button,
            'submit'. If there is more to this script than you're showing us,
            check that none of your controls use Form object method names.
            However, if what you showed in your reply is verbatim, then frankly,
            I'm stumped.

            Mike


            * I changed part of your code for testing purposes, namely the action
            and method attribute values, but everything else was the same.

            --
            Michael Winter
            M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

            Comment

            • Lee

              #7
              Re: parameters not entering function?

              A Lexiewa said:[color=blue]
              >
              >Thanks for the enriching reply.
              >
              >I've changed my code as you suggested and am still getting the same
              >error. I have a hidden form that I forgot to add in my origial post.
              >This is what I have now.
              >
              ><SCRIPT type="text/javascript">
              >
              > function AddDealer(deale r) {
              > document.forms['adddealer'].elements['dealertoadd'].value = dealer;
              > document.forms['adddealer'].submit();
              > }
              ></SCRIPT>
              >
              ><form name="adddealer " action="registe r2.asp" method="POST">
              >
              ><input type="hidden" name="dealertoa dd" value="">
              > <input type="button" value="Make This My Dealer"
              >onClick="AddDe aler(2479);" name="CustDeale r">
              >
              >Thanks again![/color]

              When I add just enough HTML to make your posted code functional,
              it works without any error. The problems seems to be in some
              part of the page that you haven't shown us:


              <html>
              <body>
              <SCRIPT type="text/javascript">

              function AddDealer(deale r) {
              document.forms['adddealer'].elements['dealertoadd'].value = dealer;
              document.forms['adddealer'].submit();
              }
              </SCRIPT>

              <form name="adddealer " action="registe r2.asp" method="POST">
              <input type="hidden" name="dealertoa dd" value="">
              <input type="button" value="Make This My Dealer"
              onClick="AddDea ler(2479);" name="CustDeale r">
              </form>
              </body>
              </html>

              Comment

              Working...