• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2090
  • Last Modified:

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

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
obyapka
Asked:
obyapka
1 Solution
 
GwynforWebCommented:
replace  this.form.cboContacts.value  with  document.getElementById('cboContacts').value
0
 
searlasCommented:
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
 
ZvonkoSystems architectCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ZvonkoSystems architectCommented:
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
 
obyapkaAuthor Commented:
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
 
ZvonkoSystems architectCommented:
Thanks for points and feedback.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now