Solved

simple one?

Posted on 2006-10-24
8
1,590 Views
Last Modified: 2008-02-26
Hi,
As there is no validation for a check box I slid in a Javascript function to check that a checkbox has been checked and to alert the user and stop the form from submitting if they haven't.
Done this many many times in classic ASP but .NET doesn't seem to want to play.
Have a made a syntax error? Is it something to do with all the forms being server-side?

The function:
<script language="javascript" type="text/javascript">
   function AgreeCheck() {
        if(document.form1.ChkAgree.checked = false)
        {
            alert('Please tick the I agree box to continue');
            document.form1.ChkAgree.focus();
            return false;
        }
     }
   </script>

The event:
<form id="form1" runat="server" onsubmit="return AgreeCheck()">

The html server up:
<form name="form1" method="post" action="Default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">

Error:
document.form1.ChkAgree is null or not an object
0
Comment
Question by:QPR
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
can you tell us how you defined the ChkAgree input?
I guess that the issue is case sensitivity...
0
 
LVL 17

Expert Comment

by:xDJR1875
Comment Utility
Is the ChkAgree control within the Form tags?
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
<asp:CheckBox ID="ChkAgree" runat="server" />
Yes inside form tags
0
 
LVL 17

Expert Comment

by:xDJR1875
Comment Utility
Create a hidden field html field to carry the value of the checkbox. Set it when the checkbox is clicked.
Check the value of that field instead of the server control.
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 10

Expert Comment

by:jnhorst
Comment Utility
First fix your operator in the if statement to "==".  Then make sure your form tag is named "form1".  Based on your comment above it looks like your <input type="checkbox"...>, when rendered, may not have a name attribute.  It should render like this (do a View Source to see):

<input type="checkbox" id="ChkAfree" name="ChkAgree".../>

The name part of the name/value pair in an HTML form comes from the name attribute in the input tag.

John
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
changed operator to ==
added name="form1" (visual studio put a squiggle under that but no problem)

Same error null or not an object.
It would be null if unchecked would it? Can you give a checkbox an unchecked value?
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
solved it myself.
I changed the checkbox from an asp server side control to a bog standard html input type.
Now all is fine!
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 0 total points
Comment Utility
PAQing question with points refunded
angelIII, page editor
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

12 Experts available now in Live!

Get 1:1 Help Now