Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 16th, 2005, 10:53 AM   #1
ktsirig
Programmer
 
Join Date: Oct 2005
Posts: 54
Rep Power: 4 ktsirig is on a distinguished road
PHP + Javascript(?)

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
ktsirig is offline   Reply With Quote
Old Dec 16th, 2005, 10:59 AM   #2
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
Well, I think you mean like a box with a checkmark in it. I don't know PHP, but I do know that you can have a checkbox with simply HTML. You can control what it does with PHP I'm guessing, but to make it, all you need to know is HTML.

<form>
<input type="checkbox" name="Nick">
Nick
<br>
<input type="checkbox" name="John">
John
<br>
<input type="checkbox" name="Mary">
Mary
<br>
</form>

This code will put 3 checkboxes with the words Nick, John and Mary beside them. Again, I don't know PHP, so you might want to wait for someone that does, but I think that you can control what happens when these checkboxes are selected with PHP.
MrMan9879 is offline   Reply With Quote
Old Dec 16th, 2005, 11:02 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It's hard to tell precisely what you realize. When you look at a page with PHP and HTML and Javascript intermixed, you are not looking at interactivity; you are looking at plans for constructing a page which will ultimately be sent to the client. The connection will then be dropped. It is a stateless protocol working in a request/response paradigm.

Any information you want to manipulate with Javascript (client-side JS, anyway) has to reside on the client. It may be present in a .js file or explicit inside of script tags or generated on the client. If you want information in the page that reflects the contents of PHP variables, then you have to put it there by one mechanism or another.

Quite often a new request is sent to the server which loads a new page, or reloads the existing page, with the expanded information. Sometimes the full set of information is conveyed in the original page, but hidden until some client-side action is taken. There are also ways of making ancilliary requests without reloading the entire page.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 17th, 2005, 10:01 AM   #4
drifter
Programmer
 
drifter's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia
Posts: 39
Rep Power: 0 drifter is an unknown quantity at this point
Send a message via ICQ to drifter Send a message via MSN to drifter
You'll have to modify this, since this is for an online game we created for class.
But using checkboxes, this is a start on how you can grab just the ones checked and place them on a new page.

<script language="javascript" type="text/javascript">
// global variable to track the number of checkboxes that are checked
var checkCount = 0

// increment or decrement the checkbox counter
function validate(checkbox)
{
	if (checkbox.checked)
	{
		checkCount++
	}
	else
	{
		checkCount--
	}
}

// check that only 1 to 5 characters are checked before posting the form
function submitIt()
{
	if (checkCount > 5 || checkCount < 1)
	{
		alert ("Limit of 5 characters per party.")
	}
	
	return (checkCount <= 5 && checkCount > 0)
}

</script>
*Edited* actually this is for disbanding party members, so you might have to adjust it more than I thought.

Keep in mind you actually have to have your html form call this function.
I can't really give you much more than that, but perhaps there is someone that can help you figure it out with this tidbit of information.

If it helps you at all, you can actually generate PHP script using Javascript for dynamic updates.
Not too sure how you would do that with PHP, or if you can, I am fairly fimilar with PHP, but by no means a guru. lol
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former.
drifter is offline   Reply With Quote
Old Dec 17th, 2005, 10:07 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
generate PHP script using Javascript
Please elucidate as to means and application.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 17th, 2005, 10:24 AM   #6
drifter
Programmer
 
drifter's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia
Posts: 39
Rep Power: 0 drifter is an unknown quantity at this point
Send a message via ICQ to drifter Send a message via MSN to drifter
Quote:
Originally Posted by DaWei
Please elucidate as to means and application.
Well in our case we used it to update statistics based on a choosen class for our game. (Str, Sta, Dex, etc...)

<script type="text/javascript" language="javascript">

strength = new Array;
vitality = new Array;
dexterity = new Array;
agility = new Array;
intelligence = new Array;
wisdom = new Array;

<?php
$sql = "SELECT ID, strength, vitality, dexterity, agility, intelligence, wisdom FROM Class";
$result = @mysql_query($sql,$db)or die(mysql_error());

while ($row = mysql_fetch_array($result))
{
	echo "strength[" . $row['ID'] . "] = " . $row['strength'] . ";\n";
	echo "vitality[" . $row['ID'] . "] = " . $row['vitality'] . ";\n";
	echo "dexterity[" . $row['ID'] . "] = " . $row['dexterity'] . ";\n";
	echo "agility[" . $row['ID'] . "] = " . $row['agility'] . ";\n";
	echo "intelligence[" . $row['ID'] . "] = " . $row['intelligence'] . ";\n";
	echo "wisdom[" . $row['ID'] . "] = " . $row['wisdom'] . ";\n";
}
?>

function updateStats()
{
	document.getElementById("strength").innerHTML = strength[document.charCreate.charClass.selectedIndex + 1];
	document.getElementById("vitality").innerHTML = vitality[document.charCreate.charClass.selectedIndex + 1];
	document.getElementById("dexterity").innerHTML = dexterity[document.charCreate.charClass.selectedIndex + 1];
	document.getElementById("agility").innerHTML = agility[document.charCreate.charClass.selectedIndex + 1];
	document.getElementById("intelligence").innerHTML = intelligence[document.charCreate.charClass.selectedIndex + 1];
	document.getElementById("wisdom").innerHTML = wisdom[document.charCreate.charClass.selectedIndex + 1];
}

</script>

I have to correct that, meaning you can place PHP code within a javascript tag, lol.
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former.
drifter is offline   Reply With Quote
Old Dec 17th, 2005, 10:52 AM   #7
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 218
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
That would be generating Javascript using php

You CAN generate php using javascript if you really wanted, but not on the same page, you'd have to write the php to another file then request that file
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote
Old Dec 17th, 2005, 10:57 AM   #8
drifter
Programmer
 
drifter's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia
Posts: 39
Rep Power: 0 drifter is an unknown quantity at this point
Send a message via ICQ to drifter Send a message via MSN to drifter
eh?
pfft.
LOL
Yea, I am backwards today.
Not much sleep.

Although that last bit is good to know.
__________________
Only two things are infinite, the universe and human stupidity, and im not sure about the former.
drifter is offline   Reply With Quote
Old Dec 17th, 2005, 11:01 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
pfft.
Indeed.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC