javascript - radio button sets text box value -


$(function () {      $("input[name='rbselection']").change(function () {         switch (this.value) {             case "1":                 caption = "daily";                 form_content = '<div class="divborder"><input type="radio" class="inputed" name="every_days" value="every_days" /><span>every</span> <input type="text" size="1" name="every_days_amount" value="1" /> <span>day(s)</span><br /></div><div class="divborder"><input type="radio" class="inputed" name="every_dayweekday" disabled="disabled" value="every_weekday" /><span>every weekday</span></div>';                 break;             case "2":                 caption = "weekly";                 form_content = '<div class="divborder"><input type="radio" class="inputed" name="every_weeks" value="every_weeks" /><span>recur every</span> <input type="text" size="1" name="every_week_amount" value="1" /><span> weeks(s) on </span><select name="weekly_day" id="weekly_day"><option value="1" selected>monday</option><option value="2">tuesday</option><option value="3">wednesday</option><option value="4">thursday</option><option value="5">friday</option><option value="6">saturday</option><option value="7">sunday</option></select></div>';                 break;             case "3":                 caption = "monthly";                 form_content = '<div class="divborder"><input type="radio" class="inputed" name="every_month" value="every_months" /><span>day</span> <input type="text" size="1" name="every_month_day_amount" value="31" /> <span>of every</span> <input type="text" size="1" name="every_week_amount" value="1" /> <span>month(s)</span><br></div><div class="divborder"><input type="radio" class="inputed" name="every_the_month" value="every_the_months" /><span>the</span>  <select name="monthly_what" id="monthly_what"><option value="first">first</option><option value="second">second</option><option value="third">thrid</option><option value="fourth">fourth</option><option value="last" selected>last</option></select> <select name="weekly_day" id="weekly_day"><option value="1" selected>monday</option><option value="2">tuesday</option><option value="3">wednesday</option><option value="4">thursday</option><option value="5">friday</option><option value="6">saturday</option><option value="7">sunday</option></select> <span>of every </span><input type="text" size="1" name="every_week_amount" value="1" /> <span>month(s)</span></div>';                 break;             case "4":                 caption = "yearly";                 form_content = '<div class="divborder"><input type="radio" class="inputed" name="every_years" value="every_years" /><span>every</span> <select name="year_month" id=""><option value="1">january</option><option value="2">february</option><option value="3">march</option><option value="4">april</option><option value="5" selected>may</option><option value="6">june</option><option value="7">july</option><option value="8">august</option><option value="9">september</option><option value="10">october</option><option value="11">november</option><option value="12">december</option></select> <select id="dayselection"><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><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31" selected>31</option></select><br></div><div class="divborder"><input type="radio" class="inputed" name="every_the_month" value="every_the_months" /><span>the</span>  <select name="monthly_what" id="monthly_what"><option value="first">first</option><option value="second">second</option><option value="third">thrid</option><option value="fourth">fourth</option><option value="last" selected>last</option></select> <select name="weekly_day" id="weekly_day"><option value="1" selected>monday</option><option value="2">tuesday</option><option value="3">wednesday</option><option value="4">thursday</option><option value="5">friday</option><option value="6">saturday</option><option value="7">sunday</option></select> <span>of</span> <select name="" id=""><option value="1">january</option><option value="2">february</option><option value="3">march</option><option value="4">april</option><option value="5" selected>may</option><option value="6">june</option><option value="7">july</option><option value="8">august</option><option value="9">september</option><option value="10">october</option><option value="11">november</option><option value="12">december</option></select></div>';                 break;             case "5":                 caption = "misc";                 form_content = '<div class="divborder"><input type="radio" class="inputed" name="every_5th_sunday_of_month" disabled="disabled" value="every_5th_sunday_of_month" />every 5th sunday of month<br></div><div class="divborder"><input type="radio" class="inputed" name="every_easter" disabled="disabled" value="every_easter" />every easter</div>';                 break;             default:                 caption = "default";                 form_content = "test default";         }         $("#content").html(form_content);         //$("#content").html(form_content + "<br><br>" + caption + "<br> - load content div option " + this.value);      });  });       </td> </tr> <tr  bgcolor="whitesmoke"><td><p>&nbsp;</p></td><td>     <div align="left" id="date_string_input">         <input type="text" name="date_string" size="75"  id="date_string">     </div> 

in above code i'm trying fill textbox(date_string) values selected i've tried:

if ($('#every_days:checked').val() == 'true') {       alert("hello"); } //$("#date_string").val("every ".$("#every_days_amount").val()); 

and other looked posts

jquery if radio button checked

find out if radio button checked jquery?

nothing seams fire event.

this doc ready in case needed

<script type="text/javascript"> jquery(document).ready(function () {     $("#generate").val("save info");      if ($('#every_days:checked').val() == 'true') {         alert("hello");     }      jquery("#datetimecustom").dyndatetime({         showstime: true,         ifformat: "%y-%m-%d %h:%m:00",         daformat: "%a, %b %e, %y [%i:%m %p]",         align: "tl",         electric: false,         singleclick: false,         displayarea: ".siblings('.dtcdisplayarea')",         button: ".next()" //next sibling     });     jquery("#datetimecustom2").dyndatetime({         showstime: true,         ifformat: "%y-%m-%d %h:%m:00",         daformat: "%a, %b %e, %y [%i:%m %p]",         align: "tl",         electric: false,         singleclick: false,         displayarea: ".siblings('.dtcdisplayarea2')",         button: ".next()" //next sibling     });      $("radio[name='daterbselection']").click(function () {         alert('test');         if ($(this).val() === 'r') {             if ($(this).is(":checked")) {                 $("#r_date").show();             }         } else {             $("#r_date").hide();         }     }); }); 

update: still not working stuff ive tried

$('#every_days').click(function () {     var ischecked = $('#every_days').prop('checked');     alert(ischecked); });  $("#every_days").click(function () {     alert("days");     if ($("input:radio[name=every_days]").is(":checked")) {         alert("hello");         //$("#date_string").val("every ".$("#every_days_amount").val());     } });  //$("#date_string").val("every ".$("#every_days_amount").val()); //$('#date_string').val($('#every_days_amount').val());  // works value textbox - pattern //$('#date_string').val('5555');  //alert("hi: ".$('#every_days_amount').val());  function xevery_days() {     //some code     alert("hello"); } 

in form output area:

form_content = '<div class="divborder"><input type="radio" title="ie every 2 days every other day" class="inputed" name="every_days" id="every_days" value="every" onclick="xevery_days()" /><span>every</span> <input type="text" size="1" name="every_days_amount" id="every_days_amount" value="2" /> <span>day(s)</span><br /></div><div class="divborder"><input type="radio" class="inputed" name="every_dayweekday" disabled="disabled" value="every_weekday" /><span>every weekday</span></div>'; 

still trying work out - 8/30/13 asked friend , sent me saying should work (he didn't have time test nor can me month hes going out of town) not work. nothing. maybe can me figure out why not looks should work new code:

                $('.inputed').live('click blur change', function() {                     alert('hi');                     window.container = '';                     var container = '';                     $(this).parents().each(function() {                         var valueclass = $(this).attr("class");                         if (valueclass == 'divborder') {                             $(this).children().each(function() {                                 if ($(this).attr('type') != 'radio') {                                     if ($(this).is('select')) {                                         window.container += ' ' + $(this).find(":selected").text() + ' ';                                     } else {                                         window.container += ' ' + $(this).val();                                         window.container += ' ' + $(this).text() + ' ';                                     }                                 }                             });                         }                     });                     $("#date_string").val(window.container);                 });              }); 

i did not update jsfiddle new code of 8/30/13 latest jsfiddle {got toggle work form now}: http://jsfiddle.net/2p6qq/9/

there syntax errors in fiddle fixed them & cleaned bit. result here: http://jsfiddle.net/2p6qq/12/. click event attached this:

$(document).on('click', '#every_days', function (e) {         if ($(this).is(":checked")) {             alert("is checked");         }  }); 

start reading event delegates here: http://api.jquery.com/delegate/ has since been superseded .on().


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -