kpcollier Posted May 3, 2021 Report Share Posted May 3, 2021 I have a datapage with 2 date fields and I am using the timepicker to set the Time for them. The script I have is working, however I'd like to make some minor changes and it seems to be difficult for me. document.getElementsByName('Mod0EditRecord')[0].onmouseover = function(){ var date = document.getElementById('EditRecordTech_Schedule_Table_2_Date').value; if(date == "") { date = "1/1/2011"; } var ampm = document.getElementById('timepicker1').value; var ampm2 = document.getElementById('timepicker2').value; document.getElementById('EditRecordTech_Schedule_Table_2_Time_From').value = date + " " + ampm; document.getElementById('EditRecordTech_Schedule_Table_2_Time_To').value = date + " " + ampm2; }; Right now, this is working if you give both Timepickers a time. However, if you only update one of the timepickers, the other defaults to '12:00:00'. I would like it to not update that particular date field if the timepicker is blank/null. Any help is appreciated. Quote Link to comment Share on other sites More sharing options...
kpcollier Posted May 3, 2021 Author Report Share Posted May 3, 2021 (edited) I have tried inserting an IF statement - if (ampm !== null) - but it is updating it to the default '12:00:00' regardless. **Here is the script if anyone is looking for the answer to this problem. document.getElementsByName('Mod0EditRecord')[0].onmouseover = function(){ var date = document.getElementById('EditRecordTech_Schedule_Table_2_Date').value; if(date == "") { date = "1/1/2011"; } var ampm = document.getElementById('timepicker1').value; var ampm2 = document.getElementById('timepicker2').value; if (ampm !== null && ampm !== ''){ document.getElementById('EditRecordTech_Schedule_Table_2_Time_From').value = date + " " + ampm; } if (ampm2 !== null && ampm2 !== ''){ document.getElementById('EditRecordTech_Schedule_Table_2_Time_To').value = date + " " + ampm2; } }; Edited May 4, 2021 by kpcollier Added solution Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted May 4, 2021 Report Share Posted May 4, 2021 20 hours ago, kpcollier said: I have tried inserting an IF statement - if (ampm !== null) - but it is updating it to the default '12:00:00' regardless. Here is the script if anyone is looking for the answer to this problem. document.getElementsByName('Mod0EditRecord')[0].onmouseover = function(){ var date = document.getElementById('EditRecordTech_Schedule_Table_2_Date').value; if(date == "") { date = "1/1/2011"; } var ampm = document.getElementById('timepicker1').value; var ampm2 = document.getElementById('timepicker2').value; if (ampm !== null && ampm !== ''){ document.getElementById('EditRecordTech_Schedule_Table_2_Time_From').value = date + " " + ampm; } if (ampm2 !== null && ampm2 !== ''){ document.getElementById('EditRecordTech_Schedule_Table_2_Time_To').value = date + " " + ampm2; } }; What happens? Do you have a sample DataPage? nothing happens when my 2 fields are null (2and 3 for timepicker 1 and 2) If I put a value, it appends, Maybe you have some stray script or triggered action? Quote Link to comment Share on other sites More sharing options...
kpcollier Posted May 4, 2021 Author Report Share Posted May 4, 2021 Sorry @TellMeWhy, you may have missed the 'Edited' remark on my last response. I had found the solution myself and posted it there. It is working as intended. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted May 4, 2021 Report Share Posted May 4, 2021 2 minutes ago, kpcollier said: Sorry @TellMeWhy, you may have missed the 'Edited' remark on my last response. I had found the solution myself and posted it there. It is working as intended. Thanks for the help! Oh, alright, sorry about that, thank you for the solution, as well! kpcollier 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.