Page 1 of 1

javascript problem

PostPosted: Fri Mar 09, 2012 5:30 am
by samhans
hai Steve and all;

i have made a page which without refreshing shows the search result from database.
for that i have made a html form with javascript . i have tested it and it is working.
outside xataface .
the exact code is like this:

< html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

this form onchange call the javascript and the javascript calls a getuser.php file which query the database and shows the result as a table.

i have tested it and its working. but i failed to integrate it with xataface main templates.
to integrate i have made a search.html form in templates folder and a action to show the templates as default as we make dashboard. i have included the javascript my application delegate class get included.
but when i am selecting the name in search page nothing happens . hopefully i think the javascript is not called at all. please help me to say where i am wrong.


thanks in advance

Re: javascript problem

PostPosted: Fri Mar 09, 2012 10:34 am
by shannah
Hard to comment with this amount of information. Troubleshooting Javascript involves:
1. Checking your javascript error log and following clues.
2. Reviewing the resulting Page source to see that the javascript is actually included.
3. Adding messages in javascript at various points to see what code is executing (e.g. using console.log() if you are using chrome, safari, or Firefox - or just alert() otherwise).


-Steve

Re: javascript problem

PostPosted: Fri Mar 09, 2012 10:43 am
by samhans
Steve the code is ok i have checked it and its working. please check the xmlhttp.open tag in my javascript. is this will work in xataface

Re: javascript problem

PostPosted: Fri Mar 09, 2012 10:49 am
by shannah
Anything that will work outside Xataface will work inside Xataface.
You just have to be aware of your context and environment.

Re: javascript problem

PostPosted: Fri Mar 09, 2012 10:53 am
by samhans
Steve can i included javascript inside the macro tag in my search html template.