Page 1 of 1

[SOLVED] Can anybody help me get this working?

Posted: Wed Feb 22, 2012 9:03 pm
by spike1968
Hi,

I have the following code in a module

Code: Select all

$lists['pcat_id'] 	= JHTML::_('select.genericlist',$p_category,  'pcat_id', 'class="inputtext" onchange="getsubcat(this.value);" ', 'pcid', 'title',0);
The function getsubcat is as follows

Code: Select all

function getsubcat(cid)
{		
 	xmlHttp = GetXmlHttpObject();
	
	var subcat_label=document.getElementById("sc_label").value; // Imported Label for List from helper.php
	
	xmlHttp.onreadystatechange =function() {		
		if (xmlHttp.readyState == 4 && xmlhttp.status==200) {			

			document.getElementById("sub_div").innerHTML=xmlHttp.responseText; // Element id in default layout
		}
	}	 
	var url = live_path+"modules/mod_cyril_ajaxselectcontent/subcategories.php?pcat_id="+cid+"&subcat_lbl="+subcat_label;
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null);			
}
I know I have got something wrong but have been banging my head against a screen for a while now and can't see the wood.

The following works as I have placed this url in my browser and substituted with exact values and I know the php for subcategories.php works.

Code: Select all

var url = live_path+"modules/mod_cyril_ajaxselectcontent/subcategories.php?pcat_id="+cid+"&subcat_lbl="+subcat_label;
What seems to be the problem is the transfer of the value 'cid'. I'm lost can anybody help me.

Cheers

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 9:55 am
by shakur1911
Hello,

What do you get when you alert cid in getsubcat?
Any errors on your firebug console?

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 11:21 am
by spike1968
Thanks for coming back to me
shakur1911 wrote:What do you get when you alert cid in getsubcat?
This is something I am not familiar with as ajax/javascript is something I am muddling through, what do you mean?
Any errors on your firebug console?
I assume you mean firebug on firefox, i don't use this much as each time i've tried to it crashes my pc.

Is there a google chrome extension that would do the same for me?

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 11:26 am
by spike1968
Got firebug lite for chrome now...

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 11:33 am
by spike1968
shakur1911 wrote:What do you get when you alert cid in getsubcat?
Do you mean change the php code?
shakur1911 wrote: Any errors on your firebug console?
I now have lite installed, what am I looking for? Any tips would be welcome.

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 12:30 pm
by shakur1911
Hello spike,

From your code I guess that this.value does not get what you expect that is why i suggested in your Javascript method to do a

Code: Select all

alert(cid);
to see what you send to getsubcat. In chrome you can use the Javascript console provided by default in Developers tools

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 12:45 pm
by spike1968
shakur1911 wrote: From your code I guess that this.value does not get what you expect that is why i suggested in your Javascript method to do a

Code: Select all

alert(cid);
to see what you send to getsubcat. In chrome you can use the Javascript console provided by default in Developers tools
Sorry for my ignorance where exactly should I put alert(cid), in the onchange code or in the ajax code itsself?

Javascript console in tools, now why didn't I look closely , doh!

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 12:49 pm
by shakur1911
something like this

Code: Select all

function getsubcat(cid)
{      
alert(cid);
    xmlHttp = GetXmlHttpObject();
   
   var subcat_label=document.getElementById("sc_label").value; // Imported Label for List from helper.php
   
   xmlHttp.onreadystatechange =function() {      
      if (xmlHttp.readyState == 4 && xmlhttp.status==200) {         

         document.getElementById("sub_div").innerHTML=xmlHttp.responseText; // Element id in default layout
      }
   }    
   var url = live_path+"modules/mod_cyril_ajaxselectcontent/subcategories.php?pcat_id="+cid+"&subcat_lbl="+subcat_label;
   xmlHttp.open("GET", url, true)
   xmlHttp.send(null);         
}
also, where do you get the live_path from?

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 1:23 pm
by spike1968
Live path is already set within the site.

Thanks for help with the code......

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 1:27 pm
by spike1968
Thanks that has confirmed that 'cid' is not defined... why i don't know but now I know what's happening I can start looking in the right place...

Any ideas would be welcome...

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 1:40 pm
by shakur1911
spike1968 wrote:Thanks that has confirmed that 'cid' is not defined... why i don't know but now I know what's happening I can start looking in the right place...

Any ideas would be welcome...
hmm giving the code that produces $p_category might clarify things..

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 1:46 pm
by spike1968
Just uploaded the file with alert(cid) and that then worked and displayed the correct value, so that bit is working, so it must be something in the ajax code that's causing it not to work.

Code: Select all

 function getsubcat(cid)
{
	alert(cid);
 	xmlHttp = GetXmlHttpObject();
	
	var subcat_label=document.getElementById("sc_label").value; // Imported Label for List from helper.php
	
	xmlHttp.onreadystatechange =function() {		
		if (xmlHttp.readyState == 4 && xmlhttp.status==200) {			

			document.getElementById("sub_div").innerHTML=xmlHttp.responseText; // Element id in default layout
		}
	}	 
	var url = live_path+"modules/mod_cyril_ajaxselectcontent/subcategories.php?pcat_id="+cid+"&subcat_lbl="+subcat_label;
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null);			
}
Does the code above look ok or am I missing something?

Re: Can anybody help me get this working?

Posted: Thu Feb 23, 2012 10:55 pm
by spike1968
Many thanks for your help shakur1911,

The little tips you gave for troubleshooting really helped me understand where the issue was. :)

My issue in this case was due to the value for sc_label not being defined, hence the rest would not work.

Thank you for your time.... :)