473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"object doesn't support this property or method" error

Hello,

I have a function that loops through 2 select lists and records the
values of any hi-lighted options a user would have selected. It then
sets 2 corresponding "hidden" form elements to the values and submits
the form data to the server.

I was error free until I added the following line:

document.myform .submit();

This produces the "object doesn't support this property or method"
error. The troubleshooting steps I have taken are:

1) Confirmed the existance of <form> and </form> tags.
2) Confirmed there is no typo in the form name.
3) Tried changing the form name from "bhd2pib_fo rm" to just "myform".
4) Commented out the suspected offending line of code and I am again
error free, uncomment it, the error comes back.
5) Added a normal "submit" button to test the action and post
attributes of the <form> tag and that works fine.

I am having a hard time believing a simple method call such as
document.myform .submit(); is so difficult to figure out! Please, any
help would be greatly appreciated. The function is pasted below in
it's entirety:

<script type="text/javascript">
function setValues()
{
var bhd_list = document.myform .bhd_headings;
var pib_list = document.myform .pib_headings;

var bhd_values = ''; // String of selected base_heading ids to
map
var pib_value;

for ( i=1; i<bhd_list.opti ons.length; i++ ) {
if ( bhd_list.option s[i].selected ) {
if ( !bhd_values ) {
bhd_values = bhd_values +
bhd_list.option s[i].value;
}
else {
bhd_values = bhd_values + ':' +
bhd_list.option s[i].value;
}
}
}

for ( j=1; j<pib_list.opti ons.length; j++ ) {
if ( pib_list.option s[j].selected ) {
pib_value = pib_list.option s[j].value;
break;
}
}

if ( !bhd_values ) {
alert( "You have to select at least 1 base heading to
map or else this page doesn't make a lot of sense to have." );
}

if ( !pib_value ) {
alert( "You have to select a PIB heading to map to" );
}

// Set values of hidden fields
document.myform .bhd_values.val ue = bhd_values;
document.myform .pib_value.valu e = pib_value;

document.myform .submit(); //this line causes the error
}
</script>

Jul 23 '05 #1
2 3797
SmittyBroham wrote:
Hello,

I have a function that loops through 2 select lists and records the
values of any hi-lighted options a user would have selected. It then
sets 2 corresponding "hidden" form elements to the values and submits
the form data to the server.

I was error free until I added the following line:

document.myform .submit();
I would add your function to the form "onsubmit" event and return
false if your validation fails. Then your submit stays as a
plain submit button.

[...] var bhd_list = document.myform .bhd_headings;
var pib_list = document.myform .pib_headings;
If you pass a reference to the table from the event, you don't
need all those document.myform calls:

<form ... onsubmit="retur n setValues(this) ;" ... >
for ( i=1; i<bhd_list.opti ons.length; i++ ) {
This can be optimised a little as:

var len=bhd_list.op tions.length;
for (var i=0; i<len; i++) {

Use var to keep i local. Getting the length property once is
more efficient and will make a small difference if you have many
options.
if ( bhd_list.option s[i].selected ) {
if ( !bhd_values ) {
bhd_values = bhd_values +
bhd_list.option s[i].value;
}
else {
bhd_values = bhd_values + ':' +
bhd_list.option s[i].value;
This too can be a little more concise:

for ( i=1; i<bhd_list.opti ons.length; i++ ) {
if ( bhd_list.option s[i].selected ) {
if ( !bhd_values == '') bhd_values += ':';
bhd_values += bhd_list.option s[i].value;
}
}

[...] if ( !bhd_values ) {
alert( "You have to select at least 1 base heading to
map or else this page doesn't make a lot of sense to have." );
}
return false here to cancel the submit:

map or else this page doesn't make a lot of sense to have." );
return false
}
if ( !pib_value ) {
alert( "You have to select a PIB heading to map to" );
}
And do the same here

// Set values of hidden fields
document.myform .bhd_values.val ue = bhd_values;
document.myform .pib_value.valu e = pib_value;
Use "theForm" reference here to get rid of document...

theForm.bhd_val ues.value = bhd_values;
theForm.pib_val ue.value = pib_value;

document.myform .submit(); //this line causes the error


This line is no longer needed. The trivial line to add is:

return true;

But that should not be required (but test in lots of browsers
first).

The full script is below, tested in IE and Firefox.

<script type="text/javascript">
function setValues(theFo rm) {
var bhd_list = theForm.bhd_hea dings,
pib_list = theForm.pib_hea dings,
bhd_values = '',
pib_value = '';

var len = bhd_list.option s.length;
for (var i=1; i<len; i++ ) {
if ( bhd_list.option s[i].selected ) {
if ( !bhd_values == '') bhd_values += ':';
bhd_values += bhd_list.option s[i].value;
}
}

var len = pib_list.option s.length
for (var j=1; j<len; j++ ) {
if ( pib_list.option s[j].selected ) {
pib_value = pib_list.option s[j].value;
break;
}
}

if ( bhd_values == '' ) {
alert("You have to select at least 1 base"
+ " heading to map or else this page"
+ " doesn't make a lot of sense to have.");
return false;
}

if ( pib_value == '' ) {
alert("You have to select a PIB heading"
+ " to map to");
return false;
}

// Set values of hidden fields
theForm.bhd_val ues.value = bhd_values;
theForm.pib_val ue.value = pib_value;
}
</script>

--
Rob
Jul 23 '05 #2
Hi Rob,

Using the form's onSubmit action did indeed work. Thanks for your
detailed response!

-Mark

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8925
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input onclick="javaScript:alert('document.forms(0)='+document.forms(0)); parent.myFunc(document.forms(0));" type="button" value="Open" name="Button" ID="Button"> The strange part is that the debug alert says that the document.forms(0) is an object så all seem to be well. But...
6
19943
by: Lauchlan M | last post by:
Hi. Usin ASP.NET, getting an "Object reference not set to an instance of an object" error. In my login.aspx page I have: string arrUserRoles = new string {"UserRole"}; Context.Items.Add("UserRoles", arrUserRoles); Context.User = new
1
5480
by: Kamal | last post by:
I am trying to send mail through smtp. smtp service is running on my machine. But every time during the smtpmail.send(msg) call gives "Could not access 'CDO.Message' object." error. Could some one help me out to resolve this issue. Thanks in advance, Kamal
1
2364
by: Lauchlan M | last post by:
Hi. I'm using ASP.NET, getting an "Object reference not set to an instance of an object" error. In my login.aspx page I have: string arrUserRoles = new string {"UserRole"}; Context.Items.Add("UserRoles", arrUserRoles); Context.User = new
2
2408
by: chuckdfoster | last post by:
I am getting a "Could Not Access CDO.Message Object" Error when I try to use the following code to send an email via ASP.NET. When I run this on one machine it works, on another one it doesn't. Both have VS.NET installed and both have MS Outlook installed. What do I need done to the machine that doesn't work? Or is something wrong with the code? Dim email as New System.Web.Mail.Message email.To = "me@me.com" email.Subject = "Test...
7
3794
by: dhnriverside | last post by:
Hi peeps I'm just following this HOW-TO from MSDN.. http://support.microsoft.com/default.aspx?scid=kb;en-us;306355 But I've got a problem. I've adding the #using System.Diagnostics; line to my cs file, but when I try and type the following line... Exception objErr = Server.GetLastError().GetBaseException();
2
2977
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back to the same page at the top of my form alerting the user that their request has been approved or denied. However, the end result is an error message: Error Message: Object reference not set to an instance of an object.
0
1282
by: piyumi80 | last post by:
hi, i wrote the following code to get a specific data row from the data set.but it generates the "Object reference not set to an instance of an object.".....error private void showClientListForUser() { string fkeys = new string; fkeys = txtUserName.Text; fkeys = txtUserCompanyNumber.Text;
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.