Solved

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

Posted on 2004-04-20
6
2,075 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

708 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