arianhojat Posted October 10, 2007 Share Posted October 10, 2007 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/72665-evaluate-javascript-returned-by-php-maybe-more-of-a-javascript-question/ 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.