English 中文(简体)
2. 如果在无纽特顿的情况下选定价值变化,则采用文字压缩形式
原标题:Submit wordpress form if selected value changes without button

I m trying to submit a form without a submit button. This form takes values from custom fields in wordpress, displaying results in another page. I ve been trying with the usual javascript function onchange and nothing happens, I ve tried with functions as well...does anyone know what s wrong with this or if is there a better way to solve it? Can it be something related to Wordpress, or the post method? This is the code for the form:

<form method="get" name="form" action="/busqueda/" >
        <div class="search">

            <select class="styled" name="author"  onChange="this.form.submit();">
            <option value="-1" selected>Authors</option>    
            <?php
            $metakey =  author ;
            $autores = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
            if ($authors) {
            foreach ($authors as $author) {
            echo "<option VALUE="" . $author . "">" . $author . "</option>";
                                    }
                            }
                ?>
            </select>
        </div><!-- #search1 -->

</form>

BTW, the form works fine when displaying results with a standard submit button. Any hint of what can be wrong is welcome. Thanks a lot!

最佳回答

引证:

<form method="get" name="form" action="/busqueda/" >
        <div class="search">

            <select class="styled" name="author" onChange="document.forms[ form ].submit();">

            <?php
            $metakey =  author ;
            $autores = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
            if ($authors) {
            foreach ($authors as $author) {
            echo "<option VALUE="" . $author . "">" . $author . "</option>";
                                    }
                            }
                ?>
            </select>
        </div><!-- #search1 -->

</form>

Updated with jQuery submit

最新表格:

<form id="authorForm" method="get" name="form" action="/busqueda/" >
        <div class="search">

            <select id="author" class="styled" name="author">
                <option value="default">Choose an author...</option>
                <?php
                $metakey =  author ;
                $autores = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
                if ($authors){
                    foreach ($authors as $author) {
                        echo  <option value="  . $author .  ">  . $author .  </option> ;
                    }
                }
                ?>
            </select>
        </div><!-- #search1 -->

</form>

j 文字改变活动处理和形式提交:

<script type="text/javascript">
$(document).ready(function(){
    $( #author ).change(function(){
        if($(this).val() !==  default ){
            $( #authorForm ).submit();
        }
    }); 
});
</script>

http://jsfiddle.net/b8SjT/rel=“nofollow” 页: 1 放弃箱子改变活动提交书状

问题回答

我希望你将员额后的价值正确地从GET美元中收回,因为如果在我的浏览器上操作该代码,URL的数值就会相当高。 检查你的检索代码,确保你使用_GET,而不是_POST。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签