简体   繁体   English

提交单选按钮值而不刷新页面

[英]Submitting radio button values without page refresh


I'm currently having radio buttons to choose which payment the user want on the website, they can choose between (invoice, card, part payment(?)). 我目前正在使用单选按钮来选择用户要在网站上进行的付款,他们可以在其中选择(发票,卡,部分付款(?))。

I'm using scripting to submit the radio buttons so no button is needed, however the page reloads every time they choose a different payment option, which is bad for the customer since they have to scroll down again to input the values of the form (phone number etc.) that appear when the radio button is selected. 我正在使用脚本提交单选按钮,因此不需要按钮,但是,每当他们选择其他付款方式时页面都会重新加载,这对客户不利,因为他们不得不再次向下滚动以输入表格的值(电话号码等)。

So after a few complaints I've been trying to fix this issue to make the form appear without the page getting refreshed. 因此,在提出一些投诉之后,我一直在尝试解决此问题,以使表单显示而无需刷新页面。

Is it possible to make a few changes in the scripting to make this possible? 可以在脚本中进行一些更改以使之成为可能吗?

Thanks in advance. 提前致谢。

Here's the scripting i use: 这是我使用的脚本:

function autoSubmit(){
    var formObject = document.forms['choice_form'];
    formObject.submit();
}

Here's the PHP: //I use the post values to show the form where you enter phone number and email 这是PHP://我使用帖子值显示表单,您可以在其中输入电话号码和电子邮件

<?php 
 $value = '';
  if(isset($_POST['choice'])) {
   $value = $_POST['choice'];
  }
?>

Here's the "radio" form: 这是“广播”形式:

<form name="choice_form" id="choice_form" method="post">
   <table>
     <tr>
      <td>
        <input type="radio" name="choice" <?php if ($value == 'faktura') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="faktura"> Faktura
      </td>
    </tr>
    <tr>
      <td>
        <input type="radio" name="choice" <?php if ($value == 'kort-direkt') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="kort-direkt"> Kort / Direktbetalning
      </td>
    <tr>
      <td>
        <input type="radio" name="choice" <?php if ($value == 'delbet') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="delbet"> Delbetalning
      </td>
    </tr>
  </table>
</form>

If every time a payment option is selected a different form needs to appear underneath the radio buttons, you could render all forms in hidden state in individual <div> s, and then display the corresponding <div> every time an option is selected. 如果每次选择付款选项时,单选按钮下方都需要显示其他表单,则可以在各个<div>以隐藏状态呈现所有表单,然后在每次选择选项时显示相应的<div>

If you need to do something more complex than that, you will probably need to use AJAX. 如果您需要做的事情比这更复杂,则可能需要使用AJAX。

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

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