Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

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

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
SOLUTION
Avatar of callrs
callrs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny

ASKER

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