简体   繁体   English

根据下拉菜单和单选按钮更改2个字段的值

[英]change value of 2 fields depending on dropdown and radio button selection

I am trying to replicate the sort of functionality which is present on this website . 我正在尝试复制此网站上提供的功能。 The price, mentioned above the 'Get a Protective Plan' button, updates with respect to different options selected from the dropdown and the radio button selected. “获取保护计划”按钮上方提到的价格,会根据下拉菜单和单选按钮中的不同选项进行更新。

Now I have a form which has 2 read-only input field's for 'Price' and 'Price-2' and I want the value of those fields to be updated depending on the selection of the dropdown options and the radio button by the user. 现在,我有一个表单,其中有两个用于“价格”和“价格2”的只读输入字段,并且我希望根据用户对下拉选项和单选按钮的选择来更新这些字段的值。 So basically, the values of the read-only input fields, which needs to be updated, will be an addition of the values of the selected dropdown option and the radio button. 因此,基本上,需要更新的只读输入字段的值将是所选下拉选项和单选按钮的值的加法。

Here's a rough example of the form which I've created along with the dropdown and the radio buttons: 这是我与下拉菜单和单选按钮一起创建的表单的粗略示例:

<form action="#" method="post">

      <label>Last Name*</label>

        <input type="text" name="lastname" value="" required="true">

                <select id="p1">
                        <option value="1">$1</option>
                        <option value="2">$2</option>
                        <option value="3">$3</option>
                        <option value="4">$4</option>
                        <option value="5">$5</option>
                </select>

                <input id="p2" type="radio" name="price2" value="50">$50<br/>
                <input id="p2" type="radio" name="price2" value="100">$100

      <label>Price</label>

        <input type="text" name="Price" readonly="readonly" value="">

            <input type="text" name="Price-2" readonly="readonly" value="">

            <input type="submit" value="Submit">
</form>

So in this form if I select the second option from the dropdown whose value is '2' and then I select the first radio button whose value is '50', I'd want the value of the 'Price' and the 'Price-2' fields to automatically become '$52'. 因此,在这种形式下,如果我从下拉菜单中选择值为“ 2”的第二个选项,然后选择值为“ 50”的第一个单选按钮,则需要“价格”和“价格- 2”字段自动变为“ $ 52”。 I know this can be achieved using jQuery but I cannot really figure out how as I am still learning it. 我知道可以使用jQuery来实现,但是我仍然无法真正了解如何学习它。 Looking forward to get a solution. 期待获得解决方案。 Thanks. 谢谢。

you can accomplish using JQuery , 您可以使用JQuery完成,

Here is a Fiddle Demo for your desired result. 这是您想要的结果的小提琴演示

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

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