470,647 Members | 1,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

parameters not entering function?

I keep getting a runtime error stating that this
document.adddealer.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="JavaScript">
<!--//hide
function AddDealer(dealer) {
document.adddealer.dealertoadd.value = dealer;
document.adddealer.submit();

}
//-->
</script>

This calls the Function;

<input type="button" value="Make This My Dealer"
onClick="AddDealer('<%=(iwDealerCode(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
Jul 20 '05 #1
6 1959
In article <1c**************************@posting.google.com >,
we*******@dakotacollectibles.com enlightened us with...
I keep getting a runtime error stating that this
document.adddealer.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="JavaScript">
<!--//hide
function AddDealer(dealer) {
document.adddealer.dealertoadd.value = dealer;
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="dealertoadd"
which is what better be there for the code above to run. :)
<input type="button" value="Make This My Dealer"
onClick="AddDealer('<%=(iwDealerCode(x))%>');" name="button">


I'm thinking you named this wrong.

--
~kaeli~
Suicide is the most sincere form of self-criticism.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
Andrew wrote on 25 Nov 2003:

<snip>
<Script language="JavaScript">
You don't need to use the language attribute, but you *must* use the
type attribute. Change the above to:

<SCRIPT type="text/javascript">
<!--//hide
There is no need to hide SCRIPT element contents with SGML comments.
function AddDealer(dealer) {
document.adddealer.dealertoadd.value = dealer;
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.
document.adddealer.submit();
This can be changed, likewise:

document.forms['adddealer'].submit();
}
//-->
You can remove that.
</script>

This calls the Function;

<input type="button" value="Make This My Dealer"
onClick="AddDealer('<%=(iwDealerCode(x))%>');" name="button">


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.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #3
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(dealer) {
document.forms['adddealer'].elements['dealertoadd'].value = dealer;
document.forms['adddealer'].submit();
}
</SCRIPT>

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

<input type="hidden" name="dealertoadd" value="">
<input type="button" value="Make This My Dealer"
onClick="AddDealer(2479);" name="CustDealer">

Thanks again!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
Lee
Andrew said:

I keep getting a runtime error stating that this
document.adddealer.dealertoadd.value = dealer; is null or not an
object.


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.

Jul 20 '05 #5
A Lexiewa wrote on 25 Nov 2003:
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.


<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.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #6
Lee
A Lexiewa said:

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(dealer) {
document.forms['adddealer'].elements['dealertoadd'].value = dealer;
document.forms['adddealer'].submit();
}
</SCRIPT>

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

<input type="hidden" name="dealertoadd" value="">
<input type="button" value="Make This My Dealer"
onClick="AddDealer(2479);" name="CustDealer">

Thanks again!


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(dealer) {
document.forms['adddealer'].elements['dealertoadd'].value = dealer;
document.forms['adddealer'].submit();
}
</SCRIPT>

<form name="adddealer" action="register2.asp" method="POST">
<input type="hidden" name="dealertoadd" value="">
<input type="button" value="Make This My Dealer"
onClick="AddDealer(2479);" name="CustDealer">
</form>
</body>
</html>

Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by | last post: by
reply views Thread by Xah Lee | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.