1

i have a script for a datepicker and it puts the date selected to my input text:

<script type="text/javascript" language="javascript">
$(function () {
    $(".datepicker").datepicker({ onSelect: function (dateText, inst) { },
        altField: ".alternate"
    });

});

this is my form:

<form action="/" >

   <input type="text" class="alternate" onchange='this.form.submit()' readonly="readonly" />

</form> 

i would like to automatically submit the form everytime the value of input text changes.. everytime i select a new date in the datepicker, the input text changes, but the form does not submit... how could i do this?

raberana
  • 11,739
  • 18
  • 69
  • 95

2 Answers2

0
    $("#EleId").click({
         alert("Called");
    });

<form action="/" >

   <input type="text" id="EleId" class="alternate" onchange='this.form.submit()' />

</form> 
Dilip Godhani
  • 2,065
  • 3
  • 18
  • 33
0

See Call Javascript onchange event by programatically changing textbox value

Why not just use the onSelect event from the datepicker to submit the form?

Something like:

$(function () {
    $(".datepicker").datepicker({ onSelect: function (dateText, inst) { 
           $("#textboxID").val(dateText);
           $("FORM").submit();
        },
        altField: ".alternate"
    });
});
Community
  • 1
  • 1
Tim M.
  • 53,671
  • 14
  • 120
  • 163
  • how am i going to do that... i thought of that also but i did not do it because i dont know how to call the form in the onSelect event and make it submit – raberana May 11 '12 at 06:56
  • See the example I added. If you have multiple forms on the page, you will need to use the correct selector for the form. – Tim M. May 11 '12 at 06:57
  • $("FORM").submit(); is FORM the name of form? how would name the form... moreover, .submit() is not appearing in intellisense – raberana May 11 '12 at 07:01
  • "FORM" is a jquery selector for a tag name. You could also use an ID selector, class selector, whatever: http://api.jquery.com/element-selector/. If you are using jQuery UI, you definitely have jquery, so I wouldn't worry about it not showing in intellisense. – Tim M. May 11 '12 at 07:02
  • how could i retain the date selected??? because every time the form submits, the date selected is back to default... – raberana May 11 '12 at 07:09
  • If I recall, the datepicker is bound to a text input. When selection occurs, it should update that text input and the value should come back to the server. The server will need to repopulate the text input so that it comes back to the client and the datepicker "remembers" its original value. – Tim M. May 11 '12 at 07:13