To stay on the current page on submitting page but should display new items PHP
I have a page called file.php, it has a form in it, but when the page is submitted it should stay on this page itself and the form should not be shown, instead it should display a message "Welcome".
The sample code is
<form name="fn" method="post" action="postib.php">
<table align="center" border="1" >
<TR><TD>Job Title</TD><TD><input type="text" name="jobtitle"/></TD></TR>开发者_如何学编程
<TR><TD>Job Description</TD><TD><input type="textarea" name="jobdescription"/></TD></TR>
<TR><TD>Location</TD><TD><select name="locid" id="locid" size="1" style="width:190px;" onchange="showsub();"><option value="1" title="Any Location">Any Location</option>
<input type="submit">
Create a hidden iframe:
<iframe id="my_hidden_iframe" style="display:none;></iframe>
Then set the target of your form to this iframe and set an onSubmit for the form:
<form id="my_form" target="my_hidden_iframe" onSubmit="submit_form_function();">
Create a welcome message div that is hidden by default:
<div id="my_welcome_message" style="display: none;">Welcome...</div>
Then have the submit_form_function() hide the form and add a welcome message:
function submit_form_function() { $('#my_form').hide(); $('#my_welcome_message').show(); }
The above code uses JQuery, you can also do this without a JS library:
function submit_form_function() { document.getElementById('my_form').style.display = 'none'; document.getElementById('my_welcome_message').style.display = 'block'; }
精彩评论