[SOLVED] Can anybody help me get this working?

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

[SOLVED] Can anybody help me get this working?

Post by spike1968 » Wed Feb 22, 2012 9:03 pm

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
Last edited by spike1968 on Thu Feb 23, 2012 10:56 pm, edited 1 time in total.
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
shakur1911
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 104
Joined: Tue May 06, 2008 12:28 pm

Re: Can anybody help me get this working?

Post by shakur1911 » Thu Feb 23, 2012 9:55 am

Hello,

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

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 11:21 am

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?
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 11:26 am

Got firebug lite for chrome now...
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 11:33 am

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.
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
shakur1911
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 104
Joined: Tue May 06, 2008 12:28 pm

Re: Can anybody help me get this working?

Post by shakur1911 » Thu Feb 23, 2012 12:30 pm

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

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 12:45 pm

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!
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
shakur1911
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 104
Joined: Tue May 06, 2008 12:28 pm

Re: Can anybody help me get this working?

Post by shakur1911 » Thu Feb 23, 2012 12:49 pm

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?

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 1:23 pm

Live path is already set within the site.

Thanks for help with the code......
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 1:27 pm

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...
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
shakur1911
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 104
Joined: Tue May 06, 2008 12:28 pm

Re: Can anybody help me get this working?

Post by shakur1911 » Thu Feb 23, 2012 1:40 pm

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..

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 1:46 pm

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?
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best

User avatar
spike1968
Joomla! Explorer
Joomla! Explorer
Posts: 427
Joined: Fri Aug 25, 2006 2:39 pm
Location: United Kingdom - Aldershot
Contact:

Re: Can anybody help me get this working?

Post by spike1968 » Thu Feb 23, 2012 10:55 pm

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.... :)
I may be wrong and I often am.
http://www.yourparish.co.uk - Free listing directory
IMHO Chrome is the best


Locked

Return to “Joomla! 2.5 Coding”