Cherry
Cherry

Reputation: 675

calling input value using jquery val() method not working after space in my MVC View?

Here is my code :

In My MVC View:

  @
  {
  var datefrom = Model.Vehicle.First().DateFrom.ToString("MMMM    yyyy")
  };

In my AjaxBeginForm:

    {
     <input type="hidden" id="vehicledatefrom" value=@datefrom/>
    }

My jquery:

          var datefromto= $('#vehicledatefrom').val() ;



   After debugging with break point, the datefrom value is = " July 2006";
   But when I am calling the val() in jquery I am getting only "July".
   What's the wrong in my code why I am not getting complete value "July 2006";
   val() is not taking after the space why any suggestions thanks

Upvotes: 1

Views: 1145

Answers (1)

Sushanth --
Sushanth --

Reputation: 55750

That is because you have not enclosed the value attribute using quotes.

And it seems to taking only the first part of the value before it is encountering a space which it thinks is the end of it.

Upvotes: 2

Related Questions