0
<?php
echo $_POST['textvalue'];
echo $_post['radiovalue'];

?>
<div id="hidethis">
<form method="POST" action="">
<label>Tekst Value</label>
<input type="text" name="textvalue">
<label>Radio Value</label>
<input type="radio" name="radiovalue" value="autogivevalue">
<input type="submit" id="submit" name="submit" value="submit">
</div>

http://jsfiddle.net/Bjk89/2/ here is it with the jQuery.

What i try to do is to hide the <div id="hidethis"> when it's clicking submit.

I know i can make another page where i can recieve the values without the <form> section, but i want to put both in one page, make the <div id="hidethis"> hidden after submit.

So i'll be able to get echo $_POST['textvalue']; and echo $_post['radiovalue']; as results

RESULT MUST BE LIKE

A Text // This is the value you input into Tekst Value

autogivevalue // This is the value from the radio button

----- INVISIBLE -----

<form is hidden because we set it in jQuery so>
</form>
0

2 Answers 2

3

Try this. No need to use jQuery here.

<?php
if($_POST) {
    echo $_POST['textvalue'];
    echo $_post['radiovalue'];
} else {
?>
    <form method="POST" action="">
        <label>Tekst Value</label>
        <input type="text" name="textvalue">
        <label>Radio Value</label>
        <input type="radio" name="radiovalue" value="autogivevalue">
        <input type="submit" id="submit" name="submit" value="submit">
    </form>
<?php
}
?>
2
  • You could even use <form method="POST" action="" onsubmit="$('#hidethis').hide()"> to hide it even a bit sooner ;-)
    – Farce
    Dec 17, 2013 at 20:38
  • But if the form submits, the page reloads, and then the div is shown again, no?
    – Floris
    Dec 17, 2013 at 20:40
0

Try adding '#' in your jquery code. Your version does not have # next to submit. Also your form is missing a closing tag here and in your JSFiddle code.

Try this:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script>
$(document).ready(function () {
    $('#submit').click(function () {   
         $('form').submit();
         $('#hidethis').hide();  
    });
});
</script>
    <form method='post' id="hidethis" name='form'>
        <input type="text" name="textvalue">
        <input type="radio" name="radiovalue" value="1">
        <input type="button" id="submit" name="submit" value="submit">
    </form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.