0

I am designing a project in Asp.net-MVC 5 with C#. I am having a textbox along with a calendar Icon attached at the end. codings below:

Design:

<div class="col-md-4  col-lg-4">
   <label>From</label>
   <div class="input-group date">
      <input type="text" name="q" id="txtFrom" class="form-control" >
      <span class="input-group-btn">
      <button type="submit" name="search" id="datepicker" class="btn btn-flat btn-success">
      <i class="fa fa-calendar"></i>
      </button>
      </span>
   </div>
</div>

Script:

<script>
        $(function () { 
          $('#txtFrom').datepicker({
           autoclose: true
       })       
   })
</script>

This one is working fine, like when I click the text box, the calendar pops up and the selected date was shown in 'From' text box.

But, What I need is-the calendar must pop up only if the calendar Icon got clicked and the selected date must be displayed in 'From' Text box.

If I changed the script as below

Script:

 <script>
        $(function () { 
          $('#datepicker').datepicker({
           autoclose: true
       })       
   })
</script>

then the Pop up comes when Calendar Icon got clicked, but the value not sent to the text box. Image of my TextBox Design :

Image of my TextBox Design

Kindly Help. TIA.

Keyur Ramoliya
  • 1,900
  • 2
  • 16
  • 17
Riya
  • 157
  • 5
  • 22

2 Answers2

1

You could try to use html5 tag

<input type="date">
SelfishCrawler
  • 225
  • 2
  • 12
1

If you want to choose year only, like you asked in your comment, see this:

Can I use an HTML input type "date" to collect only a year?

Or this (even nicer):

`http://jsfiddle.net/lemonkazi/ucfxywh6/`
Presi
  • 806
  • 10
  • 26
  • Fiddle one is what I am looking for.. But I tried ur both answers but it is not working for me.. I dont know Y.. I used the same code... – Riya Jul 20 '19 at 06:04
  • What's the problem? Not showing or what is happening – Presi Jul 20 '19 at 10:21
  • I used the code.. while clicking testbox- there is no change.. I used the same code from fiddle that u gave, but calendar year pop up never come out.. which means the function in script is not working ah?? – Riya Jul 22 '19 at 07:24
  • I think you forgot to add the javascript libraries. In the fiddle are the ressources. You need them to execute the code – Presi Jul 22 '19 at 07:54