dhcrusoe Posted July 27, 2009 Share Posted July 27, 2009 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; } Quote Link to comment Share on other sites More sharing options...
haku Posted July 27, 2009 Share Posted July 27, 2009 What do you mean "the values aren't coming across"? What do you want to happen? What is actually happening? Quote Link to comment Share on other sites More sharing options...
dhcrusoe Posted July 27, 2009 Author Share Posted July 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
haku Posted July 27, 2009 Share Posted July 27, 2009 And how is it supposed to get that way? Where is this data coming from? Give as much information as you can, please try to be a little less vague. Quote Link to comment Share on other sites More sharing options...
dhcrusoe Posted July 27, 2009 Author Share Posted July 27, 2009 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> Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted July 27, 2009 Share Posted July 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
haku Posted July 27, 2009 Share Posted July 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
dhcrusoe Posted July 27, 2009 Author Share Posted July 27, 2009 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. 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.