Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2003, 04:09 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default checking boxes

This is mostly javaScript code but because it is a php website thing I thought you guys may be able to help me. I cant find any good javaScript forms, so please have a look at it.

I am pulling severall rows out of a database and each of them have a checkbox, and I am trying to check them automatically when the page loads up.




function loadCheck3(rowID) {



if ("document.f"+rowID+".b"+rowID+".checked == false")

     //alert("document.f"+rowID+".b"+rowID+".checked = true")
     eval("document.f"+rowID+".b"+rowID+".checked = true");

}



I then call the function further down in the page for each row that is pulled from the database




><input type=\"checkbox\" value=\"CHECKED\" name=\"b".$row['id']."\" "?>
onMouseover="loadCheck3 (<? echo $row['id'];?>)"
<? echo " ></form>



It works because if I move the mouse over the box it checks it, my problem is is that I want it to check the box automatically when the page loads.

Anyone know how to do this?

I dont want to just write CHECKED in the input tags because i intend to develop this a little further.


I have tried onLoad but it doesnt work unless it is in the body tags
 
Old July 16th, 2003, 09:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

i haven't checked your code but this is how you can do it:

output your data to browser, make sure you include all <input type=checkbox> within one form for example <form name=myform></form>. then use the following code:

function setCheckedOnLoad() {

   //myform is the name of the form that includes all the checkboxes

   for(i=0;i<document.getElementById("myform").elemen ts.length;i++) {
      if(document.getElementById("myform").elements[i].type == "checkbox")
         document.getElementById("myform").checked = true;
   }
}


then invoke the function using onLoad event handler in <body>

<body onLoad="setCheckedOnLoad()">

peace




the genuine genius





Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Controls and Checking Boxes rstelma ASP.NET 1.0 and 1.1 Professional 1 October 30th, 2007 02:01 PM
checking for any whitespaces furia_cross Javascript How-To 1 September 7th, 2005 05:58 PM
Checking for Null ~Bean~ BOOK: Beginning ASP 3.0 2 June 27th, 2005 07:09 AM
SQL , List Boxes/Menu Boxes, DB's Ginzu3 Classic ASP Databases 1 June 30th, 2003 04:07 AM
Checking for a number aware Classic ASP Basics 5 June 5th, 2003 09:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.