Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 1st, 2005, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default checkbox ( control )

I want to use following code in asp header and body.
this is work when field type text box.
how can I control user to click check box otherwise
if user not check the check box it should display message.
and stay same page.

I use fourteen checkbox in the asp page.

<head>
<script language="JavaScript">
function docheck()
{
for (i=0;i<=13;++i)
 {
 x=document.forms[0].elements[i].value
 n=document.forms[0].elements[i].name

 if (i==0)
  {
  s0=document.forms[0].elements[i].value
    if (s0=="")
   {
   alert ("Please click the checkbox checked")
   document.forms[0].elements[i].focus()
   return false;
   }
  }
}
}
</script>
</head>
<body>
<form method=post action="http://dcilweb/DCILDepts/confview2.asp" id=myform name=myform onSubmit="return docheck()">


<table>
        <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT id=checkbox1 type=checkbox name="checkbox1" value="Target Zero Tolerance">
            </div></td>
        </tr>
        <tr>
          <td colspan="3">5.
            Defensive Driving</td>
          <td><div align="center">
              <INPUT id=checkbox5 type=checkbox name=checkbox5 value="Defensive Driving">
              </div></td>
        </tr>
...
....

<INPUT type="submit" value="Confirm" id=submit12 name=submit12 title="Confirm">
</body>


when user move to this page, focus should be checkbox.
there are fourteen checkbox in this page.

how can control the user without click the checkbox it not
move to next page ?

if user check the check box then move to next page
otherwise it stay same page how ?
what changing in above coding.
user can select more then one check box.

I have to write fourteen time check box focus lines
ie

if (s1=="") then do this
if (s2=="") then do this
....
...

Please help to write the java coding.

regads.

Mateen






 
Old January 2nd, 2005, 06:42 AM
Authorized User
 
Join Date: Sep 2004
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to nashnash
Default

Hi

Please copy and paste and try this is just sample i hope this will solve your purpose if not please let me know..

---
<head>
<script language="JavaScript">
function docheck()
{
    var chkFlag=false;
    for (var i=1;i<=14;++i)
 {
    n="checkbox"+i;
    if (document.getElementById(n).checked)
    {
        chkFlag=true;
    }

}
    if(chkFlag==false)
    {
        alert("Please check one of the checkBox");
        return(false);
    }
}
</script>
</head>
<body>
<form method=post action="http://dcilweb/DCILDepts/confview2.asp" name=myform>


<table>
        <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance1</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox1" value="Target Zero Tolerance1">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance2</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox2" value="Target Zero Tolerance2">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance3</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox3" value="Target Zero Tolerance3">
            </div></td>
        </tr>

         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance4</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox4" value="Target Zero Tolerance4">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance5</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox5" value="Target Zero Tolerance5">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance6</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox6" value="Target Zero Tolerance6">
            </div></td>
        </tr>

         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance7</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox7" value="Target Zero Tolerance7">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance8</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox8" value="Target Zero Tolerance8">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance9</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox9" value="Target Zero Tolerance9">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance10</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox10" value="Target Zero Tolerance10">
            </div></td>
        </tr>

        <tr>
          <td colspan="3">5. Defensive Driving11</td>
          <td><div align="center">
              <INPUT id=checkbox5 type=checkbox name="checkbox11" value="Defensive Driving11">
              </div></td>
        </tr>


 <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance12</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox12" value="Target Zero Tolerance12">
            </div></td>
        </tr>
         <tr>
          <td colspan="3"><div align="left"><strong>1. Target Zero Tolerance13</strong></div></td>
          <td width="11%"> <div align="center">
              <INPUT type=checkbox name="checkbox13" value="Target Zero Tolerance13">
            </div></td>
        </tr>

        <tr>
          <td colspan="3">5. Defensive Driving14</td>
          <td><div align="center">
              <INPUT type=checkbox name="checkbox14" value="Defensive Driving14">
              </div></td>
        </tr>
<INPUT type="submit" value="Confirm" name=submit12 title="Confirm" onclick="return docheck();">
</form>
</body>


------------------

Regards
Nash

 
Old January 2nd, 2005, 07:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot.

checkbox control is very good.

regards.

Mateen








Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox control and bit field keyvanjan ASP.NET 1.0 and 1.1 Basics 2 September 6th, 2006 05:09 PM
Checkbox server control whiterainbow ASP.NET 1.0 and 1.1 Professional 3 November 27th, 2005 02:30 AM
binding an tinyint to a CheckBox control... ShadowMoon ADO.NET 0 October 26th, 2004 05:55 AM
checkbox in grid control rahilahmed Excel VBA 0 May 12th, 2004 02:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.