**Ajax dblookup code "Get the value in second combo based on the choise of first combo"**
This is easy to get values in other field based on the selection of text in one field without refreshing the whole form. This is all we can do with Ajax code.
This code i have tested in Mozilla and IE and working like charm!
How to Use:-
1) Form in which you want to use this ajax dblookup code
take a field named
"path" type text put default value @WebDbName
2) Take two field combo type say named "fieldselect" and "fieldget"
3) In "fieldselect" enter formula for your choices or enter choices (Whatever value you want in first field) to get the value
// Above was the designing and accessing value in fields with formula and all that your Ajax code will start now//
4) On change of "fieldselect" put follwing code:-
Tdatabase =document.forms[0].path.value; // Accessing Database NameObjT1=document.forms[0].fieldselect; //Making object of first field
keyVal=ObjT1.options[ObjT1.selectedIndex].text;
ObjT2=document.forms[0].fieldget; //Making object of second field
dbLookup("",Tdatabase,"Test",keyVal,2) //dbLookup (server,database,view,key,column)
5) In JS Header of the form Put following Code(Just Copy and Past):-
var TReq;
var ObjT2;
/*////////--Dblookup function ---////////*/
function dbLookup(server,database,view,key,column)
{
server = window.location.hostname;
if( !isNaN(column) )
column -= 1;
viewurl = "http://"+trim(server)+"/"+trim(database)+"/"+view+"?Readviewentries&restricttocategory="+key
if (window.XMLHttpRequest) //for Mozilla
{
TReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) // for IE
{
TReq = new ActiveXObject("Microsoft.XMLHTTP");
}
TReq.onreadystatechange = responseState;
TReq.open("GET", viewurl, true);
TReq.send(null);
}
function responseState()
{
if (TReq.readyState == 4) // Continue when Response from sever has arrived
{
if (TReq.status == 200) // Continue when everything is ok
{
response = TReq.responseXML;Mylookup(response)
}
else
{
alert("You are not getting the data check it" + TReq.statusText);
}
}
}
/* //// Extract Lookup value form XML data ////*/
function Mylookup(responseXML)
{
NodeList = responseXML.getElementsByTagName("viewentry")
var strValue="";
var Tsep="";
for(var i=0; i
{
strValue =strValue+Tsep+NodeList[i].getElementsByTagName("text")[0].childNodes[0].nodeValue
Tsep="¿"
}
strValuesplit = strValue.split("¿")
generateCombo(strValuesplit,ObjT2)
}
/*//////// Trim Function*/
function trim(str)
{
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
/*//Getting value in cobmo Function//*/
function generateCombo(data,inField)
{
inField.length=0
inField.length +=1
inField[inField.length-1].text = "--Select--"
for(vCount=0;vCount
{
inField.length +=1strText=data[vCount]
if (strText !=undefined && strText != null)
{
inField[inField.length-1].text = trim(strText)
}
}
}
Find the full Running code in images.
Because due to the some html code above part missing some line code.
1stimage:
2ndimage:
Subscribe to:
Post Comments (Atom)
excellent job done!!
ReplyDeleteThis is obviously an error:
ReplyDeletefor(var i=0; i
{
strValue =strValue+Tsep+NodeList[i].getElementsByTagName("text")[0].childNodes[0].nodeValue
Tsep="¿"
}
Hi friend due to the Html error right now this not excepting some text which is missing
ReplyDeleteMissing Code:
for(var i=0; ilessthanNodeList.length; i++)
replace lessthan by <
there is also some code missing in:
ReplyDeletefor(vCount=0;vCount
{
inField.length +=1strText=data[vCount]
if (strText !=undefined && strText != null)
Boss due to some html error its not showing some error if you want the same code send me your id . will do in favour of you.
ReplyDelete