0

We have been trying to change the visibility of an input from within a php function. Other code will execute in the PHP code block but no luck changing the visibility of the input. will post code because it is a test project all the code is in a php file Our question is how to make the input visible with js

    if($response->success == 1){

     echo "<script 
     type='text/javascript'>document.getElementById('idb').style.visibility 
     ='visible'; </script>";

    }else{

     header('location:https://androidstackoverflow.com/index.html');/* page 
     on 
    the server */
    die();

    }
    }

   ?>
   <script 
   src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
  </script>
  <style type="text/css">
  #inb{
  visibility: hidden;
  }
  </style>
 <form method="post" action="">
 <input type="text" name="your_name" placeholder="Your Name" /><br /><br />
 <input type="text" name="email" placeholder="Your Email Address" /><br />
 <br 
 />
 <div class="g-recaptcha" data-sitekey="<?php print $SITE_KEY; ?>"></div>
 <input id="inb" type="submit" name="submit_form" value="Submit Your 
 Information" />

so I am calling this function from the PHP block of code and still no results I use this to call the function echo "changeVisibility()"; and here is the function code

<script type="text/javascript">

function changeVisibility(){

var formTag = document.getElementById('inb');
formTag.style ="visibility:visible"     

}

James_Duh
  • 1,101
  • 8
  • 28
  • 2
    Look at your javascript console in the browser. you should be seeing an error about accessing a property of null – Patrick Evans Mar 19 '18 at 00:56
  • `idb` != `inb` => `document.getElementById('idb')` != ` – Sean Mar 19 '18 at 00:58
  • @Sean I am not a web or PHP coder what is the idb != telling me I understand the => but why set it this way as Patrick Evans is suggesting it is set to null ? – James_Duh Mar 19 '18 at 01:09
  • @PatrickEvans Used developer tools see no errors just a depreciated component – James_Duh Mar 19 '18 at 01:12
  • `!=` is short code for does not equal, or not the same. Your javascript is looking for an element with the id of `idb`, but the only id I see is `inb`. But your other issue is in the linked duplicate question. You need to place your code *after* the input is defined. – Sean Mar 19 '18 at 01:12
  • @Sean thanks I see the type now will try to move the code my concern here is the input is hidden when page loads so it is finding the component because it is test the html is not well formated – James_Duh Mar 19 '18 at 01:19
  • @Sean moved all HTML to top of page now the reCaptcha will not show is this because the PHP code is running or do you want me to move the Style code – James_Duh Mar 19 '18 at 01:26

0 Answers0