Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having problems submitting a form using javascript 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
I have this script
Code:
<script type="text/javascript">
function RemCharge(id,code,desc,rate,qty,units,amount) {
	var agree = confirm('You have requested to remove following entry:\n Code: ' + code + '\nDesc: ' + desc + '\n Qty: ' + qty + '\n    : ' + units + '\nAmnt: ' + amount + '\n\nARE YOU SURE YOU WANT TO REMOVE THIS ENTRY?');
	if (agree)
	{
		document.getElementById('submitID').value='Remove';
		document.getElementById('remidID').value=id;
		document.AddCharge.submit();
	}
}
</script>

and I am getting an error
Code:
document.AddCharge.submit is not a function

AddCharge is the name of my form
Code:
<form name="AddCharge" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" cellpadding="0" cellspacing="0">

I admit that is has been a very long day but I really cannot see the reason to this error. I even found some pages sampling this type of code and they worked OK but not within my page.

What am I doing wrong?

Thanks!

 
[0] The line
[tt] document.AddCharge.submit();[/tt]
by itself is just fine. Error may be thrown though mainly for two page structure related causes.

[1] Either you have more than one form named AddCharge; in that case, index should be nneded such as:
[tt]
document.forms[0].submit(); //independent of name, index 0 for first form.
[/tt]
or if you want to use index associated with AddCharge, it is this.
[tt]
if (document.AddCharge.length>1) {
document.AddCharge[0].submit(); //for first form of that name
} else {
document.AddCharge.submit();
}
[/tt]
[2] Or, most likely the case, is that you have a submit button named "submit", you have to change it to some other name to avoid the collision.
[tt]
<form name="AddCharge" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<!-- etc etc -- and somewhere a submit button... -->
<!-- <input type="submit" name="[red]submit[/red]" /> -->
<!-- change it to someother name -->
<input type="submit" name="someothername" />
<!-- etc etc... -->
</form>
[/tt]
The latter ([2]) seems more probably be the cause.
 
A third possibility is that the form isn't actually named AddCharge.

You need to show your form HTML for us to know for sure what the problem is.

Lee
 
Changing the name did it ... Who knew?

Thank you guys !!! tsuji you get the start :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top