简体   繁体   English

在PHP中动态更改文本

[英]Dynamically change text in php

hey guys i am building a form in which i want when a user select an option from the dropdown menus a text to be displayed and calculate the price. 大家好,我正在构建一个表单,当用户从下拉菜单中选择一个选项时,我要在其中显示文本并计算价格。

The dropdown menu is: 下拉菜单为:

<select id="recipient" name="recipient" tabindex="6" class="selmenu">  
            <option value="staff">Site Staff</option>  
            <option value="editor">Editor-in-Chief</option>  
            <option value="technical">Tech Department</option>  
            <option value="pr">Public Relations</option>  
            <option value="support">General Support</option>  
        </select>

and the other dropdown menu is: 另一个下拉菜单是:

<select id="recipient" name="recipient" tabindex="6" class="selmenu">  
            <option value="one">1</option>  
            <option value="two">2</option>  
            <option value="three">3</option>  
            <option value="four">4</option>  
            <option value="five">5</option>  
        </select>

What i want to do is when the user selects something from the first and the second menu i want a textfield to change dynamically... can anyone point me the way? 我想做的是,当用户从第一和第二个菜单中选择某项内容时,我希望文本字段可以动态更改……有人可以指出我的方向吗?

only ajax/jquery could do that in combination of php step might be... 只有ajax / jquery可以结合php步骤来做到这一点...

  1. onchange of any dropdown make a ajax request to php script. 任何下拉列表的onchange都会向php脚本发出ajax请求。

  2. return the json response from php script 从php脚本返回json响应

  3. use this response to either manipulate your form or display data on page. 使用此响应来操作表单或在页面上显示数据。

you don't need to use php for this, it can all be done with jquery/javscript 您不需要为此使用php,都可以通过jquery / javscript完成

an example using jquery is below (i had to rename your second select as you had re-used an ID): 下面是一个使用jquery的示例(我不得不重命名第二个选择,因为您已经重复使用了ID):

$('.selmenu').change(function() {
  $('#output').text($('#recipient option:selected').text() + ' ' + $('#recipient2 option:selected').text());
})

output is the id of your textbox. 输出是您的文本框的ID。

on a select value being changed, output will be filled with the selected value in both select controls 在更改选择值时,将在两个选择控件中将选择值填充到输出中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM