Jump to content

Multiple Inputs to Multiple Fields


Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...