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
LVL 1
obyapkaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ZvonkoConnect With a Mentor Systems 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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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
All Courses

From novice to tech pro — start learning today.