Jump to content
  • 0
roattw

Separate Input Fields for Date/Time Parts - Done twice on same form page?

Question

I need START Time and an END Time  on a form.  I was using the Separate Input Fields for Date/Time Parts steps.  Works well but only once.

But I need to do it twice.  I need to use it once for a Start Time field and an  End Time field.

When I enter the script twice in footer (once for a start time section, once for an end time section) it doesnt work anymore.  Also tried combining them but no luck.

<script>
document.getElementsByName('Submit')[0].onmouseover = function(){ 
<script> var date = document.getElementById('cbParamVirtual1').value;
if(date == "") { date = "1/1/2011"; }
var hour = document.getElementById('cbParamVirtual2').value;
if(hour =="") { hour="00"; }
var minute = document.getElementById('cbParamVirtual3').value;
if(minute == "") { minute = "00"; }
document.getElementById('InsertRecordTIME1').value = date + " " + hour + ":" + minute;
};
</script>
<script>
document.getElementsByName('Submit')[0].onmouseover = function(){ 
var date2 = document.getElementById('cbParamVirtual4').value;
if(date == "") { date = "1/1/2011"; }
var hour2 = document.getElementById('cbParamVirtual5').value;
if(hour =="") { hour="00"; }
var minute2 = document.getElementById('cbParamVirtual6').value;
if(minute == "") { minute = "00"; }
document.getElementById('InsertRecordTIME2').value = date + " " + hour + ":" + minute;
};
</script>

Any way to run this twice.  Or a better way to get a Start Time and End Time fields using time values so they can be subtracted as time between intervals later?

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello @roattw

Try to use this code:

<script>
function first() {
	var date = document.getElementById('cbParamVirtual1').value;
	if(date == "") { date = "1/1/2011"; }
	var hour = document.getElementById('cbParamVirtual2').value;
	if(hour =="") { hour="00"; }
	var minute = document.getElementById('cbParamVirtual3').value;
	if(minute == "") { minute = "00"; }
	document.getElementById('InsertRecordTIME1').value = date + " " + hour + ":" + minute;
}

function second() {
	var date2 = document.getElementById('cbParamVirtual4').value;
	if(date == "") { date = "1/1/2011"; }
	var hour2 = document.getElementById('cbParamVirtual5').value;
	if(hour =="") { hour="00"; }
	var minute2 = document.getElementById('cbParamVirtual6').value;
	if(minute == "") { minute = "00"; }
	document.getElementById('InsertRecordTIME2').value = date + " " + hour + ":" + minute;
}

document.getElementsByName('Submit')[0].addEventListener('mouseover', first);
document.getElementsByName('Submit')[0].addEventListener('mouseover', second);
</script>

You should add new events using "addEventListener()" method. In other case, you will just overwrite the existing one.

Share this post


Link to post
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
Answer this question...

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