select输入中的onChange事件然后在同一页面上显示进程的结果

时间:2013-10-03 07:41:58

标签: javascript php jquery html onchange

我有一个内置select输入的表单。当option更改时,将处理表单(使用php)并在<form>下显示该过程的结果。 怎么做?

这是我的html表单代码:

<tr>
  <td>
    <form name="group" id="form1" method="post">
      <select name="group" id="group" onChange="something()">
        <?php foreach ($userGroups['data'] as $groups) {
           echo "<option value=\"".$groups['id']."\">".$groups['name']."</option>";
        }?>
      </select>
    </form>
  </td>
</tr>
<tr>
  <td>
    <?php //PROCESSING THE FORM
      if ($_POST) {
         $groupId = $_POST['group'];
         $groupmember = $facebook->api('/'.$groupId.'/members');
         $membergroup = $groupmember['data'];
         foreach ($membergroup as $membergroups) {
            $membergroupsname = $membergroups['name'];      
         }
      }
   ?>
    <!---- THE PLACE WHERE $membergroupsname DISPLAYED ------>

</td>
</tr> 

非常感谢任何帮助..谢谢

3 个答案:

答案 0 :(得分:0)

当你用jquery标记时,我建议使用jquery post

$.get( "some.php", function( data ) {
  $( "#membergroupsname" ).html( data );
});

请参阅http://api.jquery.com/jQuery.get/

答案 1 :(得分:0)

试用此代码

<强> JQuery的

function handleSelect(elm){
    window.location = elm.value;
}

<强> PHP

 <form name="group" id="form1" method="post">
          <select name="group" id="group" onChange="handleSelect(this)">
            <?php foreach ($userGroups['data'] as $groups) {
               echo "<option value=\"index.php?groupname=".$groups['id']."\">".$groups['name']."</option>";
            }?>
          </select>
        </form>
      </td>
    </tr>
    <tr>
      <td>
        <?php //PROCESSING THE FORM
          if ($_GET) {
             $groupId = $_GET ['group'];
             $groupmember = $facebook->api('/'.$groupId.'/members');
             $membergroup = $groupmember['data'];
             foreach ($membergroup as $membergroups) {
                $membergroupsname = $membergroups['name'];      
             }
          }
       ?>
</form>
    <!---- THE PLACE WHERE $membergroupsname DISPLAYED ------>

答案 2 :(得分:0)

使用jquery .change

jQuery('#group').change(function() {
var id_group = this.value; 
var memberjson = "fetchmember.php?group="+id_group;

jQuery("#fetchmember").html('<img src="./templates/standard/images/ajax-loader.gif">');


jQuery.getJSON(memberjson,function(data){

jQuery("#fetchmember").empty();

jQuery.each(data, function(i, item) {
jQuery("#fetchmember").append("write your html");
});
});
});