Good day.!

I thought ive already solve the problem regarding to disable a button. When a variable totalbill is equal to zero the button will be disable, otherwise it will disable if totalbill is not equal to zero.! If totalbill is zero then it will be enable otherwise disable. Whats wrong with the code below:

<?php
		  $totalbill = mysql_real_escape_string($row_reclog['total']);
		if($totalbill==0.00) { $disables="disabled=false"; } else { $disables="disabled=true"; }
           echo "<Input type='button' name='button' value='Enroll Now' $disables >";
?>

Thank you very much ! Please help

I have tested it and I think it's a html syntax error. This works for the Opera browser:

<?php
$totalbill = mysql_real_escape_string($row_reclog['total']);
if($totalbill==0.00) { $disables=""; } else { $disables=" disabled"; }
echo "<input type='button' name='button' value='Enroll Now'$disables>";
?>

I have tested it and I think it's a html syntax error. This works for the Opera browser:

<?php
$totalbill = mysql_real_escape_string($row_reclog['total']);
if($totalbill==0.00) { $disables=""; } else { $disables=" disabled"; }
echo "<input type='button' name='button' value='Enroll Now'$disables>";
?>

Ive changed my code to someting like this. Ive store the string to compare in a session not an integer. But just like the same, it does not work again.pls help. heres my code.

<?php
		 
 if ($_SESSION['MM_enrolltype']=="block") { 
    $disables =""; } 
 else { 
$disables ="disabled"; }
		  
echo "<input type='submit' name='Submit' value='Enroll Now' $disables />";
?>

I dont really know whats wrong with the code. My browser is also opera

Thank you for helping everyone.!

Would this be the answer:

<?php
session_start();
//above line (session_start) must be at the very top.
$_SESSION['MM_enrolltype']='block';
 
 if ($_SESSION['MM_enrolltype']=="block") { 
    $disables =""; } 
 else { 
$disables ="disabled"; }
 
echo "<input type='submit' name='Submit' value='Enroll Now' $disables />";
?>

Would this be the answer:

<?php
session_start();
//above line (session_start) must be at the very top.
$_SESSION['MM_enrolltype']='block';
 
 if ($_SESSION['MM_enrolltype']=="block") { 
    $disables =""; } 
 else { 
$disables ="disabled"; }
 
echo "<input type='submit' name='Submit' value='Enroll Now' $disables />";
?>

I have already changed the code but i dont know why it does not work. Ive also tried to add something to it but it fails to run.here is the code:

<?php
session_start();		  
 $_SESSION['MM_enrolltype']="block";
session_register( $_SESSION['MM_enrolltype']);
		  
 if ($_SESSION['MM_enrolltype']=="block") { 
$disables ="disabled"; } 
else { 
$disables =""; }
echo "<input type='submit' name='Submit' value='Enroll Now' $disables />";
?>

Pls help.!! Thank you.!

The line session_register( $_SESSION['MM_enrolltype']); does not need to be used in the way it is used because from what I have read in the documentation, it makes a variable a global variable and $_session's are allready global. So there is no need to use that line in this case and just as a note, the function session_register() has been depreciated which means in php version 6.0.0 that function will nolonger exist since global variables were proven to be so insecure. So I would recommend removing that line.

thank you for the information sir.but still the code fails to run.
What should i do this.?Pls help.! other said i could use javascript instead but i dont know how.here is my code.

<?php
		  
		  $_SESSION['MM_enrolltype']="block";
		  if ($_SESSION['MM_enrolltype']=="block") { 
		  $disables ="disabled"; } 
		  else { 
		  $disables =""; }
		  
          echo "<input type='submit' name='Submit' value='Enroll Now' $disables />";
?>

Well at the moment your code should should be as follows if you want to use php:

<?php
session_start();
//above line (session_start) must be at the very top.
 
if ($_SESSION['MM_enrolltype']=="block") { 
    $disables =""; } 
else { 
$disables ="disabled"; }
 
echo "<input type='submit' name='Submit' value='Enroll Now' $disables />";
?>

Then if you want to use javascript to hide the button instead of having to wait for the page to load then there is a script at http://www.winfolinx.com/tips/howto/various/hidetext.htm which shows your code would look like the following:

<script language="JavaScript">
var buttonstatus = 'off';
function changebuttonstatus() {
if (buttonstatus=='off')
    {
    buttonObject1.style.display='none';
    buttonObject2.style.display='inline';
    buttonstatus = 'on';
    } else {
    buttonObject1.style.display='inline';
    buttonObject2.style.display='none';
    buttonstatus = 'off';
    }
}
</script>

<style>
#buttonObject1 {display:none}
</style>
<a href="javascript:changebuttonstatus()">Change button status</a>
<p>
<div id="buttonObject1">
<input type='submit' name='Submit' value='Enroll Now' disabled />
</div><div id="buttonObject2">
<input type='submit' name='Submit' value='Enroll Now' />
</div>

Note: the second code box has no php.

thank you for your advise sir.!

but can i just put a variable in javascript that holds the data block and unblock. If varname="block" buttonstatus="off" else buttonstatus="on".

but how can it be done in javascript.?

If you are talking about to put the php variable into the javascript code then the following will do the job:

<?
session_start();
/* then more php code
 * $_SESSION['MM_enrolltype'] should = 'block' or 'unblock'
 */




$_SESSION['MM_enrolltype']='block';
?>
<script language="JavaScript">
var buttonstatus = '<? echo $_SESSION['MM_enrolltype']; ?>';
function changebuttonstatus() {
if (buttonstatus=='block')
    {
    buttonObject1.style.display='none';
    buttonObject2.style.display='inline';
    buttonstatus = 'unblock';
    } else {
    buttonObject1.style.display='inline';
    buttonObject2.style.display='none';
    buttonstatus = 'block';
    }
}
</script>
 
<style>
<?
if ($_SESSION['MM_enrolltype']=='block') {
    echo "#buttonObject2 {display:none}";
    } else {
    echo "#buttonObject1 {display:none}";
    }
?>
</style>
<a href="javascript:changebuttonstatus()">Change button status</a>
<p>
<div id="buttonObject1">
<input type='submit' name='Submit' value='Enroll Now' disabled />
</div><div id="buttonObject2">
<input type='submit' name='Submit' value='Enroll Now' />
</div>
<?




//more php code
?>
commented: very helpful, very good.! +1

@Blocker: You keep saying it doesn't run. What does that mean exactly? PHP errors? Or does it always disable the button? Does it never disable the button? It helps to be as specific as possible.

thank you for the reply.it really helps me.but im so confused on the java coding part..I cannot find find the function disabled which is passed on the button property.

Is there any process to do the job more accurately.?

Thank you sir!

@Blocker: You keep saying it doesn't run. What does that mean exactly? PHP errors? Or does it always disable the button? Does it never disable the button? It helps to be as specific as possible.

I dont know but it keeps the button diabled even if the session variable is unblock.

I dont know but it keeps the button diabled even if the session variable is unblock.

I have checked my samples and they all seem to work which makes me wonder if your session is really being set to unblock. Because when for example running the page with the following code, the button will not be disabled:

<?
session_start();
/* then more php code
 * $_SESSION['MM_enrolltype'] should = 'block' or 'unblock'
 */
 
 
 
 
$_SESSION['MM_enrolltype']='unblock';
?>
<script language="JavaScript">
var buttonstatus = '<? echo $_SESSION['MM_enrolltype']; ?>';
function changebuttonstatus() {
if (buttonstatus=='block')
    {
    buttonObject1.style.display='none';
    buttonObject2.style.display='inline';
    buttonstatus = 'unblock';
    } else {
    buttonObject1.style.display='inline';
    buttonObject2.style.display='none';
    buttonstatus = 'block';
    }
}
</script>
 
<style>
<?
if ($_SESSION['MM_enrolltype']=='block') {
    echo "#buttonObject2 {display:none}";
    } else {
    echo "#buttonObject1 {display:none}";
    }
?>
</style>
<a href="javascript:changebuttonstatus()">Change button status</a>
<p>
<div id="buttonObject1">
<input type='submit' name='Submit' value='Enroll Now' disabled />
</div><div id="buttonObject2">
<input type='submit' name='Submit' value='Enroll Now' />
</div>
<?
 
 
 
 
//more php code
?>

So to check if this is the case, just place echo $_SESSION['MM_enrolltype']; at the end of the page and see what that variable is really set to when you embed the above script into your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.