Forum Moderators: coopster

Message Too Old, No Replies

PHP + Javascript(?)

'tick' boxes...

         

ktsirig

4:50 pm on Dec 16, 2005 (gmt 0)

10+ Year Member



Hi all,
I am relatively new in PHP and I have come into a problem, that, I think, is solved by using Javascript

The problem is the following:

I have a form where the user inserts a query, e.g :"Retrieve all tha names of the students".
The next page, which is written in PHP gets the result, e.g: "Nick", "John", "Mary".
What I want to do is to have something like a small box near each name, which the user can tick and then see the student's page for examlpe.
It is sort of a 'select button', and the user can select one or more students to view their pages.

Q1: Is this done with Javascript only or can I use PHP as well?
Q2: Because I don't know anything about Javascript, is there any short code that can do my job easily?

Thanx in advance

ergophobe

5:54 pm on Dec 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll probably need a combination. PHP to get the URL, and JS to make something happen when you click. If you just want to check off the sites using checkboxes, then you would not need JS and the processing of the request would happen when you submit the form.

Let's start with a really simple version. Let's assume that you want list all students and, when someone checks the box, it opens a popup with their page on it.


$student_list = "<form method="post" name="myform" action=""><ul>";

$q = "SELECT id, name, url FROM students";
$r = mysql_query($q);
while ($student = mysql_fetch_assoc($r))
{
$student_list .= '<li><input type="checkbox" name="'. $student['id'] onclick="window.open(\'' . $student['url'] . '\')" /> ' . $student['name'] . '</li>';
}

$student_list .= "</ul></form>";

I don't know whether that gets you part way there, at least conceptually. You will likely want the onclick to call a function that you have defined elsewhere that can do more complex things (like show and hide a screenshot of the page or some such thing).