Jump to content

How to reference calendar pop-up in Javascript


Recommended Posts

Hi all --

In a previous post, I asked about a block of code that "went bad" on me and stopped working. The code was part of a larger error-checking process in a real estate transactions database that gives alerts if you've selected an incorrect date range (among other checks). Part of the code runs a check when you use the calendar pop-up to fill in the date vs. typing in the box. Here was the original code:

function dateClickStart () {

document.getElementById('caspioform').Value5_1.focus();

if (document.getElementById) {if(document.getElementById('Value5_1')!= null){ try {v_cal.select(document.getElementById('Value5_1'),'a1','MM/dd/yyyy');return false;} catch (e) {}}};
}

function dateClickEnd ()
{
document.getElementById('caspioform').Value5_2.focus();

if (document.getElementById) {if(document.getElementById('Value5_2')!= null){ try {v_cal.select(document.getElementById('Value5_2'),'a2','MM/dd/yyyy');return false;} catch (e) {}}};
}

document.getElementById("a1").onclick = dateClickStart;
document.getElementById("a2").onclick = dateClickEnd;

"a1" and "a2" are references to the calendar pop-up, but when I run Firebug to see how the pop-ups are referenced, it appears to be dynamic -- i.e., with IDs and names like "a1_963361391." When I remove this code block, the rest of the code works, and the error that shows up on this code says "a1 is null" which tells me I'm not referencing the calendar pop-up correctly.

Any ideas? Thanks!

-- Mike

Link to comment
Share on other sites

Hi Mike,

That is right, the calendar element ID is a dynamic one and keeps changing every time page reloads and that is why you can not call the object by its ID. I would suggest to find another event listener to check the dates, for example on form submit call the function.

Best,

Bahar M.

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