possible to "catch" a javascript-variable to put it into php

A place for users and developers of the Xataface to discuss and receive support.

Postby Markus » Tue May 15, 2007 7:32 am

Hello df-users, hello steve,

i wonder wether it could be possible to "catch" a javascript variable and use it in a php-function. The Thing is, i tested your little Happy Birthday - Alert JavaScript i found somewhere here. I changed it a little bit to get an id out. When doing so and combining with a select in fields.ini and a valuelist i got an alert with the id of the corresponding record onchange of my select field.

In order to have dynamic valuelists could i somehow get this id into a php-function? I know, there could not be dynamic valuelists, i read it somewhere. But if i could kind of translate this JavaScript variable into php, maybe it works?

I want to accomplish the following: Given i have two tables linked with a foreign_key ID one the source one the destination table. Each record in the source table has some related records in the destination table. In my new record form where i have two selects i want to select one value in the first select and then the second select should display only the related values.

Normally i can not get this until something is saved in my db, i know. But would it be possible using either the above mentioned javascipt-variable or doing some other javascript action with an widget:atts:onchange of the first select? I tried a little but could no achieve something.

Right now i am still using 0.6.13r4 instead of 0.7 version.

Thank you for your help, hopefully you understand, what i mean ;)

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue May 15, 2007 11:58 am

Ok.. I think I see what you mean.

Let me recap so that I can make sure that I understand.

On your form you have:

[Select_list_A]
widget:type=select
vocabulary=valuelist_1

[Select_list_B]
widget:type=select
vocabulary=valuelist_2

And you want the values in valuelist_2 to depend on the value chosen for Select_list_A?

If this is the case, then there is a bit of stickiness you have to deal with.Ê If feasible and possible, I would make valuelist_2 contain all of the possible values that Select_list_B can take on.Ê Then just use javascript to filter them.

This can still be a bit tricky.Ê I have done a few maneuvres like this one before... I'll see if I can track down some examples.

Dataface 0.7 has some features to make it easy to do this with checkboxes, but I haven't gotten around to adding the "simple" way of doing it to select lists.Ê One of the coming versions will allow you to do this 100% in the ini file, but it may be a few months before this gets added and released.

-Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Wed May 16, 2007 3:37 am

Thank you for your hints. My application is structured like you write. All possible values that select_list_B can take on are in there.

The values from select_list_A are from list_event_group table which is related to the table list_event_type.

TABLE list_event_group has the structure:

l_gid (int, auto increment)
type_group (varchar)

Table list_event_type has

l_tid (int, auto increment)
L_GID (int, relation to Table A)
type (varchar)

Every type_group in Table A has some related types in Table B

I do something like

[list_event_group]
__sql__ = "select l_gid, type_group from list_event_group"

[list_event_type]
__sql__ = "select l_tid, L_GID, type from list_event_type"

in my valuelists.ini of a THIRD TABLE called events and has L_GID, L_TID as foreign keys.

But this gets all the data in Select_list_B instead of only the related ones.

And I can not use a $l_gid in the valuelists.ini like
__sql__ = "select l_tid, L_GID, type from list_event_type WHERE L_GID=$l_gid"

This because there is no l_gid submitted when jumping from SELECT A to SELECT B, right?
This l_gid variable I have to get somehow ;) with javascript.

Am i right until here?

The problem ist the javascript filter because i am not really deep into javascript. So if you could find an example I can learn from would be great.

Maybe there are other solutions with version 0.71 I have installed now. You mentioned checkboxes. This would be an opportunity instead of select A maybe because there are only 5 values in there.


Thank you for your patience once more

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Thu May 24, 2007 11:59 am

Ok.. I think I see what you mean.

Let me recap so that I can make sure that I understand.

On your form you have:

[Select_list_A]
widget:type=select
vocabulary=valuelist_1

[Select_list_B]
widget:type=select
vocabulary=valuelist_2

And you want the values in valuelist_2 to depend on the value chosen for Select_list_A?

If this is the case, then there is a bit of stickiness you have to deal with. If feasible and possible, I would make valuelist_2 contain all of the possible values that Select_list_B can take on. Then just use javascript to filter them.

This can still be a bit tricky. I have done a few maneuvres like this one before... I'll see if I can track down some examples.

Dataface 0.7 has some features to make it easy to do this with checkboxes, but I haven't gotten around to adding the "simple" way of doing it to select lists. One of the coming versions will allow you to do this 100% in the ini file, but it may be a few months before this gets added and released.

-Steve



Hello Steve,

I think I am a little further now but how i said before I am not a JavaScript - Enthusiast ;) Please refer to my last posting in this thread also.

OK. I can pass the JavaScript-Variable to the URL with a little trick when opening a new browser-window and after that read it out with php which I don't want because it is ugly.

I still have my two selects, values in select two depending on choosen values in select one.

I have a Javascript-Function in javascript.js which reads out the ID of the value in select one and puts it into a link.

The Link is http://www.mydomain.de/path/to/my/app/index.php?-action=new&-table=event&type_group=2 where type_group is the JavaScript Variable.

When I select a value from select one where i have the widget:atts:onchange = "myJavascriptFunction(this.value);" in my fields.ini the Link will open in a new blank browser-window.

If I click on the Link now, which brings me back to my form, the selected value in select one is not selected anymore BUT select two shows only the values dependent on my selection in select one.
This because I have a function in the ApplicationDelegate of this table which reads out the type_group var from the URL and processes it further in a php-query.

Better than before but not perfect so far...

How can I -maybe with using actions.ini and javascript.js - files ??? for this single table- avoid that a new blank window is opened between focussing select one and select two.

I can feel there must be a solution but did not manage to find it til now.
Maybe there are other JavaScript or AJAX-specialized users here to help me out.

Thank you for all hints.

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu May 24, 2007 12:17 pm

Hi Markus,

How do you determine which options should be available in the 2nd select?Ê Do you have a naming convention for the values, or is it based on related values?Ê Here's what I generally do:
The valuelist for the 2nd select list is *big* - it holds all possible values that that 2nd field can take regardless of what is selected in the first field.
I write an onchange event handler and attach it to the first select list.Ê This handler goes through the options in the second select list and hides the values that shouldn't be shown based on what is selected in the first list.ÊÊ If you let me know how you are determining which options in the 2nd list should be selected, I can go into some more details about how to approach this.
-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Fri May 25, 2007 3:00 am

Hi Markus,

How do you determine which options should be available in the 2nd select? Do you have a naming convention for the values, or is it based on related values? Here's what I generally do:
The valuelist for the 2nd select list is *big* - it holds all possible values that that 2nd field can take regardless of what is selected in the first field.
I write an onchange event handler and attach it to the first select list. This handler goes through the options in the second select list and hides the values that shouldn't be shown based on what is selected in the first list. If you let me know how you are determining which options in the 2nd list should be selected, I can go into some more details about how to approach this.
-Steve



Hi Steve,

Oh. I thought I had already explained (in my last but second posting). I'll try to make it a little bit clearer. I have the so called type_group in the first select. I have the type in second select. Both valuelists come from SQL-queries of two related tables as shown above in my other posting. Each type_group has related types by a foreign key in the second valuelist. If the user selects a value (type_group) in the first (an onchange event handler is already in the fields.ini) only the relates values (type) should show up in the second. The first one should remain the selected value.

How to hide the non-related values in the second valuelist then?

Thank you for your help

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri May 25, 2007 12:46 pm

Here's an AJAX solution:

create a custom action named get_types as follows:

Add a file named get_types.php into your actions directory with the following contents:

class actions_get_types {
ÊÊÊ function handle(&$params){
ÊÊÊÊÊÊÊ if ( isset($_REQUEST['type_group']) ){
ÊÊÊÊÊÊÊÊÊÊÊ $sql = "select type_id, type_name from types where type_group='".addslashes($_REQUEST['type_group'])."'";
ÊÊÊÊÊÊÊ } else {
ÊÊÊÊÊÊÊÊÊÊÊ $sql = "select type_id, type_name from types";
ÊÊÊÊÊÊÊ }
ÊÊÊÊÊÊÊ $res = mysql_query($sql, df_db());
ÊÊÊÊÊÊÊ if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
ÊÊÊÊÊÊÊ header('Content-type: text/javascript');
ÊÊÊÊÊÊÊ echo '[';
ÊÊÊÊÊÊÊ $values = array();
ÊÊÊÊÊÊÊ while ( $row = mysql_fetch_assoc($res) ){
ÊÊÊÊÊÊÊÊÊÊÊ $values[] =Ê "{id:'".$row['type_id']."', name: '".addslashes($row['type_name'])."'}";
ÊÊÊÊÊÊÊ }
ÊÊÊÊÊÊÊ echo implode(',',$values);
ÊÊÊÊÊÊÊ echo ']';
ÊÊÊÊÊÊÊ exit;
ÊÊÊ }
}

?> Ê

What this does is returns the values for a given type group in JSON format (which javascript can read very easily).

Then in javascript you could do something like:

var types_http = getHTTPObject();

/**
Ê* updateTypesList
Ê* This function is to be assigned in the onchange handler for the group types select list.
Ê*/

function updateTypesList(type_groups_select){
ÊÊÊ // type_groups_select is a reference to the type_groups select list
ÊÊÊ var selectedGroup = type_groups_select.options[group_list.selectedIndex].value;
Ê Ê var url = DATAFACE_SITE_HREF +'?-action=get_types&type_group='.escape(selectedGroup);
Ê Ê types_http.open("GET", url);
Ê Ê types_http.onreadystatechange =Ê handleUpdateTypesList;
ÊÊÊÊÊÊÊ // Assign the handleUpdateTypesList function as a handler to be called when the HTTP object receives a response from the server
ÊÊÊ types_http.group_list = type_groups_select;
ÊÊÊÊÊÊÊ // Save a reference to the group types select list in the http object so that it can be accessed from the handleUpdateTypesList function
ÊÊÊ types_http.send(null);
}

/**
Ê* handleUpdateTypesList
Ê* This function is called when a response is received from the HTTP object after we request the types for a particular group.
Ê*/
function handleUpdateTypesList(){
ÊÊÊ if ( types_http.readystate == 4 ){
ÊÊÊÊÊÊÊ // We have successfully obtained the response from the server
ÊÊÊÊÊÊÊ var options = eval('(' + types_http.responseText +')');
ÊÊÊÊÊÊÊ // we now have the options that we will use to fill the 2nd select list as an array
ÊÊÊÊÊÊÊ // now let's get out select list and refill it
ÊÊÊÊÊÊÊ var types_list = types_http.group_list.form.elements['type_id'];
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ // We obtain a reference to the type_id select list (let's assume that the field is named type_id.. if not, then change this).
ÊÊÊÊÊÊÊÊÊÊÊ // Clear the existing options in the types list.
ÊÊÊÊÊÊÊ for ( var i=0; iÊÊÊÊÊÊÊÊÊÊÊ types_list.options[i] = new Option(options[i]['name'], options[i]['id']);
ÊÊÊÊÊÊÊ }
ÊÊÊ }


}




Finally you can add the following to your fields.ini file for the type_groups field:
[type_groups]
widget:atts:onchange="updateTypesList(this):"



Now this code has not been tested, and I undoubtedly have the names of fields wrong,Ê - so you will need to work with it a bit to make it work.. but this is the general strategy to take.

References:

http://www.javascriptkit.com/javatutors/selectcontent.shtml
http://www.developer.com/lang/jscript/article.php/3596836

Best regards

Steve



--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Fri May 25, 2007 1:48 pm

Hi Steve,

thanks a lot for your work and the references I had a short look on. I cannot test it right now because I will go on holiday for the weekend early tomorrow but I am eager to try it when I am back. I will give you a response then.

By the way let me thank you for developing this great framework. I was thinking of testing seagull or tried dadabik before but I think dataface is the one I should use now and in future. I am nearly convinced of it. It is a little bit a pity that the community here is still very small but I hope it will grow very soon. On the long run you should not be the only one answering most of the questions by yourself. On the other hand it is really familiar here and I also like it this way ;)

Have a nice weekend

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Tue May 29, 2007 6:43 am

Here's an AJAX solution:

create a custom action named get_types as follows:

Add a file named get_types.php into your actions directory with the following contents:

class actions_get_types {
function handle(&$params){
if ( isset($_REQUEST['type_group']) ){
$sql = "select type_id, type_name from types where type_group='".addslashes($_REQUEST['type_group'])."'";
} else {
$sql = "select type_id, type_name from types";
}
$res = mysql_query($sql, df_db());
if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
header('Content-type: text/javascript');
echo '[';
$values = array();
while ( $row = mysql_fetch_assoc($res) ){
$values[] = "{id:'".$row['type_id']."', name: '".addslashes($row['type_name'])."'}";
}
echo implode(',',$values);
echo ']';
exit;
}
}

?>

What this does is returns the values for a given type group in JSON format (which javascript can read very easily).

Then in javascript you could do something like:

var types_http = getHTTPObject();

/**
* updateTypesList
* This function is to be assigned in the onchange handler for the group types select list.
*/

function updateTypesList(type_groups_select){
// type_groups_select is a reference to the type_groups select list
var selectedGroup = type_groups_select.options[group_list.selectedIndex].value;
var url = DATAFACE_SITE_HREF +'?-action=get_types&type_group='.escape(selectedGroup);
types_http.open("GET", url);
types_http.onreadystatechange = handleUpdateTypesList;
// Assign the handleUpdateTypesList function as a handler to be called when the HTTP object receives a response from the server
types_http.group_list = type_groups_select;
// Save a reference to the group types select list in the http object so that it can be accessed from the handleUpdateTypesList function
types_http.send(null);
}

/**
* handleUpdateTypesList
* This function is called when a response is received from the HTTP object after we request the types for a particular group.
*/
function handleUpdateTypesList(){
if ( types_http.readystate == 4 ){
// We have successfully obtained the response from the server
var options = eval('(' + types_http.responseText +')');
// we now have the options that we will use to fill the 2nd select list as an array
// now let's get out select list and refill it
var types_list = types_http.group_list.form.elements['type_id'];
// We obtain a reference to the type_id select list (let's assume that the field is named type_id.. if not, then change this).
// Clear the existing options in the types list.
for ( var i=0; i types_list.options[i] = new Option(options[i]['name'], options[i]['id']);
}
}


}




Finally you can add the following to your fields.ini file for the type_groups field:
[type_groups]
widget:atts<img src=:o" title="Surprised" />nchange="updateTypesList(this):"



Now this code has not been tested, and I undoubtedly have the names of fields wrong, - so you will need to work with it a bit to make it work.. but this is the general strategy to take.

References:

http://www.javascriptkit.com/javatutors/selectcontent.shtml
http://www.developer.com/lang/jscript/article.php/3596836

Best regards

Steve





Hi Steve,

now I am testing with your suggestions. To verify that I am doing everything right I will give you a nearly complete overview about the things I have done so far.

In my app I have the tables:

list_event_group

l_gid (int,8) NOT NULL, auto increment PRIMARY KEY
type_group (varchar,30) NULL


list_event_type

l_tid (int,8) NOT NULL, auto increment PRIMARY KEY
L_GID (int,8) NULL
type (varchar,256) NULL


event

eid (int,8) NOT NULL, auto increment PRIMARY KEY
L_GID (int,8) NOT NULL
L_TID (int,8) NOT NULL
more fields...

Currently I am working with the table event

valuelists.ini

[list_event_group]
__sql__ = "select l_gid, type_group from list_event_group"

[list_event_type]
__sql__ = "select l_tid, L_GID, type from list_event_type"


fields.ini

other fields...

[L_GID]
widget:label = "Ereignisgruppen ID"
widget:description = "Die Ereignisgruppen ID des Ereignisses"
widget:type = "select"
vocabulary = "list_event_group"
widget:atts:onchange="updateTypesList(this);"
actions = "get_types"

[L_TID]
widget:label = "Ereignistyp ID"
widget:description = "Die Ereignistyp ID des Ereignisses"
widget:type = "select"
vocabulary = "list_event_type"

other fields...

relationships.ini

other relationship...

[list_event_group]
list_event_group.l_gid = "$L_GID"

[list_event_type]
list_event_type.l_tid = "$L_TID"

Now I took your code like above and did the following in the http://path/to/my/app/actions Directory

I made a get_types.php and changed the field-names corresponding to my field-names:

class actions_get_types {
function handle(&$params){
if ( isset($_REQUEST['L_GID']) ){
$sql = "select l_tid, type from list_event_type where L_GID='".addslashes($_REQUEST['L_GID'])."'";
} else {
$sql = "select L_tid, type from list_event_type";
}
$res = mysql_query($sql, df_db());
if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
header('Content-type: text/javascript');
echo '[';
$values = array();
while ( $row = mysql_fetch_assoc($res) ){
$values[] = "{l_tid:'".$row['l_tid']."', type: '".addslashes($row['type'])."'}";
}
echo implode(',',$values);
echo ']';
exit;
}
}

?>



In the http://path/to/my/app/javascripts.ini I have the following:

var types_http = getHTTPObject();

/**
* updateTypesList
* This function is to be assigned in the onchange handler for the group types select list.
*/

function updateTypesList(list_event_group_select){
// list_event_groups_select is a reference to the list_event_group select list
var selectedGroup = list_event_groups_select.options[list_event_group.selectedIndex].value;
var url = DATAFACE_SITE_HREF +'?-action=get_types&type_group='.escape(selectedGroup);
types_http.open("GET", url);
types_http.onreadystatechange = handleUpdateTypesList;
// Assign the handleUpdateTypesList function as a handler to be called when the HTTP object receives a response from the server
types_http.list_event_group = list_event_groups_select;
// Save a reference to the list_event_groups select list in the http object so that it can be accessed from the handleUpdateTypesList function
types_http.send(null);
}

/**
* handleUpdateTypesList
* This function is called when a response is received from the HTTP object after we request the types for a particular group.
*/
function handleUpdateTypesList(){
if ( types_http.readystate == 4 ){
// We have successfully obtained the response from the server
var options = eval('(' + types_http.responseText +')');
// we now have the options that we will use to fill the 2nd select list as an array
// now let's get out select list and refill it
var list_event_type = types_http.list_event_group.form.elements['l_tid'];
// We obtain a reference to the type_id select list (the field is named l_tid so I changed it).
// Clear the existing options in the types list.
for ( var i=0; i list_event_type.options[i] = new Option(options[i]['type'], options[i]['l_tid']);
}
}


}





When doing all this, whats happening is:

In my application new record form I choose the list_event_group select and select an item.

The list_event_type select then stays empty and in my IE status bar I get a JavaScript-Error whose details say: list_event_group ist undefiniert ("is undefined" in english, I suppose).

Where did I go wrong here?

Thank you again
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue May 29, 2007 8:54 am

It may be objecting to adding the list_event_group member variable to the types_http object.Ê Another way to accomplish this is to create a global variable called list_event group and then replace all references to types_http.list_event_group to just list_event_group.

e.g.:Ê

After
var types_http = getHTTPObject();
add
var list_event_group = null;
And then replace all references to types_http.list_event_group to just list_event_group
-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Tue May 29, 2007 9:06 am

Hi Steve,

some more questions occured, when I tried your code:

FIRST:

function updateTypesList(type_groups_select){
// type_groups_select is a reference to the type_groups select list

Does that mean, that I have to replace "type_groups_select" with the name of my table which is "list_event_group" and name the function updateTypesList(list_event_groups_select) ?
Does the plural or the _select within the brakes mean anything according to naming conventions in DF?

Or do I have to replace "type_groups_select" through the name of my select widget in fields.ini which is L_GID and write updateTypesList(L_GID)?

I have tried a little, but still could not get anything out of my list_event_type select field.

SECOND:

When I look into the error-console of firefox browser it says GetHTTPObject() is not defined.

Maybe this can help you to find something wrong

Best regards

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Tue May 29, 2007 9:08 am

Hi Steve,

>

some more questions occured, when I tried your code:

>

FIRST:

>

function updateTypesList(type_groups_select){

> / type_groups_select is a reference to the type_groups select list

>

Does that mean, that I have to replace "type_groups_select" with the name of my table which is "list_event_group" and name the function updateTypesList(list_event_groups_select) ?

>Does the plural or the _select within the brakes mean anything according to naming conventions in DF?



>Or do I have to replace "type_groups_select" through the name of my select widget in fields.ini which is L_GID and write updateTypesList(L_GID)?



>I have tried a little, but still could not get anything out of my list_event_type select field.



>SECOND:



>When I look into the error-console of firefox browser it says GetHTTPObject() is not defined.



>Maybe this can help you to find something wrong



>Best regards



>Markus



This was before your last answer, sorry ;)

I will try first.
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Tue May 29, 2007 9:35 am

It may be objecting to adding the list_event_group member variable to the types_http object. Another way to accomplish this is to create a global variable called list_event group and then replace all references to types_http.list_event_group to just list_event_group.

e.g.:

After
var types_http = getHTTPObject();
add
var list_event_group = null;
And then replace all references to types_http.list_event_group to just list_event_group
-Steve



My code in javascript.js now:

//FUNKTIONEN ANGEPASST
var types_http = getHTTPObject();
var list_event_group = null;

/**
* updateTypesList
* This function is to be assigned in the onchange handler for the group types select list.
*/

function updateTypesList(list_event_groups_select){
// list_event_group_select is a reference to the list_event_group select list
var selectedGroup = list_event_groups_select.options[list_event_group.selectedIndex].value;
var url = DATAFACE_SITE_HREF +'?-action=get_types&list_event_group='.escape(selectedGroup);
types_http.open("GET", url);
types_http.onreadystatechange = handleUpdateTypesList;
// Assign the handleUpdateTypesList function as a handler to be called when the HTTP object receives a response from the server
list_event_group = list_event_groups_select;
// Save a reference to the group types select list in the http object so that it can be accessed from the handleUpdateTypesList function
types_http.send(null);
}

/**
* handleUpdateTypesList
* This function is called when a response is received from the HTTP object after we request the types for a particular group.
*/
function handleUpdateTypesList(){
if ( types_http.readystate == 4 ){
// We have successfully obtained the response from the server
var options = eval('(' + types_http.responseText +')');
// we now have the options that we will use to fill the 2nd select list as an array
// now let's get out select list and refill it
var list_event_type = types_http.list_event_group.form.elements['l_tid'];
// We obtain a reference to the type_id select list (let's assume that the field is named type_id.. if not, then change this).
// Clear the existing options in the types list.
for ( var i=0; i list_event_type.options[i] = new Option(options[i]['type'], options[i]['l_tid']);
}
}

}


and error-console of firefox goes:

getHTTPObject() is not defined

list_event_group has no properties


Any idea?

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed May 30, 2007 10:02 am

The getHTTPObject() function is defined in the js/ajax.js file in the dataface installation folder.ÊÊ Most likely it hasn't been loaded yet in your document.Ê If you change the following:

var types_http = getHTTPObject();

var list_event_group = null;


to

require(DATAFACE_SITE_URL+'/js/ajax.js');
var types_http = null;
var list_event_group = null;

And then add the following to the updateTypesList() function:

if ( types_http == null ) types_http = getHTTPObject();

That should give the function time to be loaded before it is called.

The second error (list_event_group has no properties) is coming up because you haven't changed the types_http.list_event_group to just list_event_group in the handler function.

-Steve


--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Markus » Wed May 30, 2007 10:52 am

The getHTTPObject() function is defined in the js/ajax.js file in the dataface installation folder. Most likely it hasn't been loaded yet in your document. If you change the following:

var types_http = getHTTPObject();

>
var list_event_group = null;


to

require(DATAFACE_SITE_URL+'/js/ajax.js');
var types_http = null;
var list_event_group = null;

And then add the following to the updateTypesList() function:

if ( types_http == null ) types_http = getHTTPObject();

That should give the function time to be loaded before it is called.

The second error (list_event_group has no properties) is coming up because you haven't changed the types_http.list_event_group to just list_event_group in the handler function.

-Steve

>




Hi Steve,

I changed the code to:

//FUNKTIONEN ANGEPASST
require(DATAFACE_SITE_URL+'/js/ajax.js');
var types_http = null;
var list_event_group = null;

/**
* updateTypesList
* This function is to be assigned in the onchange handler for the group types select list.
*/

function updateTypesList(list_event_groups_select){
if ( types_http == null ) types_http = getHTTPObject();
// list_event_group_select is a reference to the list_event_group select list
var selectedGroup = list_event_groups_select.options[list_event_group.selectedIndex].value;
var url = DATAFACE_SITE_HREF +'?-action=get_types&list_event_group='.escape(selectedGroup);
types_http.open("GET", url);
types_http.onreadystatechange = handleUpdateTypesList;
// Assign the handleUpdateTypesList function as a handler to be called when the HTTP object receives a response from the server
list_event_group = list_event_groups_select;
// Save a reference to the group types select list in the http object so that it can be accessed from the handleUpdateTypesList function
types_http.send(null);
}

/**
* handleUpdateTypesList
* This function is called when a response is received from the HTTP object after we request the types for a particular group.
*/
function handleUpdateTypesList(){
if ( types_http.readystate == 4 ){
// We have successfully obtained the response from the server
var options = eval('(' + types_http.responseText +')');
// we now have the options that we will use to fill the 2nd select list as an array
// now let's get out select list and refill it
var list_event_type = list_event_group.form.elements['l_tid'];
// We obtain a reference to the type_id select list (let's assume that the field is named type_id.. if not, then change this).
// Clear the existing options in the types list.
for ( var i=0; i list_event_type.options[i] = new Option(options[i]['type'], options[i]['l_tid']);
}
}

}

as you said. The first error does not occur any longer. Thank you for your help. But the second one "list_event_group has no properties" is still there.

And I would like to know wether the naming in function updateTypesList, which means(list_event_groups_select) follows special naming conventions in DF? Especially the Plural and the _select. Or am I free to name it somehow. See similar question in my last but second posting.

Thank you

Markus
Markus
 
Posts: 94
Joined: Wed Dec 31, 1969 5:00 pm

Next

Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 41 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved