473,239 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

"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_form" 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.options.length; i++ ) {
if ( bhd_list.options[i].selected ) {
if ( !bhd_values ) {
bhd_values = bhd_values +
bhd_list.options[i].value;
}
else {
bhd_values = bhd_values + ':' +
bhd_list.options[i].value;
}
}
}

for ( j=1; j<pib_list.options.length; j++ ) {
if ( pib_list.options[j].selected ) {
pib_value = pib_list.options[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.value = bhd_values;
document.myform.pib_value.value = pib_value;

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

Jul 23 '05 #1
2 3776
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="return setValues(this);" ... >
for ( i=1; i<bhd_list.options.length; i++ ) {
This can be optimised a little as:

var len=bhd_list.options.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.options[i].selected ) {
if ( !bhd_values ) {
bhd_values = bhd_values +
bhd_list.options[i].value;
}
else {
bhd_values = bhd_values + ':' +
bhd_list.options[i].value;
This too can be a little more concise:

for ( i=1; i<bhd_list.options.length; i++ ) {
if ( bhd_list.options[i].selected ) {
if ( !bhd_values == '') bhd_values += ':';
bhd_values += bhd_list.options[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.value = bhd_values;
document.myform.pib_value.value = pib_value;
Use "theForm" reference here to get rid of document...

theForm.bhd_values.value = bhd_values;
theForm.pib_value.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(theForm) {
var bhd_list = theForm.bhd_headings,
pib_list = theForm.pib_headings,
bhd_values = '',
pib_value = '';

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

var len = pib_list.options.length
for (var j=1; j<len; j++ ) {
if ( pib_list.options[j].selected ) {
pib_value = pib_list.options[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_values.value = bhd_values;
theForm.pib_value.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
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...
6
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"};...
1
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...
1
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"};...
2
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. ...
7
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...
2
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...
0
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.