Open Source & Stuff  
  |     Main Site     |      Forum     |     Contact     |
Ajax Linked Select boxes :  forum.Salix.gr forum.Salix.gr
Comments, questions, usage, bugs. 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
messageWorks in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 15, 2007 10:22AM

Hi Panos,

This is a very useful script - I have been looking for something like this for ages.

I have it working great in the example.php with my own database tables.

I am now trying to add the script into an existing form however I find that it fails. I have tried the following without success:

1. <?php include("example.php");?> both with and without <script src="prototype.js" type="text/javascript"></script> in the page. The files are in teh same directory as the file with the include.

2. Adding the following code in the file:

<?php

include("top_script.php");
include("sc_classes.php");

$sc_ajax_select_boxes = new sc_ajax_select_boxes();
$sc_ajax_select_boxes->add_select_box('town_lookup','town_id','state','town_id','','sel1','sel_id_1','');
$sc_ajax_select_boxes->add_select_box('town_lookup_sub','sub_type','municipality','sub_type','st21','sel2','sel_id_2','');
$sc_ajax_select_boxes->add_select_box('town_lookup_sub_sub','sub_type','town','sub_type','st22','sel3','sel_id_3','');
$sc_ajax_select_boxes->add_select_box('town_lookup_sub_sub','sub_type','town','sub_type','st22','sel4','sel_id_4','');
$sc_ajax_select_boxes->link_select_boxes('sel1','sel2', 'town_id','t2');
$sc_ajax_select_boxes->link_select_boxes('sel2','sel3', 'town_id','st22');
$sc_ajax_select_boxes->link_select_boxes('sel3','sel4', 'town_id','st22');
$sc_ajax_select_boxes->place_jscripts();
$sc_ajax_select_boxes->show_select_box('sel1');
$sc_ajax_select_boxes->show_select_box('sel2');
$sc_ajax_select_boxes->show_select_box('sel3');
$sc_ajax_select_boxes->show_select_box('sel4'); ?>

This is a direct copy and paste of the script in the example.php file which works just fine. I have also added the reference to the prototype.js file as well but it also has no effect.

Any ideas what might be happening. The form action is

<form action="index.php" method="get">

Thanks
Nick

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 16, 2007 02:20AM

Hi Nick,

looked at your page and i see that you use jQuery also in that page.
When you change selection in the first combo you will notice that there is
a javascript error $F is not defined. That 99% is caused by having jQuery
and prototype in the same page.

According to [docs.jquery.com]
you should include prototype.js before jquery and call that jQuery.noConflict(); function.

Maybe give it a try first without that rotator script, it should work.

Regards
Panos

messageRe: Works in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 16, 2007 04:11AM

Hi Panos,

Nope. Took out the rotator and it still doesn't work.

I did some more testing and interestingly enough the first drop down (before your ajax) works when linked select is not present but fails to work when the ajax is inserted.

The only other javascript preent in the page is the following:

<script language="javascript">


function sendFormToMambo(form, mamboURL) {

if ( form.method.toLowerCase() == 'get' ) {
var hex = formAsHex(form);

// check whether there is already an openrealty query parameter...
splitStr = mamboURL.split("openrealty=");
if ( splitStr.length>1 ) {
hex = splitStr[1] + ascii2Hex('&') + hex;
if ( splitStr[0].charAt(splitStr[0].length-1)!='&' ) splitStr[0] += '&';
mamboURL = splitStr[0]+'openrealty='+hex;
}
else if (mamboURL.indexOf("index.php?")>=0) {
mamboURL = mamboURL+'&openrealty='+hex;
}
else { // SEF style
mamboURL = mamboURL+'openrealty,'+hex+'/';
}

window.location=mamboURL;
return false;
}
else {
form.submit();
}
return false;
}

function formAsHex(form) {

var query='';
for ( var i=0; i<form.elements.length; i++ ) {

if ( form.elements[i].type!=undefined && form.elements[i].type!="button") {
var type = form.elements[i].type.toLowerCase();

// Ensure the value field is populated as OR doesn't always do that...
if ( type=="select-one" ) {
var dropdown = form.elements[i];
if ( dropdown.selectedIndex>0 && dropdown.value.length==0 ) {
dropdown.options[dropdown.selectedIndex].value = dropdown.options[dropdown.selectedIndex].text;
}
}

if ( form.elements[i].name!='' && form.elements[i].value!='' ) {
if ( type=="checkbox" || type=="radio") {
if ( form.elements[i].checked ) {
if ( query.length>0 ) query+='&';
query += form.elements[i].name + '=' + escape(form.elements[i].value);
}
}
else {
if ( query.length>0 ) query+='&';
query += form.elements[i].name + '=' + escape(form.elements[i].value);
}
}
}
}
return ascii2Hex(query);
}

function ascii2Hex( ascii ) {
var hex='';
for ( var i=0; i<ascii.length; i++) {
hex+=ascii.charCodeAt(i).toString(16).toUpperCase();
}
return hex;
}

function debug(text) {
var debug = false;
if ( debug ) {
alert(text);
}
}
</script>

And I can't see a conflict......

N

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 16, 2007 05:20AM

Strange...
is prototype.js located in the same location with your index page?

messageRe: Works in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 16, 2007 07:40AM

OK I have put the proptype.js in every conceivable directory the script might need and the behavior has now changed.

Before all it showed was a "please select" and now it shows an empty list. As I said it continues to work fine in the example.

Obviously the script is inside a <form ..> but not in the example - does this make any difference?

N

messageRe: Works in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 16, 2007 07:42AM

In case any one is interested the URI are:

The example file that works fine: [portugal.sunseakerpropertiesltd.com]

and the inserted script where it doesn't work: [portugal.sunseakerpropertiesltd.com]


Obviously unfinished work! ;-)

N

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 16, 2007 07:50AM

ok, now it finds prototype.js
is sc_select_ajax_handler.php in same place with index.php ?

messageRe: Works in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 16, 2007 09:42AM

OK I have it all working - the drop downs. In fact I have to have all the files in several different directories as the scripts are called form different places. Efharisto for the pointers!

However the form does work. It sends itself off to the appropriate page but does not action the search correctly. If I remove the script it does work. Two things occur to me:

1. Could it be because the form is GET:
<form action="index.php" method="get">

2. Could it be because I am using an image as the send button:
<INPUT TYPE="IMAGE" SRC="/images/search_but.jpg" ALT="Submit button">

N

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 16, 2007 09:59AM

I am guessing now....

in the js function function formAsHex(form)

is that one

if ( type=="select-one" ) {

correct?

messageRe: Works in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 16, 2007 10:07AM

Well if I remove the ajax code the form works perfectly. I have changed it and it made no difference.


In fact the line that I get an error on (from Firebug) is:

var myAjax = new Ajax.Request( url, );\n


Any ideas

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 16, 2007 10:14AM

I also saw that in the results page /index.php?option=com_cmsrealty&Itemid=1&openrealty=.....
which is very-very odd cause the rest of that line is a hard coded string

var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: onCompleteCallBack });

in sc_classes.php (around line 450).

Do you mind mailing me that file (joompla module file) to have a look at it?

Panos

messageRe: Works in example but not in other script
Posted by: logz05 (IP Logged)
Date: May 16, 2007 10:26AM

Panos,

I have sent you an email with an ftp to the site.

N

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 17, 2007 03:05AM

Good morning Nick,

form problem is fixed js reads all parameters atleast from what i get the query string before
encoding looks like:

pclass[]=1&sel1=1&sel2=12&sel3=12&sel4=12&beds=2
&price-min=450000&price-max=1800000&action=serachresults

the problem in the search results form was joomla template engine.
Looks that it encounters as variables all strings in the form {something}
if { and } are in the same line, so it replaced that new Ajax parameters
enclosed in {} with space since {} were in the same line.

Now what i am trying to understand is how search works.
Should all parameters be named pclass[] ?
You know how search class builds sql query from form input?

Panos

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 17, 2007 03:08AM

forgot!!

i changed sc_classes.php located in /openrealty/template/cms_integration/
i splited line 450 in to several lines so Joomla want think that it is a template variable.

messageRe: Works in example but not in other script
Posted by: panos (IP Logged)
Date: May 17, 2007 03:26AM

Finaly thank you for your trust giving me ftp access to your site.

Truly appreciated

Panos



Sorry, only registered users may post in this forum.

All Rights Reserved 2006 Salix.gr  |  Design by Ades Design |  Hosting by e-emporio |  forum.Salix.gr powered by Phorum