Trying to set a boolean true onClick and another false

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Trying to set a boolean true onClick and another false

Post 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='??'>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hmmm, what have you tried?











Code: Select all

Str = true, Dex = false;
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

hmm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're attempting to set PHP variables from HTML/Javascript. Without a transport between them, that won't happen.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Post 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 -.-
Last edited by Mythic Fr0st on Fri Dec 08, 2006 3:24 pm, edited 1 time in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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>
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post by wyrmmage »

what should be used instead then? (and I thought that I did use php tags around my php code, sry :\ )
-wyrmmage
Post Reply