要在提交页面上保留当前页面,但应显示新项目PHP

时间:2011-06-29 06:10:11

标签: php

我有一个名为file.php的页面,它有一个表单,但是当提交页面时,它应该保留在这个页面本身并且不应该显示表单,而是应该显示一条消息“欢迎”。

示例代码是

    <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">

1 个答案:

答案 0 :(得分:0)

创建隐藏的iframe:

<iframe id="my_hidden_iframe" style="display:none;></iframe>

然后将表单的目标设置为此iframe,并为表单设置onSubmit:

<form id="my_form" target="my_hidden_iframe" onSubmit="submit_form_function();">

创建默认隐藏的欢迎消息div:

<div id="my_welcome_message" style="display: none;">Welcome...</div>

然后让submit_form_function()隐藏表单并添加欢迎消息:

function submit_form_function() {
    $('#my_form').hide();
    $('#my_welcome_message').show();
}

上面的代码使用JQuery,你也可以在没有JS库的情况下执行此操作:

function submit_form_function() {
    document.getElementById('my_form').style.display = 'none';
    document.getElementById('my_welcome_message').style.display = 'block';
}