-2

I am trying to get input text from html scala templete form with jquery that the value of that input text is the date and i pass it to the controller to be converted into date format then be reused on the interface but i get null value ,please help me.

Image error

scala tamplete:

 ...........

  <form  class="" role="form"   id="mapform">
                   <table width="1000" >
                    <tr>
                      <td width="500">
                          <div class="form-group col-sm-6">
                          <select name="names" class="form-control" 
id="dropdown" required="true">
                              <option value="">   </option>
                              @for(d <- Driver_registrationInfo.findAll()){
                                  <option id="namesId" name="names" value="@d.names"> @d.names </option>
                              }
                          </select>
                          </div>

                      </td>

                      <td width="500" >
                          <div class="form-group  col-sm-8">

                             <div class="col-lg-10">
                                  <div class='input-group date' id="datetimepicker8">
                                      <input type='text' class="form-control message"  id="datesfield"  name="dateSelect" required="true"/>
                                      <span class="input-group-addon">
                                          <i class="fa fa-calendar" aria-hidden="true"></i>
                                      </span>
                                  </div>
                              </div>
                          </div>

                      </td>

                      <td>
                          <div class="form-group ">

                          <input type='submit' class="form-control btn btn-danger" id="plot_marker" value="Track" />
                              </div>

.................

Jquery function :

.....

$('#plot_marker').click(function(e){
e.preventDefault();

   var ioId2 = document.getElementById('datesfield').value;
   if(ioId2 ) {
    var nextUrl = "/searched/";
    window.location = nextUrl;
     }

......

Controller:

......

    public static Result searched() {
    Form<Coordinates> coordinatesForm = 
   Form.form(Coordinates.class).bindFromRequest();

    String names = coordinatesForm.field("names").value();
//  selected date on form convert it to string
    Date dateSelect = new 
   Date(coordinatesForm.field("dateSelect").value());
    DateFormat df = new SimpleDateFormat("yyy-MM-dd");
    String DateString = df.format(dateSelect);
    return ok(admin.render(names, DateString));
   }
     ......
  • Please read [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) before attempting to ask more questions. –  Jul 14 '17 at 05:03
  • [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) –  Jul 14 '17 at 05:03
  • Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before attempting to ask more questions. –  Jul 14 '17 at 05:03
  • [What does your step debugger tell you?](http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) –  Jul 14 '17 at 05:03
  • 1
    Possible duplicate of [Submit a form using jQuery](https://stackoverflow.com/questions/1200266/submit-a-form-using-jquery) – Paul Roub Jul 14 '17 at 14:03

1 Answers1

0

The proble was the jquery function i was using , when you use $('#plot_marker').click(function(e){ e.preventDefault(); it blocks form submition functionality , and play framework consider post method as GET.

to correct this error i used Jquery submitting a form function

$('plot_marker').click( function() {
  $.post( '/searched/', $('form#mapform').serialize(), function(data) {
  ...
       },
       'json' // I expect a JSON response
   );
 });

Visit stackoverflow answer