本文介绍了获取选择&在PHP中显示选定的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了很多&搜索了很多,但我没有找到解决方案。



我有HTML代码

HTML

 < form id =program_modeaction =method =post> 
< option>选择< / option>
< option value =<?php echo $ vars ['url']?> pg / event_calendar / all<?php if($ mode =='All')echo'selected =选择'; ?>>所有< /选项>
< option value =<?php echo $ vars ['url']?> pg / event_calendar / anytime<?php if($ mode =='Online')echo'selected =选择'; ?>>在线< /选项>
< option value =<?php echo $ vars ['url']?> pg / event_calendar / offline<?php if($ mode =='Offline')echo'selected =选择'; ?>>离线< /选项>
< / select>
< / form>

然后我想在php部分选中选项。



所以我写过像



PHP

  $ mode = $ _POST ['mode']; 
var_dump($ mode);

但我没有收到价值。我不想提交的东西。 Onchange只有它应该得到的价值。

解决方案
 < form id =program_modeaction = method =post> 
< option>选择< / option>
< option value =<?php echo $ vars ['url']?> pg / event_calendar / all<?php if($ mode =='All')echo'selected =选择'; ?>>所有< /选项>
< option value =<?php echo $ vars ['url']?> pg / event_calendar / anytime<?php if($ mode =='Online')echo'selected =选择'; ?>>在线< /选项>
< option value =<?php echo $ vars ['url']?> pg / event_calendar / offline<?php if($ mode =='Offline')echo'selected =选择'; ?>>离线< /选项>
< / select>
< / form>

使用小jquery,您可以使用这个

 < script> 
函数val_changed()
{
var mode = $('#mode')。val();

}
< / script>


I have tried a lot & searched a lot but i didn't found the solution.

I have HTML code

HTML

<form id="program_mode" action="" method="post">
        <select name="mode" id="mode">
            <option>Select</option>
            <option value="<?php echo $vars['url']?>pg/event_calendar/all" <?php if($mode == 'All') echo 'selected="selected"'; ?>>All</option>
            <option value="<?php echo $vars['url']?>pg/event_calendar/anytime" <?php if($mode == 'Online') echo 'selected="selected"'; ?>>Online</option>
            <option value="<?php echo $vars['url']?>pg/event_calendar/offline" <?php if($mode == 'Offline') echo 'selected="selected"'; ?>>Offline</option>
        </select>
        </form>

Then i want in php part the selected option.

So i have written like

PHP

$mode = $_POST['mode'];
var_dump($mode);

But i am not getting the value. The thing i dont want to submit. Onchange only it should get the value. Can it will be possible ?

解决方案
<form id="program_mode" action="" method="post">
    <select name="mode" id="mode" onchange="val_changed()">
        <option>Select</option>
        <option value="<?php echo $vars['url']?>pg/event_calendar/all" <?php if($mode == 'All') echo 'selected="selected"'; ?>>All</option>
        <option value="<?php echo $vars['url']?>pg/event_calendar/anytime" <?php if($mode == 'Online') echo 'selected="selected"'; ?>>Online</option>
        <option value="<?php echo $vars['url']?>pg/event_calendar/offline" <?php if($mode == 'Offline') echo 'selected="selected"'; ?>>Offline</option>
    </select>
    </form>

With little jquery you can do with this

    <script>
function val_changed()
        {
        var mode=$('#mode').val();

        }
</script>

这篇关于获取选择&amp;在PHP中显示选定的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 15:58