• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

How can i disable an HTML button in a PHP Code?

How can i disable an HTML button in a PHP Code?

=== Start of my code

some code...
some other code...

      $GLOBALS['error']             = 1;
                              $GLOBALS['error_type']       = "error"; //ok,warn,error,info
                              $GLOBALS['error_msg']       = $PPT->_e(array('add','50'));

' HERE i need to insert a rule which will disable the button "submitMe" ... How can i do it? The button is already displayed on the page ....

Thank you!
  • 5
  • 4
1 Solution
Ray PaseurCommented:
If the button is already displayed on the page, it's too late. PHP runs on the server, where it creates the HTML document containing the HTML markup, CSS and JavaScript.  By the time the client sees the web page, the server has disconnected and gone to sleep.  This explains the client/server protocol.

In the PHP action script you can simply ignore the button.  In the PHP script that creates the form you can omit the button.  If there is a specific client action like a checkbox or mouseclick that you want to follow, you can use JavaScript to enable or disable input controls like buttons, or to hide them completely.  The most popular JavaScript library is jQuery.
helenb1Author Commented:
Can you please go in this page?


Click on Select Plan.

On the next page go at the footer and click 'I Agree to ...' and you will see that the button will be activated, and if you un-check 'I agree' it will be disabled.

Any thoughts on this one?
Ray PaseurCommented:
Yes, this is jQuery.  This is from the "view source" at line 362

        <h4><span>5</span>Terms and Conditions</h4>
        <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#submitMe').attr('disabled', true);  }); 
        function UnDMe(){
			if ( jQuery('#submitMe').is(':disabled') === false) { 
				jQuery('#submitMe').attr('disabled', true);  jQuery('#submitMe').removeClass('green'); jQuery('#submitMe').addClass('gray');
			} else {
				jQuery('#submitMe').attr('disabled', false); jQuery('#submitMe').addClass('green');
        <!-- START TERMS BOX -->     
        <div class="green_box"><div class="green_box_content">         
            <input type="checkbox" id="agreeTC" name="interests" class="radio" tabindex="8" onclick="javascript:UnDMe();">
            <a href="http://www.linkslive.info/submission-guidelines/" style="color:blue; text-decoration:underline;" target="_blank">I agree to the Terms and Conditions</a>
        <!-- END TERMS BOX -->    
	</fieldset> <!-- end fieldset form-->

	</div><!-- end inner itembox -->
	<!-- start buttons -->
    <div class="enditembox inner">
    <input type="button" onclick="window.location='http://www.linkslive.info/submit/'"  class="button gray right" tabindex="15" value="Cancel" />
    <input type="submit" name="submit" id="submitMe" class="button gray left" tabindex="15" value="Continue"/>
    </div><!-- end buttons -->

Open in new window

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

helenb1Author Commented:
ok .. thank you for the correction.

it is possible to do what i want? How can i disable the button in the php code?
Ray PaseurCommented:
It doesn't work that way.  PHP is run and done before the client even sees the web page.  The PHP code is completed.

If you can show me examples of what you're trying to achieve, I can probably show you how to do it, but it doesn't sound like a PHP thing so far - it sounds like jQuery.
helenb1Author Commented:
I am trying to disable the button.

I need to insert the JQUERY function (to call it) from the same .php file that the button exists.

Do you understand?

With other words i need something like...

Ray PaseurCommented:
OK, I can show you how to disable the button, but it's not done in PHP.  PHP is on the server.  The button is on the client.  The only way PHP becomes involved in this process is by generating the HTML document that gets sent to the client. The HTML document contains the jQuery statements that disable the button.
helenb1Author Commented:
ok please tell me how we can disable it?
Ray PaseurCommented:
Please see: http://www.laprbass.com/RAY_temp_helenb1.php

<?php // RAY_temp_helenb1.php

$htm = <<<HTML5
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function() { $('#submitMe').attr('disabled', true);  });

function UnDMe(){
    if ($('#submitMe').is(':disabled') === false){
		$('#submitMe').attr('disabled', true);
		$('#submitMe').attr('disabled', false);

<style type="text/css">
.gray  { background-color:lightgray; }
.green { background-color:lawngreen; }

<title>Toggle Submit Button On or Off</title>

Click Me: <input type="checkbox" onclick="javascript:UnDMe();">
<input type="submit" id="submitMe" class="button gray" value="Continue" />


echo $htm;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now