I want to hide the submit button based on a PHPcondition through javascript

show hide button in php
hide and show div on if condition in php
php hide html element
hide and show textbox using javascript
onclick show div and hide other div
php hide content
javascript hide element
how to hide a form in html
<?php
if(mysql_num_rows($result5)>0)
{
    echo 'condition matched';
    // the above echo is just for testing
    ?>
     <script type='text/javascript'>
     document.getElementById("submitbtn").style.display = "none";

     </script>
    <?php
}
?>

here I am evaluating an if clause, if the condition is true, I want to hide the submit button of the form.

<form action='xyz.php'>
<input type='text'>
<input type='text'>
<input type='text'>
 <input type='submit' id='submitbtn' name='save' value='SAVE' class='form_btn' >
</form>

The condition is evaluating to true, but the submit button is still visible. How do I achieve this??

try using this way....

<input type='submit' <?php if($result5->num_rows>0) {?> disabled="disabled" <?php } ?> id='submitbtn' name='save' value='SAVE' class='form_btn' >

may be it will help

Disable or Enable Submit Button using JavaScript disabled Property, Here in this post I've shared a simple example showing how to disable or enable a submit button based on certain condition. Setting the property to true will enable the button (clickable) and setting it false (like bt.disabled = false;) will disable the button (un-clickable). How to Show/Hide or Toggle Elements in Angular 4. I browsed through the other questions on this issue but couldn't find a satisfactory answer. I have a quiz website where the user selects an option from four options and then clicks submit. I want to disable the submit button after it has been clicked once. Is there any way to do this with PHP? If not, is there a way to do this with minimal JS.

I had tied your code,and these worked ok, so I think must have other problems to affected your js code, such as a same name Id of submitbtn, or a js error.

Show or Hide Button with PHP condition - PHP, Hi guys, I ran into a coding problem. I want to show a button only if my $status variable changes to COMPLETE. Show or Hide Button with PHP condition � PHP Etiher stye may be used depending on preference or where it's used. 1 Like Powered by Discourse, best viewed with JavaScript enabled. Disable or Enable Submit Button using JavaScript disabled Property. You can use JavaScript disabled property to disable or enable a submit button, or an input button, on your web page. Here in this post I am sharing a simple example showing how to disable or enable a submit button based on certain condition.

If you want to use js try this :

<?php
if(mysql_num_rows($result5)>0)
{
    echo 'condition matched';
    // the above echo is just for testing
    ?>
     <script type='text/javascript'>
        $(document).ready(function(){
           document.getElementById("submitbtn").style.display = "none";
      });

     </script>
    <?php
}
?>

You can achieve this by using php too.

<input type='submit' id='submitbtn' name='save' value='SAVE' class='form_btn' <?php if(mysql_num_rows($result5)>0) echo 'style="display:none"';?>>

JavaScript Examples, If you would like to display a form based on a single checkbox selection, you If you want to hide the submit button until 'Yes' or 'No' is selected in a that shows how to create your own conditional logic to show/hide a field. Firstly, you're probably including the script tag before the submit button. Secondly - if you want to hide the button based on a condition in PHP - you should hide the button with PHP. No reason to use JS to do it.

Posting the answer because all others are just disabling the button. It will still be visible. So to hide the button, use:

window.onload = function(){
   document.getElementById("<id of your submit button>").style.display = "none";
}

inside the if(condition=true)

OR

<input type='submit' name="sbmt" id="id_1"<?php if(condition=true) { ?> style="display: none" <?php } ?> />

but since your question has asked exceptionally for "javascript" i will go one step further and write

     <input type='submit' name="sbmt" id="id_1"
     <?php if(condition=true) { ?>
     <script type='text.javascript'>
        document.getElementById("id_1").style.display = "none";
     </script>
     <?php } ?>
     />

WebD2: Using Javascript to Hide and Show Content, One way that JavaScript is commonly used is to hide or display content based on For example, a user may select an option when filling out an on-line form, and However, in this case we want to make the element visible only if the user� Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. w3schools .com THE WORLD'S LARGEST WEB DEVELOPER SITE

Try as below : jQuery must be there on your page.

On calling the statement on page ready will solve the problem.

<?php
if(mysql_num_rows($result5)>0)
{
    echo 'condition matched';
    // the above echo is just for testing
    ?>
     <script type='text/javascript'>
     $( document ).ready(function() {
        document.getElementById("submitbtn").style.display = "none";
     });
     </script>
    <?php
}
?>

PHP Lesson 30 - Hiding a Form after a Submit, If you are working with a PHP page that has the form and PHP code all in one page you may Duration: 7:18 Posted: Mar 9, 2012 If all these validations are passed then only the submit button will be enabled for the visitor to submit. DEMO of disabling submit button with form validation → Inside the window.onload function ( see below for the code ) we have assigned all the form elements to variables and trigger the function validateField by using onchange event handler.

How to Disable a Submit Button on Submit, Here is the full source from the video: http://helpvideoguru.com/sources/Java HTML, CSS Duration: 8:08 Posted: Feb 27, 2018 Hiding the Submit button based on field value. We can also show or hide buttons based on the values of fields. Suppose you want to hide the Submit button if the radio button "Yes" is picked in the following form: First, add a custom CSS class called hideSubmit to the field: Then, add the following JavaScript to your form:

How to Hide Form Fields Based Upon User Selection, Ultimately, making certain form fields conditional on based upon previous user- inputed options Not that each form field grouping should have its own unique ID. This ID will be used in jQuery target specific sections to show or hide. The Javascript uses jQuery to change the DOM depending on the selections made. Hi guys, I ran into a coding problem. I want to show a button only if my $status variable changes to COMPLETE. I don’t know how to do this. Can anyone help me?

How to Conditionally Show the Submit Button with WPForms, You may want to just redirect a user to another page rather than submitting a form entry if they answer No to a Using PHP and JavaScript you can conditionally set up the submit button to show or hide based on an answer from your form. visibility:visible;. } </style>. <?php } );. // Conditional logic for Submit button. function�

Comments
  • Why don't you rather conditionally print or not print the tag for button?
  • Firstly, you're probably including the script tag before the submit button. Secondly - if you want to hide the button based on a condition in PHP - you should hide the button with PHP. No reason to use JS to do it.
  • @DalHundal is right. You can do it with PHP or you have to right the JS at the end of page, so that after page is ready then JS comes in action and work fine.
  • Yeah, doing it through the PHP itself rather than using JS is the sensible solution. If he wants it to not show (rather than be disabled) you could use style="display: none;" in the condition.
  • yes, javascript was'nt doing it because I was executing script before the submit button. Doing it directly through php on the input tag is a better option.Thanks
  • Adding a small explanation of your solution may be a help for someone running into this in the future :D
  • document.getElementById("submitbtn").style.display = "none"; Works just as well as that, not really a solution.
  • I just tried and it doesn't work with "none" but works with "hidden"
  • There's a difference between display and visibility. This isn't a solution to this problem.
  • yes @GeoffAtkins its working fine now. The problem was that I was loading script before the submit button had loaded. Both, executing the script after the submit button and doing it directly through PHP on the input tag work good.