Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

simple one?

Posted on 2006-10-24
8
1,604 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 143

Expert Comment

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

Expert Comment

by:Daniel Reynolds
ID: 17799337
Is the ChkAgree control within the Form tags?
0
 
LVL 29

Author Comment

by:QPR
ID: 17799434
<asp:CheckBox ID="ChkAgree" runat="server" />
Yes inside form tags
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 17799570
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
 
LVL 10

Expert Comment

by:jnhorst
ID: 17799795
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
ID: 17800550
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
ID: 17800557
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 143

Accepted Solution

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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