简体   繁体   中英

Change html style after submitting form

Is there a way to change the style of something from display none to display block after a form has been submitted? I'm checking if the form has been submitted:

if(isset($_POST['submit'])){

I'm guessing it goes somewhere after here..?

I've tried this but no joy...

echo '<style type="text/css">
      .login {
       display: block;
      } </style>';

thanks

You should probably define a style for hidden, and then add/remove that class from the parent element.

So in css:

<style type="text/css">
hidden{
  display:none;
} 
</style>

Then in your code something like:

$submitted = isset($_POST['submit']);

And when you render your form:

<div class="<?=($submitted)?'':'hidden'; ?>">
    <form...
</div>

Alternatively, just don't render the form at all:

<?if(!$submitted){?>
<form...
<?}?>

I would tell you to add on your <form> an onsubmit: <form onsubmit="DisplayLogin()">

And elsewhere some JS

<script>
function DisplayLogin(){
    $('.login').css('display','block'); //using jquery
}
</script>

I think the piece of jQuery below should work for you, but it's very difficult because you didn't include a lot of code. Replace button with the button's id or class .

$('.button').click(function() {
  $('.login').css('display', 'block');
});

JSFIDDLE

You can do something like this:

 if(isset($_POST['submit'])){ <!--here you close the php tag--> <style type="text/css"> .login { display: block; } </style> <!--here you open the php tag--> } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM