The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Wed Feb 22, 2012 9:03 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
Hi,

I have the following code in a module

Code:
$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:
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:
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

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


Last edited by spike1968 on Thu Feb 23, 2012 10:56 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 9:55 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Tue May 06, 2008 12:28 pm
Posts: 96
Hello,

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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 11:21 am 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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?
Quote:
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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 11:26 am 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 11:33 am 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 12:30 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Tue May 06, 2008 12:28 pm
Posts: 96
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:
alert(cid);
to see what you send to getsubcat. In chrome you can use the Javascript console provided by default in Developers tools


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 12:45 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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:
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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 12:49 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Tue May 06, 2008 12:28 pm
Posts: 96
something like this

Code:
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?


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 1:23 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 1:27 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 1:40 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Tue May 06, 2008 12:28 pm
Posts: 96
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..


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 1:46 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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:
 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


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 10:55 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Fri Aug 25, 2006 2:39 pm
Posts: 426
Location: United Kingdom - Aldershot
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 



Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group