Page 1 of 1

Trying to set a boolean true onClick and another false

Posted: Thu Dec 07, 2006 11:44 pm
by Mythic Fr0st
Well I am making 2 buttons

Dex & Str

You click Strength, it sets Str=true and then sets Dex=false

visa versa, how would I do this on a simple HTML button?

IE <input type='button' onclick='??'>

Posted: Thu Dec 07, 2006 11:53 pm
by feyd
hmmm, what have you tried?











Code: Select all

Str = true, Dex = false;

hmm

Posted: Fri Dec 08, 2006 2:00 am
by Mythic Fr0st
I just tried this, it didnt work

Code: Select all

$dexBTN="<input type='button' name='dexBTN' value='Dexterity' onclick=$_SESSION['tstr']=false, $_SESSION['tdex']=true>";

got an error on line 183
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\mythic aeons\homepig.php on line 183

hmmph? any ideas

Posted: Fri Dec 08, 2006 6:46 am
by feyd
You're attempting to set PHP variables from HTML/Javascript. Without a transport between them, that won't happen.

Posted: Fri Dec 08, 2006 3:15 pm
by Mythic Fr0st
how would I transport between them?

would it be better to use javascript for stat system?

(E.G you click new fight, it opens it up, and it calculates your str, blah blah and does def, each click,)

right now this is a glimpse of what im doing

Code: Select all

if ($_SESSION['mba=elf']==true)
{$_SESSION['dexcth']=rand($_SESSION['ML'], $_SESSION['dexlvl'] * 10);
$_SESSION['dexcthelf']=rand($_SESSION['MLelf'], $_SESSION['dexlvlelf'] * 10);
//damage above
$_SESSION['defptmelf']=rand($_SESSION['MLelf'], $_SESSION['deflvlelf'] * 10);
$_SESSION['defptm']=rand($_SESSION['ML'], $_SESSION['deflvl'] * 10);}
$_SESSION['defptmelf']=$_SESSION['defptmelf']/100;
$_SESSION['dexcthelf']=$_SESSION['dexcthelf']/100;
$_SESSION['dexcth']=$_SESSION['dexcth']/100;
$_SESSION['defptm']=$_SESSION['defptm']/100;
thats for calculating dmg from both monsters, I have nearly 300 lines of code with only 2 stats done -.-

Posted: Fri Dec 08, 2006 3:20 pm
by Luke
The standard way is to post to a page (in my example, I just post to the page we're already on) and test the variables that were posted... then set your session variables accordingly.

Code: Select all

<?php
session_start();
if(isset($_POST['dexBTN']))
{
    if($_POST['dexBTN'] == 'Dexterity'){
        $_SESSION['tstr'] = false;
        $_SESSION['tdex'] = true;
    }
    else
    {
        $_SESSION['tstr'] = true;
        $_SESSION['tdex'] = false;
    }
}
?>
<form method="post" action="#">
<input type='hidden' name='dexBTN' value='Dexterity'>
<input type="submit" value="Dexterity">
</form>

<form method="post" action="#">
<input type='hidden' name='dexBTN' value='UnDexterity'>
<input type="submit" value="UnDexterity">
</form>

Posted: Fri Dec 08, 2006 10:03 pm
by wyrmmage
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


yep, I do this:

Code: Select all

<SCRIPT TYPE="text/javascript">
function changeStrength()
{

document.write("<? $_SESSION['str'] = 1; $_SESSION['dex'] = 0; ?>");

}
</SCRIPT>
<?
echo('
<FORM ACTION="somePage.php" METHOD="POST">
<input type='button' name='dexBTN' value='Dexterity' onclick=changeStrength()>";
</FORM>
');
?>
I haven't done this in awhile, but I'm pretty sure that you can hack together something it.
Good luck :)
-wyrmmage


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Dec 08, 2006 10:42 pm
by feyd
That document.write will do absolutely nothing on the client. By the time the user receives that page the session values will already be imprinted.

Posted: Sun Dec 10, 2006 9:59 pm
by wyrmmage
what should be used instead then? (and I thought that I did use php tags around my php code, sry :\ )
-wyrmmage