Jump to content

evaluate javascript returned by php (maybe more of a javascript question)


Recommended Posts

php returns a chunk of code from my database, basically html and also js from a javascript library that creates a nice formatted date popup when you click the associated hyperlink to fill a textfield with after you choose a date...

But since i just add the chunk of code to innerHTML, it never runs the javascript needed so clicking the hyperlink doesnt cause the popup object to come up since the JS object wasnt created...

I was wondering how to do this. Not sure how to handle this, maybe some sort of function to parse the XML be4hand and pass whatever is inside <script> tags to javascript's eval() function.

 

//php returns this to my AJAX script in a CDATA section in a XML node which i attach to innerHTML

echo '<div>';

echo '<script language="Javascript" id="js1"> var startDatePopup = new CalendarPopup(); startDatePopup.setDisplayType("custom"); startDatePopup.showYearNavigation(); startDatePopup.setReturnCustomFunction("funcReturnStart"); function funcReturnStart(y,m,d) {document.getElementById(\'startDate\').value=m+\'/\'+d+\'/\'+y; } </script>';

echo '<span class="label">Start Date:</span>';

echo '<span class="answer"><input type="text" id="startDate" name="customParam[startDate]" value=""/>';

echo '<a href="#" onclick="startDatePopup.showCalendar(\'anchorStartDate\'); return false;" title="Write in this format: 12-25-2006" name="anchorStartDate" id="anchorStartDate">select</a>';

echo '</span>';//will show up if saved or error on form

echo '</div>';

 

echo '<div>';

echo '<script language="Javascript" id="js2"> var endDatePopup = new CalendarPopup(); endDatePopup.setDisplayType("custom"); endDatePopup.showYearNavigation(); endDatePopup.setReturnCustomFunction("funcReturnEnd"); function funcReturnEnd(y,m,d) {document.getElementById(\'endDate\').value=m+\'/\'+d+\'/\'+y; } </script>';

echo '<span class="label">End Date:</span>';

echo '<span class="answer"><input type="text" id="endDate" name="customParam[endDate]" value=""/>';

echo '<a href="#" onclick="endDatePopup.showCalendar(\'anchorEndDate\'); return false;" title="Write in this format: 12-25-2006" name="anchorEndDate" id="anchorEndDate">select</a>';

echo '</span>';//will show up if saved or error on form

echo '</div>';

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.