I have a custom list that contains a date time field. The client requested we trim the time portion of the field to only show two available appointment times of 8:30 am and 1:30 pm. In order to do this I added the following javascript code to the New and Edit forms of the list. The problem I am having is when the users open the edit form it does not maintain the previously selected time value. It shows the first available value of 8:30 AM, so if the users open the edit form and change some other field than the time field they inadvertently change the originally selected time field to 8:30 am even if the originally selected time was 1:30PM. How can I get the code to default to the originally selected time value from the New form within Edit form?
<script type="text/javascript">
$(document).ready(function () {
var str=['8 AM','1 PM'];
$("select[id$='_DateTimeField_DateTimeFieldDateHours']").each(function(i){
$(this).html("");
for(var i=0;str[i]!=null;i++){
$(this).append('<OPTION value="'+str[i]+'">'+str[i]+'</OPTION>');
}
});
});
</script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var str=['30'];
$("select[id$='_DateTimeField_DateTimeFieldDateMinutes']").each(function(i){
$(this).html("");
for(var i=0;str[i]!=null;i++){
$(this).append('<OPTION value="'+str[i]+'">'+str[i]+'</OPTION>');
}
});
});
</script>