?
Solved

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

Posted on 2006-06-30
3
Medium Priority
?
2,064 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
[X]
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
3 Comments
 
LVL 30

Assisted Solution

by:callrs
callrs earned 800 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 1200 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
Suggested Courses

770 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