Solved

how to do: default select (checked) checkboxes with two checkboxes being disabled greyed out

Posted on 2006-06-30
3
2,045 Views
Last Modified: 2012-08-14
i have the fallowing code
the check all and clear all works fine...trying to get default checked boxes checked with two checkboxes greyed out too

--------------------------------------------------------------
function checkAll(k)
{
var i;
for(i=0;i<k;i++)
    window.document.teacher_search_display1.elements[i].checked=true;
}

function un_checkAll(k)
{
    for(i=0; i<k; i++)
    {
       window.document.teacher_search_display1.elements[i].checked=false;
    }
}

function isitcheck(k)
{
 var i;
 for(i=0;i<k;i++)
  {
    if(window.document.teacher_search_display1.elements[i].checked)
     {
      flag=0;
      break;
      }
      else flag=1;
  }
 if(flag==1)
  {
   alert("Check any one");
   return false;
  }
 }
</script>
<body>
<h3>Player/Guild Info Server - v <? echo _VIBSERVCP ?></h3>
<form name="teacher_search_display1" action="your_action.php" method="post" onSubmit="return isitcheck(20)">
 <Small>  <a href=javascript:checkAll(30)><font color=""#800000"">Check All Fields</font></a> <a href=javascript:un_checkAll(30)> - <font color=""#800000"">UnCheck All Fields</font></a> - <a href=javascript:document.teacher_search_display1.elements[1].checked=true; teacher_search_display1.elements[2].checked=true;teacher_search_display1.elements[3].checked=true;teacher_search_display1.elements[4].checked=true; target = '_self'> - <font color=""#800000"">Check Default Fields</font></a></Small>
<table class="IBlist" valign="top" border="0" cellspacing="0" cellpadding="3" width="375" bgcolor="#ffffe6">
<tr>
       <td class="IBlistHeader">Field</td>
       <td class="IBlistHeader">Info</td>
</tr>
<?

for ($counter=0;$row=mysql_fetch_row($result);$counter++){
  foreach ($row as $key => $value) {
   $field_org = mysql_field_name($result,$key);
   $field = str_replace("_"," ",$field_org);
   ?>
   <td class="IBlistLeft" height="15"><? echo '<input type="checkbox" name="myvals[]" value="'.$field_org.'"> '.ucfirst($field).'<br>'."\n"; ?></td>
   <td class="IBlistRight" height="15"><? echo $value.'<br>'."\n"; ?></td></TR>
   <?
  }
 }
?>

</table>
<SUB><b><Small>Please check off the Info Fields you will allow others to view the information they provide</Small></b></SUB>
<br>
<input type="Submit" value="Submit" name="B1">
<input type="reset" name="B2">
<input type="button" value="Cancel" onClick=javascript:window.location.href="dd.php";>
</form>
--------------------------------------------------------------

heres my problem i want to be able to have a default selected selection for multible fields checkboxes.
Check Default Fields

i tryed to do that but it does not work with the present code...

how do i do that
other question how do i disable checkbox 3 and 7 in the code too

im makeing a checkbox form by pulling the info from mysql fields.. there are about 14 fields for 14 checkboxes..

thanks for any help provide and the example code
0
Comment
Question by:Johnny
3 Comments
 
LVL 30

Assisted Solution

by:callrs
callrs earned 200 total points
ID: 17022821
>>default selected selection for multiple fields checkboxes
Use <body onload=...>
e.g.
<body onload=document.someform.elements[0].checked=true>

>>how do i disable checkbox 3 and 7 in the code too
Meaning that the user can't check them? If so, perhaps use an onclick event to fire off a javascript function that unchecks it...
0
 
LVL 4

Accepted Solution

by:
aaaaaa earned 300 total points
ID: 17023359
<script>
function checkDefault() {
  document.teacher_search_display1.elements[0].checked=true;
  document.teacher_search_display1.elements[1].checked=true;
  document.teacher_search_display1.elements[2].checked=true;
  document.teacher_search_display1.elements[3].checked=true;
}
</script>

<body>
<h3>Player/Guild Info Server - v <? echo _VIBSERVCP ?></h3>
<form name="teacher_search_display1" action="your_action.php" method="post" onSubmit="return isitcheck(20)">
 <Small>  <a href=javascript:checkAll(30)><font color=""#800000"">Check All Fields</font></a> <a

href=javascript:un_checkAll(30)> - <font color=""#800000"">UnCheck All Fields</font></a> -
<a href="#" onclick="checkDefault()"> - <font color=""#800000"">Check Default Fields</font></a></Small>
<table class="IBlist" valign="top" border="0" cellspacing="0" cellpadding="3" width="375" bgcolor="#ffffe6">
<tr>
       <td class="IBlistHeader">Field</td>
       <td class="IBlistHeader">Info</td>
</tr>
<input type="checkbox" name="myvals" value="">
<input type="checkbox" name="myvals" value="">
<input type="checkbox" name="myvals" value="">
<input type="checkbox" name="myvals" value="">

</table>
<SUB><b><Small>Please check off the Info Fields you will allow others to view the information they provide</Small></b></SUB>
<br>
<input type="Submit" value="Submit" name="B1">
<input type="reset" name="B2">
<input type="button" value="Cancel" onClick=javascript:window.location.href="dd.php";>
</form>
0
 

Author Comment

by:Johnny
ID: 17023650
function checkDefault() {
  document.teacher_search_display1.elements[0].checked=true;
  document.teacher_search_display1.elements[1].checked=true;
  document.teacher_search_display1.elements[2].checked=true;
  document.teacher_search_display1.elements[3].checked=true;
  document.teacher_search_display1.elements[4].checked=true;
  document.teacher_search_display1.elements[6].checked=true;
  document.teacher_search_display1.elements[8].checked=true;
  document.teacher_search_display1.elements[10].checked=true;
  document.teacher_search_display1.elements[11].checked=true;
  document.teacher_search_display1.elements[12].checked=true;
  document.teacher_search_display1.elements[13].checked=true;
  document.teacher_search_display1.elements[14].checked=true;
}
</script>
<script>
function checkdisable() {
  document.teacher_search_display1.elements[5].disabled=true;
  document.teacher_search_display1.elements[7].disabled=true;
 document.teacher_search_display1.elements[9].disabled=true;
}
<body onload=checkdisable();>
<a href="#" onclick="checkDefault()"> - <font color=""#800000"">Check Default Fields</font></a> </Small>


all works thanks alot...:)
split points
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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

789 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