Show/Hide div id from input value form previous page

Clash Royale CLAN TAG#URR8PPPShow/Hide div id from input value form previous page
I find it difficult to solve this problem. I want to use the form input data data from the previous page to show or hide a particular div id.
<form action="http://example.com/example/" method="post">
<input type="hidden" id="example" name="example" value="<?php echo $site; ?>">
<input class="examplesubmit" type="submit" value="Submit">
</form>
page 2
<div id="testing" style="display:none;">
konten
</div>
I want the input value or name or id, of the previous page to be used as the basis of div id showing or hidden. if the user hits the submit button, the page automatically displays the content, otherwise the content is not displayed
how should i write it? may use javascript or php code
I'd put it in the arguments of url, like
site.xz/form/page2/?whatever=yes– Blacksilver
5 mins ago
site.xz/form/page2/?whatever=yes
1 Answer
1
you would achieve that in a manner like so:
Page 1
<form action="index2.php" method="post">
<input type="hidden" id="example" name="example" value="foo">
<input class="examplesubmit" type="submit" value="Submit">
</form>
Page 2 (index2.php)
<div id="testing"<?php echo ($_POST['example'] == 'foo') ? '' : ' style="display:none;"'; ?>>
konten
</div>
This makes use of the ternary operator which is more or less an inline if/else condition.
So the form on page 1, submits to the form on page 2 (index2.php) in my example and checks that the form field with the name of example has a value set to "foo".
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Have you written any server-side code so far to try to solve this issue?
– hev1
16 mins ago