Solved

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

Posted on 2006-06-30
3
2,029 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
Comment Utility
>>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
Comment Utility
<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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now