Jump to content

Dates not combining - what's going wrong?


dhcrusoe

Recommended Posts

Hey all,

 

I have a bit of JS code that combines three date fields into one, and then checks to ensure it's set... for some reason, the values aren't coming across. The final result, field j_id0:CT_App_Template:background_check__c:BGC_DOB__c , needs to be in MM-DD-YYYY format...  Any suggestions? -- Thanks!

 

Here's the code:

 

var y = document.getElementById("j_id0:CT_App_Template:background_check__c:BGC_DOB__c");
		var t = y.value.split("-");
			document.getElementById("bd_month").value = t[1];
		document.getElementById("bd_day").value = t[2];
		document.getElementById("bd_year").value = t[0];
	y.value = t;
	alert(y.value);

	if(y.value == ""){
		alert("Please enter DOB");
		event.cancelBubble == true;
		el.focus();
		return false;
	}

Link to comment
Share on other sites

Thanks for your question -- the end result should be that:

 

j_id0:CT_App_Template:background_check__c:BGC_DOB__c.value == MM-DD-YYYY, like 02-08-1974

 

 

 

 

What do you mean "the values aren't coming across"?

 

What do you want to happen?

What is actually happening?

 

Link to comment
Share on other sites

Haku,

 

Sorry - had been trying to write a concise message, but I guess it was too concise. Here's the codebase that it pulls from, and is supposed to assign to (below). Basically, we have three fields - a day and month dropdown, and a year input box, and then need to combine that to feed a hidden field, BGC_DOB__c (this is all on Force.com). For some reason, it isn't populating - and as long as it populates in MM-DD-YYYY, it will store... 

 

<label for="BGC_DOB__c">Date of Birth:</label>
                
                <select name="bd_month" id="bd_month" style="width: 100px;">
					<option value="01">January</option>
					<option value="02">Febuary</option>
					<option value="03">March</option>
					<option value="04">April</option>
					<option value="05">May</option>
					<option value="06">June</option>
					<option value="07">July</option>
					<option value="08">August</option>
					<option value="09">September</option>
					<option value="10">October</option>
					<option value="11">November</option>
					<option value="12">December</option>
                	</select>
                	
                	<select name="bd_day" id="bd_day" style="width: 50px; margin-left: 5px;">
					<option value="01">1</option>
					<option value="02">2</option>
					<option value="03">3</option>
					<option value="04">4</option>
					<option value="05">5</option>
					<option value="06">6</option>
					<option value="07">7</option>
					<option value="08">8</option>
					<option value="09">9</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
					<option value="13">13</option>
					<option value="14">14</option>
					<option value="15">15</option>
					<option value="16">16</option>
					<option value="17">17</option>
					<option value="18">18</option>
					<option value="19">19</option>
					<option value="20">20</option>
					<option value="21">21</option>
					<option value="22">22</option>
					<option value="23">23</option>
					<option value="24">24</option>
					<option value="25">25</option>
					<option value="26">26</option>
					<option value="27">27</option>
					<option value="28">28</option>
					<option value="29">29</option>
					<option value="30">30</option>
					<option value="31">31</option>
				</select>
                	
                <input style="width: 40px; margin-left: 5px;" type="text" id="bd_year" name="bd_year" value="yyyy" length="4" width="80px" onFocus="fnClear(this);"></input>
                    
                    <apex:inputhidden id="BGC_DOB__c" value="{!Background_Check__c.BGC_DOB__c}" />
                
                <span class="required">  </span>
                </div>

 

Link to comment
Share on other sites

what your doing is alerting the value of y wich is good you need to make sure you can see it in the alert box.

 

then at the same time you need to only split the DOB if its value.length is more than 1 and if it has -'s in it.

 

once you have split it check by looping throgh

 

for(i=0;i<myarray.length;i++){

        alert(myarray);

}

 

after you make sure it splits how you need it to split,

 

then i recomend you download some framework and use its date functionality.

 

javascript documentaion is way out of controle its complex, use a framework

Link to comment
Share on other sites

So you are trying to assign the values of the select elements to the hidden form element?

 

var y = document.getElementById("j_id0:CT_App_Template:background_check__c:BGC_DOB__c");
var bdMonthIndex = document.getElementById("bd_month").selectedIndex;
var bdMonth = document.getElementById("bd_month")[bdMonthIndex].value
var bdDayIndex = document.getElementById("bd_day").selectedIndex;
var bdDay = document.getElementById("bd_day")[bdDayIndex].value;
var bdYear = document.getElementById("bd_year").value;
var bday = bdMonth + "-" + bdDay + "-" + bdYear;
y.value = bday;

 

Something like that. I didn't check it for bugs, but it should get you on your way.

Link to comment
Share on other sites

Haku,

 

Yes, exactly - thanks so much for the suggestion (it works!) and my apologies for not being as clear up front. It's a great example that I'll apply elsewhere in the codebase as well... 

 

Cheers,

--Dave

 

So you are trying to assign the values of the select elements to the hidden form element?

 

var y = document.getElementById("j_id0:CT_App_Template:background_check__c:BGC_DOB__c");
var bdMonthIndex = document.getElementById("bd_month").selectedIndex;
var bdMonth = document.getElementById("bd_month")[bdMonthIndex].value
var bdDayIndex = document.getElementById("bd_day").selectedIndex;
var bdDay = document.getElementById("bd_day")[bdDayIndex].value;
var bdYear = document.getElementById("bd_year").value;
var bday = bdMonth + "-" + bdDay + "-" + bdYear;
y.value = bday;

 

Something like that. I didn't check it for bugs, but it should get you on your way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.