Jump to content

Multiple Java Script Concatenate/combine Fields In A Footer


Recommended Posts

Hello, 

 

I am trying to edit the Java Script in the footer of a Submission Form to allow me to Concatenate Two separate Date/Time Fields. The first is a "Trip Start Date and Time" and the Second is a "Trip End Date and Time" as shown in the following attachment: post-20434-0-57276500-1464291295_thumb.p

 

The issue I'm having is that I can make one operate correctly when alone in the footer but not when I add the second. 

 

It was suggested to me that the issue may lie in the "getElementById" function and having it "defined twice" and that one may be overwriting the other. Attached are two snips of the code I have in the footer: post-20434-0-31054500-1464291294_thumb.ppost-20434-0-00935500-1464291295_thumb.p

 

I need to accomplish this in a Gallery Report Data Page as well.

 

Any thoughts?

 

Thank you, 

 

Tyler

Link to comment
Share on other sites

You need to combine your scripts and have different parameter name for instance:

<script>
document.getElementById('Submit').onmouseover = function(){
var date =
document.getElementById('cbParamVirtual1').value;
if(date == "")
date = "1/1/2011";
var hour = parseFloat(document.getElementById('cbParamVirtual2').value) + parseFloat(document.getElementById('cbParamVirtual5').value);
if(hour =="24")
hour="12";
else if(hour =="12")
hour="00";
var minute = document.getElementById('cbParamVirtual3').value;
if(minute == "")
minute = "00";
var second = document.getElementById('cbParamVirtual4').value;
if(second == "")
second = "00";
document.getElementById('InsertRecordDate_Field').value = date + " " + hour +":"+ minute +":"+second;


var date2 =
document.getElementById('XXXXXXX').value;
if(date2 == "")
date2 = "1/1/2011";
var hour2 = parseFloat(document.getElementById('YYYYYYY').value) + parseFloat(document.getElementById('ZZZZZZ').value);
if(hour2 =="24")
hour2="12";
else if(hour2 =="12")
hour2="00";
var minute2 = document.getElementById('DDDDD').value;
if(minute2 == "")
minute2 = "00";
var second2 = document.getElementById('TTTTTT').value;
if(second2 == "")
second2 = "00";
document.getElementById('BBBBBBBB').value = date2 + " " + hour2 +":"+ minute2 +":"+second2;
};
</script>

Make sure to replace IDs with actual IDs

Link to comment
Share on other sites

Thank you May Music,

 

This is what I ended up with. What do you think?

 

..............................................................................................................................

 
<SCRIPT LANGUAGE="JavaScript">
 
 
document.getElementById('caspioform').onchange = function(){
 //This takes the date and time and concatenates into one variable
 //!!! If on submission form use 'INSERT' record
 //!!! if on management form use 'EDIT' record
 // Date  
 var dt1 = document.getElementById('cbParamVirtual1').value;
 var dt2 = document.getElementById('cbParamVirtual5').value;
 // hours
 var hr1 = document.getElementById('cbParamVirtual2').value;
 var hr2 = document.getElementById('cbParamVirtual6').value;
 // Minutes
 var mn1 = document.getElementById('cbParamVirtual3').value;
 var mn2 = document.getElementById('cbParamVirtual7').value;
 //Seconds
 var seconds = "00";
 
var ampm1 =  document.getElementById('cbParamVirtual4').value;
var ampm2 = document.getElementById('cbParamVirtual8').value;
 
var dateAndTime1 =  dt1 + " " + hr1 + ":" + mn1 + ":" + seconds + " " + ampm1;
var dateAndTime2 =  dt2 + " " + hr2 + ":" + mn2 + ":" + seconds + " " + ampm2;
 
// First date/time field
if (dt1 !== "" && hr1 !== "" &&  mn1 !== "" &&  ampm1 !== "" )
{
    document.getElementById('InsertRecordStart_Date_and_Time').value = dateAndTime1; 
}
else 
{
   document.getElementById('InsertRecordStart_Date_and_Time').value = ""; 
}
 
// Second date/time field
 
if (dt2 !== "" && hr2 !== "" &&  mn2 !== "" &&  ampm2 !== "" ){
    
   document.getElementById('InsertRecordEnd_Date_and_Time').value = dateAndTime2; 
}
else
{
    
      document.getElementById('InsertRecordEnd_Date_and_Time').value = ""; 
}
 
};
</SCRIPT>
 
.......................................................................................................................................................
 
Thanks,
 
Tyler
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...