Henco Posted March 19, 2019 Report Share Posted March 19, 2019 Hi! I am trying to create 8 Date/Time fields where the user inputs Date, Hours and Minutes in separate fields. I found some JS that works on combining the input, but it only works on combining one set of the three fields to on Display Field. This is the code that I put in the Footer: <script> //Created_On_From document.getElementsByName('Submit')[0].onmouseover = function(){ var date = document.getElementById('cbParamVirtual11').value; if(date == ""){ date = "00/00/0000"; } var hour = document.getElementById('cbParamVirtual26').value; if(hour == "") { hour = "00"; } var minute = document.getElementById('cbParamVirtual27').value; if(minute == "") { minute = "00"; } document.getElementById('cbParamVirtual49').value = date + " " + hour +":"+ minute; }; </script> <script> //Created_On_To document.getElementsByName('Submit')[0].onmouseover = function(){ var date = document.getElementById('cbParamVirtual18').value; if(date == ""){ date = "00/00/0000"; } var hour = document.getElementById('cbParamVirtual33').value; if(hour == "") { hour = "00"; } var minute = document.getElementById('cbParamVirtual32').value; if(minute == "") { minute = "00"; } document.getElementById('cbParamVirtual48').value = date + " " + hour +":"+ minute; }; </script> Any help would be appreciated... Quote Link to comment Share on other sites More sharing options...
douvega Posted March 19, 2019 Report Share Posted March 19, 2019 Try this: //function to grab date parts function setDateParts(date_field, hour_field, minute_field, full_date_field){ var d = document.getElementById(date_field).value; var h = document.getElementById(hour_field).value; var m = document.getElementById(minute_field).value; if(d == ""){ d = "00/00/0000"; } if(h == ""){ h = "00"; } if(m == ""){ m = "00"; } document.getElementById(full_date_field).value = d + " " + h +":"+ m + ":00"; }; document.getElementsByName('Submit')[0].onmouseover = function(){ setDateParts('cbParamVirtual11', 'cbParamVirtual26', 'cbParamVirtual27', 'cbParamVirtual49'); setDateParts('cbParamVirtual18', 'cbParamVirtual33', 'cbParamVirtual32', 'cbParamVirtual48'); //you could continue adding more combinations depending on how many sets you want to concatenate. } Please notify me if it works. Regards. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 19, 2019 Report Share Posted March 19, 2019 You need to combine your scripts and name your variables unique: <script> //Created_On_From document.getElementsByName('Submit')[0].onmouseover = function(){ var date = document.getElementById('cbParamVirtual11').value; if(date == ""){ date = "00/00/0000"; } var hour = document.getElementById('cbParamVirtual26').value; if(hour == "") { hour = "00"; } var minute = document.getElementById('cbParamVirtual27').value; if(minute == "") { minute = "00"; } document.getElementById('cbParamVirtual49').value = date + " " + hour +":"+ minute; //Created_On_To var date2 = document.getElementById('cbParamVirtual18').value; if(date2 == ""){ date2 = "00/00/0000"; } var hour2 = document.getElementById('cbParamVirtual33').value; if(hour2 == "") { hour2 = "00"; } var minute2 = document.getElementById('cbParamVirtual32').value; if(minute2 == "") { minute2 = "00"; } document.getElementById('cbParamVirtual48').value = date2 + " " + hour2 +":"+ minute2; }; </script> 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.