I am working on a project where the user has to choose one of two options. Options are radio buttons Currently I'm getting results on keypot event. When the user selects an option and then enters the value in the input field, the result is found in another result input field. Its work is fine but the problem arises when users want to change the option and select the second option, then it must be re-entered in the input field which is not correct, when it chooses the second option, its The result is automatically the change in the input input field because it enters the first time once in the input.
For the entire process here
Here is the html:
& lt; TD & gt; & Lt; Input type = "radio" name = "rdbtn-im" id = "rdbtn-im-day" value = "25" class = "rdbtn-style-social" /> Daily & amp; Nbsp; & Lt; Input type = "radio" name = "rdbtn-im" id = "rdbtn-im-week" value = "25" class = "rdbtn-style-social" /> weekly & lt; / Td> Here is the result input
results This is my junkie
var val = 0; JQuery ("# rdbtn-im-day"). Click on (function () {if (jQuery (this) .is (": checked")) // Check whether the radio val = jQuery (this) is the check .value (); // value recover}} ); JQuery ("# rdbtn-im-week"). Click (function () {if (jQuery (this) .is (": checked")) // Check if radio val = jQuery (this) is checked .val () * 7; // value recover Please}}); JQuery ("#txt_im"). Key (function () {var txt_value = jQuery (this) .val (); var res = txt_value * val; var final = parseInt (res); var MBresult = final / 1024; jQuery ('#final_res'). Val ( MBresult.toFixed (2)); I am using jquery-1.3.2.min.js which was not available in the right dropdown list.
Thanks in advance
You can make your functionality easier:
- To change an event instead, remove the click event on the radio.
- Set a real value instead of computing it later
- Use the variable
val to maintain the value of the radio button. script jQuery ("#txt_im"). The function to add keys (set value); // on the text box keys ('[name =' rdbtn-im '] '). Function set value to calculate the call function set on the text box keys on text (insect), // {var txt_value = jQuery ("# txt_im"). Val (); // Get Go e Text Box Vir rad_val = jQuery ('[name = "rdbtn-im"]: checked'). Val (); // Receive check radio valve (! Txt_value.length ||! Rad_val.length) return; // Do not do so if none of them is available var res = txt_value * rad_val; Var final = parseint (race, 10); Var MBresult = Last / 1024; JQuery ('# final_res') Val (MBresult.toFixed (2)). } radio markup section & lt; Input type = "radio" name = "rdbtn-im" id = "rdbtn-im-day" value = "25" class = "rdbtn-style-social" /> Daily & amp; Nbsp; & Lt; Input type = "radio" name = "rdbtn-im" id = "rdbtn-im-week" value = "175" class = "rdbtn-style-social" /> weekly & lt; / Td>
No comments:
Post a Comment