Using radio button to trigger an action

I am doing a project where I need two radio buttons for date selection.One radio button takes the system date and prints but the other button when I select,I want the user to be able to enter the date(basically I want a text field to appear when I click on the second radio button).I am new to html coding so please if anyone could help me.I read about javascript and jquery but the examples that I saw werent able to provide any help. I have already added the radio buttons

<table border="1" width="100%">
<tr>
 <th> Date</th>
</tr>
<td>
  Current date<input type="radio" name="zing" id="foo" checked/>
  Add date<input type="radio" name="zing" id="bar"/></td>
</table>

Please could someone suggest me an idea.

Answers:

Answer
<table border="1" width="100%">
<tr>
 <th> Date</th>
</tr>
<td>
  Current date<input type="radio" name="zing" id="foo" checked/>
  Add date<input type="radio" name="zing" id="bar"/>
<input type='text' id='txtDate' style='display:none'/>
</td>
</table>

then write down below script

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script>
$(document).ready(function(){
  $("#bar").change(function(){
       $("#txtDate").show();
  });
$("#foo").change(function(){
       $("#txtDate").hide();
  });
});
</script>
Answer

Try this

 $(function(){
      $("input:radio:first").click();
    });

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.