Jump to content

disabled variable not work.


mmarif4u

Recommended Posts

Hi guys,

 

I have a simple function where i check that the user enter to the user area of my site,

But that user have package, there are different package in my site.

When user login he see 4 buttons, i want to disable 3 buttons there, only

1 will work for that user.

Ok now the problem is that make this function but it just show the disabled text on the button,

Still allow the user to use all buttons.

 

Code:

$sql="select * from m_package";
$query = mysql_query($sql) or die (mysql_error());
$package = $row -> nrpackage;
if ($package = $session_nrpackage){
 $disabled = 'disabled = "disabled" ';
}
else{
 $disabled = "";
} 


<input type="button" onclick="redirect_selection(1);" value="Selection by Set<?php echo $disabled ?>" name="btnset" class="button_assess">

 

Any help will be appreciated.

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/41096-disabled-variable-not-work/
Share on other sites

to make a button disabled in HTML you have to set the attribute to that object.

 

for example

 

<input type="button" value="Click Me" disabled>

this will create a button with the wording "Click Me" but it will be disabled, if you remove the disabled attribute then then button will be active.

 

I notice on your code you have the disabled attribute within quotes in the value attribute. that will cause the attribute to be printed in the button.

 

<input type="button" onclick="redirect_selection(1);" value="Selection by Set<?php echo $disabled ?>" name="btnset" class="button_assess">

 

Remove the quotes and that should work :)

Thanks flappy_warbucks.

Yes u are right that i put the php block in value attribute and it wont work, So

i edit the code according to ur situation but still the problem is the same.

Now i make a simple code which is as follows:

Code:

$query = "SELECT * FROM accdtl where icnumber = 123456-00-0012";
$result = mysql_query($query) or die(mysql_error());
$ic=$row->icnumber;
if ($ic == 123456-00-0012) {
     $disabled = 'disabled = "disabled"';
     }
else{
     $disabled = "";
     }

<form>
<input type="button"  onClick="window.print()" value="Print" <?php echo $disabled ?> >

</form>

I am confused bcoz still the button works on click.

Can i use javascript, but i dont want to use it.

Any help will be appreciated

Thanks.

This is now my modified page but still its not working.

 

Any suggestions.

 

<?php
$con = mysql_connect("localhost","root","adil");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("db", $con);
$query = "SELECT * FROM accdtl where icnumber='123456-00-0012'";
$result = mysql_query($query) or die(mysql_error());
$ic=$row->icnumber;
if ($ic == '123456-00-0012') {
     $disabled = "disabled";
     }
else{
    $disabled = "";
   }
echo "<table class='text' align=Center CELLSPACING='0'BORDERCOLOR='#007FFF' BGCOLOR='cornsilk' border='1'>
<tr><th colspan=12><Font face='Verdana'size='3'>Official Receipt</th></Font>
<tr>
<th><Font size='1'>Customer IC</th></Font>
<th><Font size='1'>Acc Code</th></Font>
<th><Font size='1'>Active</th></Font>
<th><Font size='1'>Date</th></Font>
</tr></tr>";while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo"<td>" . $row['icnumber'] . "</td></font>";
  echo "<td>" . $row['acccode'] . "</td></font>";
  echo "<td>" . $row['active'] . "</td></font>";
  echo "<td>". $row['date'] . "</td></font>";     
  echo "</tr>";
  }
echo "</table>";mysql_close($con);
echo '
<form>
<input type="button"  onClick="window.print()" value="Selection by Set"  '.$disabled.' >
</form> 
'; 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.