douyun8901 2015-03-06 10:44
浏览 107

too long

I want to use the select value in current PHP file, but without submit button, how do I do this?

This is my code:

<?php

    $args = array(
                'orderby' => 'name', 
                'order' => 'ASC',
            );

    $pays = get_terms( 'pay', $args );
    $html = '<form action="#" method="post"><select name="selected_pay" id="selected_pay" >';

    foreach ($pays as $pay) {
        $html .= '<option value="'.$pay->name.'">'.$pay->name.'</option>';  
    }

    $html .= '</select></form>';
    echo $html;

?>

And I want to use it like this:

<?php 

    if (isset($_POST['selected_pay'])) 
        echo $_POST['selected_pay'];
    else
        echo 'Please select a pay';

?>
  • 写回答

2条回答 默认 最新

  • dqr91899 2015-03-06 11:36
    关注

    You do not need a submit button, but anyway you need to send to the server what is the current value of selected_pay.

    You can do it on some event for example. Like hovering mouse over some element or even on some specific time ;) But you have to define the event - when is the moment you want to send/check that if not on clicking on a submit button.

    I guess what you really want is to send/check that value whenever it changes using AJAX. You can use JQuery with onchange event.

    jQuery('#selected_pay').change(function(){
       jQuery.post('script.php', {selected_pay: jQuery(this).val()}, function(data){
           jQuery(this).append(data); // show the result from script.php under the select element  
       })
    

    });

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题