Category Select does not complete - On Click

Hello

Could someone help me solve the problem on the Sell and Wanted Ads pages.

http://numberthree.netne.net/index.php

On the Sell & Wanted Ads pages, you need to Select a Category. eg: Art - Modern

the Category Select does not complete, no On Click,

you will need to Register to access the Sell & Wanted Ads pages.

or PM me and I will send you a Log In Username & Password

all help and ideas greatly appreciated

i would help your cause to set up a user account that we could access the page with !! Or disable the protection until you resolve the issue.

Hello Mandes

thank you for your offer of help :slight_smile:

I have sent you a PM with the Username & Password

:slight_smile:

OK had a look, but the code isnt viewable from HTML, you’ll need to post the Javascript that populates the 2nd layer

Hello Mandes, thank you for taking a look,

Java script 2nd layer ? I am new to this website/script world, yet learning :slight_smile:

please tell me where I should look for Java script 2nd layer ? in a php file ?

if you want copies of the php files emailed to you, or posted here on the forum please just tell me.

:slight_smile:

Javascript files are client-side, Mandes, you should be able to see their contents (because the browser has to be able to). I assume you meant to say we need to see the AJAX-receiver PHP code. (this of course is a blind observation)

Starlion

yep but the code for the second level of dropboxes doesnt appear when I do a source view

heres the screen shot and the code that is given by a source view of the same page

I’m not sure what you’re referring to… i’ve been given a login, but the javascript seems to work fine for me…

http://picpaste.com/pics/cats-el2PQ09W.1330003325.jpg

Hello StarLion

I am referring to the Category Select, in your screen pic the word -none- should be replaced by the Category: Antiques & Art - Architectural - Garden

but that does not happen, the On Click does not load the Category,

your help appreciated :slight_smile:

Ahhhh okay. I see now.

So the function the box calls is an AJAX caller…


function select_category(category_id, box_id, prefix, reverse, click_select, listing_type, list_in)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url = relative_path + 'ajax_files/select_category.php';
var action = url + '?category_id=' + category_id + '&target_box_id=' + box_id +
'&prefix=' + prefix + '&reverse_categories=' + reverse + '&click_select=' + click_select +
'&listing_type=' + listing_type + '&list_in=' + list_in;
// xmlHttp.onreadystatechange = function() { showResult(xmlHttp, box_id); };
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4)
{
var response = xmlHttp.responseText;
//document.getElementById(box_id).innerHTML = response;
if (response.indexOf('change_category') == 0 && click_select != true)
{
eval(response);
}
else
{
document.getElementById(box_id).innerHTML = response;
}
}
};
xmlHttp.open("GET", action, true);
xmlHttp.send(null);
} 

The onchange (not onclick, btw) code handler is:


select_category(this.value, 'main_category_field', 'main_', 0, false, 'auction', 'auction')

so i tracked this.value…
clicking on the “Select” link returned null for this.value.
clicking on Antiques and Art gave it value 215
clicking on Antiquities gave it value 225.

So now your query string to your page reads:
“ajax_files/select_category.php?category_id=225&target_box_id=addl_category_field&prefix=addl_&reverse_categories=0&click_select=false&listing_type=auction&list_in=auction”

This returns:
change_category(225, ‘addl_’, 0); (or does it?)
which should fire eval(change_category(225, ‘addl_’, 0););

Except… it doesnt. And why does it not?
http://numberthree.netne.net/ajax_files/select_category.php?category_id=225&target_box_id=addl_category_field&prefix=addl_&reverse_categories=0&click_select=false&listing_type=auction&list_in=auction

View Source on that page. You see the extra stuff your host is packing onto the response? Guess what. Javascript tries to run that through eval, and it borks.

What is ACTUALLY going into eval, is: "change_category(225, ‘main_’, 0);\r
<!-- www.000webhost.com Analytics Code –>\r
<script type=\“text/javascript\” src=\“http://analytics.hosting24.com/count.php\\”></script>\r
<noscript><a href=\“http://www.hosting24.com/\\”><img src=\“http://analytics.hosting24.com/count.php\\” alt=\“web hosting\” /></a></noscript>\r
<!-- End Of Analytics Code –>\r
"

Slice off the extra stuff, and it works fine.
PS: Did all this in Firebug. Very handy tool.
PPS: Could have just had the PHP code return the parameters part and straight-called change_category passing it the parameters. Safer than eval.

Wow StarLion ! that was fast!

ok I just read your post 3-4 times, and understood about 60% (new to this)

so what do I do to make it work? what php? remove/slice off what? where?

details for for a learner much appreciated :slight_smile:

PS: and it this caused by my Server? or the script ?

Without seeing the code for ajax_files/select_category.php, i cant say whether it was the server or the script. I’m -guessing- it was the server, though.

How to fix:
Where you have:


var response = xmlHttp.responseText;

inside the select_category function (inside the jquery/global.js file), try…


var response = xmlHttp.responseText;
response = response.substring(0,response.indexOf(";")) + ";";

instead.

This -should- trim down the string to the needed component.

EDIT: Decided i didnt like playing around with index addition.

Hello StarLion.

ok went to jquery folder, opened global.js file, added code, saved, went to the Sell page on the website, no change/improvement.

function showResult(xmlHttp, id)
{
if (xmlHttp.readyState == 4)
{
var response = xmlHttp.responseText;
response = response.substring(0,response.indexOf(“;”)) + “;”;
id.innerHTML = unescape(response);
}
}

Wrong function :wink:

function select_category(category_id, box_id, prefix, reverse, click_select, listing_type, list_in)
{
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
	alert ("Browser does not support HTTP Request");
	return;
}

var url    = relative_path + 'ajax_files/select_category.php';
var action    = url + '?category_id=' + category_id + '&target_box_id=' + box_id +
'&prefix=' + prefix + '&reverse_categories=' + reverse + '&click_select=' + click_select +
'&listing_type=' + listing_type + '&list_in=' + list_in;

//		xmlHttp.onreadystatechange = function() { showResult(xmlHttp, box_id); };
xmlHttp.onreadystatechange = function() {
	if (xmlHttp.readyState == 4)
	{
		var response = xmlHttp.responseText;
                    [COLOR="#FF0000"]response = response.substring(0,response.indexOf(";")) + ";";[/COLOR]
		//document.getElementById(box_id).innerHTML = response;
		if (response.indexOf('change_category') == 0 && click_select != true)
		{
			eval(response);
		}
		else

ok done correctly I hope this time…lol

yet still no change in Category loading behavior.

Ok. It did change things, but broke the regular behavior instead. Woops.

Move that response = response.substring(0,response.indexOf(“;”)) + “;”; line INSIDE the if (IE: right before the eval line). Save, upload, hold down shift, and push F5.

Hi StarLion

could you please show how the text will look,

var response = xmlHttp.responseText;
response = response.substring(0,response.indexOf(“;”)) + “;”;
//document.getElementById(box_id).innerHTML = response;
if (response.indexOf(‘change_category’) == 0 && click_select != true)
{
eval(response);
}
else

I have my Servers File Manager open and am changing the files within my public.html/jquery/global.js , then saving, then reloading my Sell page to test.

ok? :slight_smile:

var response = xmlHttp.responseText;
response = response.substring(0,response.indexOf(";")) + ";";
//document.getElementById(box_id).innerHTML = response;
if (response.indexOf('change_category') == 0 && click_select != true)
{
eval(response);
}

=>


var response = xmlHttp.responseText;
//document.getElementById(box_id).innerHTML = response;
if (response.indexOf('change_category') == 0 && click_select != true)
{
response = response.substring(0,response.indexOf(";")) + ";";
eval(response);
}

Hi StarLion

Success :slight_smile:

the Category Select is working perfectly! many many thank you’s :slight_smile:

so I created 2 Wanted Ads, uploaded a photo to both, yet when I go to Wanted Ads Page it says/shows - No Image Available

could you please have a look into why - No Image is showing,

your help greatly appreciated

RayWilk :slight_smile:

Where is said image supposed to appear?