Solved

Microsoft JScript runtime error: 'this.form.cboContacts' is null or not an object

Posted on 2004-04-20
6
2,078 Views
Last Modified: 2007-12-19
Hello,

I'm having a spot of bother with an object on my webpage which generates the following error

"Microsoft JScript runtime error: 'this.form.cboContacts' is null or not an object"

I'm developing this in C# and have added Javascript to a hyperlink. In HTML, the link looks like this:

<a id="lnkForgotPassword" title="Click here to receive an email reminder of your password." class="label" onclick="javascript:if(this.form.cboContacts.value != 0) {if(confirm('Proceed with password reminder request?')==false) return false;}" href="javascript:__doPostBack('lnkForgotPassword','')" style="width:184px;">Forgotten your password?</a>

Now the object in question, cboContacts does exist. In HTML its a SELECT/OPTION as follows:

<select name="cboContacts" id="cboContacts" class="label" OnFocus="alert(this.name)" style="height:16px;width:256px;">
      <option selected="selected" value="0"></option>
      <option value="9999">~*~ Admin ~*~</option>
      <option value="1">Surname1, FirstName1</option>
      <option value="2">Surname2, FirstName2</option>
.....
</select>

I added the OnFocus event to see if the object was recognised, and obviously it gave a popup message containing "cboContacts".

I want the hyperlink to test if a value has been selected (other than the empty first option), and if one has to question the user if he wished to continue to receive the email reminder. The href of the hyperlink executes codebehind code which queries the database to obtain the selected users email address and posts them their email.

Why is it failing and how do I fix this?

regards

Brian
0
Comment
Question by:obyapka
6 Comments
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10867778
replace  this.form.cboContacts.value  with  document.getElementById('cboContacts').value
0
 
LVL 7

Expert Comment

by:searlas
ID: 10867800
The reason why is was failing is because anchors are not form objects, and so this.form is not a valid reference in your javascript (i.e. this.form is undefined).
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10867845
Check this:

<a id="lnkForgotPassword" title="Click here to receive an email reminder of your password." class="label" onclick="if(document.forms[0].cboContacts.value != 0) {if(confirm('Proceed with password reminder request?')==false) return false;}" href="javascript:__doPostBack('lnkForgotPassword','')" style="width:184px;">Forgotten your password?</a>


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 63

Accepted Solution

by:
Zvonko earned 300 total points
ID: 10867865
Sorry, the first if condition lets pass the onClick without confirm()

Check this:

<a id="lnkForgotPassword" title="Click here to receive an email reminder of your password." class="label" onclick="if(document.forms[0].cboContacts.selectedIndex>0) {if(confirm('Proceed with password reminder request?')==false) return false;} else return false;" href="javascript:__doPostBack('lnkForgotPassword','')" style="width:184px;">Forgotten your password?</a>


0
 
LVL 1

Author Comment

by:obyapka
ID: 10868082
I just changed the last "else return false;" to the following:

{alert('Select a user name from the list.');return false;}

and it now works a treat.

Many thanks for everyones assistance.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10868100
Thanks for points and feedback.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now