dongmisa4779
dongmisa4779
2014-03-09 01:46
浏览 52
已采纳

使用PHP刷新动态textarea

Summary: I'm looking for a simple method to refresh a textarea on changes to an HTML form without refreshing the page.

Details: I'm writing an app to generate standardised BBCode formatting for a forum using data pulled from a database. It's a non-simple vote counter; I pull in a list of eligible voters and what option they're voting for, and have a vote count that shows each option followed by how many votes it has and a list of who is voting for them, followed by a list of people not yet voting.

Above the textarea, I want a line for each voter with a dropdown box of eligible vote choices, and when the user changes the value of the dropdown box, I want the vote count in the textarea to update without refreshing the entire page.

Is this possible with just PHP5 and HTML5?

图片转代码服务由CSDN问答提供 功能建议

摘要:我正在寻找一种简单的方法来刷新HTML表单上的textarea,而无需刷新页面 。

详细信息: 我正在编写一个应用程序,使用从数据库中提取的数据为论坛生成标准化的BBCode格式。 这是一个非简单的投票柜台; 我列出了一份合格选民名单以及他们投票的选项,并有一个投票计数,显示每个选项,然后是它有多少票,以及一个投票给谁的名单,然后是一个没有人的名单 然后投票。

在textarea上方,我希望每个选民都有一行符合条件的投票选项下拉框,当用户更改下拉框的值时,我想要投票 在textarea中进行计数以更新而不刷新整个页面。

只有PHP5和HTML5才能实现这一点吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzi4030
    dongzi4030 2014-03-09 02:12
    已采纳

    Demo: http://jsfiddle.net/5dah5/23/

    This code should get you started:

    <script>
    function changeText(choice) {
        // or just by js
        $('#myTextarea').val(choice+" modified test").show();
    
        // send choice to php file and get response back, insert that into the textarea
        // $.get('do.php?file='+choice, function(data) {
        // $('#myTextarea').html(data);
        // });
    }    
    </script>
    
    
    <select onChange="changeText(this.value)">
        <option></option>
        <option value="1">Option1</option>
        <option value="2">Option2</option>
    </select>
    <hr>
    <textarea id="myTextarea">Test</textarea>
    

    Now you have to options of modifying the choice:

    1. with Javascript on client-side
    2. or pass the choice to the server and let PHP give you the response for that choice

    Add Jquery to the head of your page:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
    
    点赞 评论

相关推荐