Hi all........
We normally use javascript to call ajax page to generate/formulate content and display the content using reponseText. But today i have tried to create a javascript function inside the ajax page to perform validation.
But this doesnot work fine even the responseText loaded with all the functions. but why, because all the javascript functions and inclusion of files are done when the page loads first time. since the javascript functions defined in ajax page it is not successfully loaded. So how to achieve this i'll tell you the simpler way. JUST load all the functions in the first page itself, and all the operations performed by javascript when loading the ajax page should be define inside the functions, you need to create and use inside the functions. i.e you should not set a value for control when loading a ajax page. The complete illustration is below
for eg:
//setting a value like this doesn't work
Calendar.setup(
{
inputField : "date1",
ifFormat : "%m/%d/%Y %I:%M %p",
button : "trigger1",
showsTime : "true",
timeFormat : "12"
} );
//the button trigger1 doesn't trigger anything in the main page since the javascript function is not inside the main page, so the above functionality as below to make it work.
first create a function
function setDate(val)
{
}
and include this function in the main page
after including change the code in the ajax page as below
now this will work fine.
i hope this helps someone.
We normally use javascript to call ajax page to generate/formulate content and display the content using reponseText. But today i have tried to create a javascript function inside the ajax page to perform validation.
But this doesnot work fine even the responseText loaded with all the functions. but why, because all the javascript functions and inclusion of files are done when the page loads first time. since the javascript functions defined in ajax page it is not successfully loaded. So how to achieve this i'll tell you the simpler way. JUST load all the functions in the first page itself, and all the operations performed by javascript when loading the ajax page should be define inside the functions, you need to create and use inside the functions. i.e you should not set a value for control when loading a ajax page. The complete illustration is below
for eg:
function ajaxCall()ajaxPage.php
{
xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET','ajaxPage.php',false);
xmlhttp.send();
document.getElementById('div').innerHTML = xmlhttp.responseText;
}
//setting a value like this doesn't work
<input id='date1' type='text'><button id="trigger1">...button>
Calendar.setup(
{
inputField : "date1",
ifFormat : "%m/%d/%Y %I:%M %p",
button : "trigger1",
showsTime : "true",
timeFormat : "12"
} );
//the button trigger1 doesn't trigger anything in the main page since the javascript function is not inside the main page, so the above functionality as below to make it work.
first create a function
function setDate(val)
{
Calendar.setup(
{
inputField : "date"+val,
ifFormat : "%m/%d/%Y %I:%M %p",
button : "trigger"+val,
showsTime : "true",
timeFormat : "12"
} );
}
and include this function in the main page
after including change the code in the ajax page as below
<input id="date1" type="text" />
<button id="trigger1" onclick='setDate(1)'>...button>
i hope this helps someone.
No comments:
Post a Comment