Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-30
3
Medium Priority
?
2,074 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

636 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