PDA

View Full Version : Combobox send selection to querystring


opensource2000
04-07-2008, 11:55 AM
Hi,
I am using PHP as the backend. I load the options for the combobox from a mysql database. After one of the option from the combobox is selected, I want to save the selected option in the database.

Before opening the application, the database field (where the selected option is saved) has a default value (ex: "Company1" is the selected option). However after I open the application, the database field is deleted ("Company1" becomes "") before I even choose the option from the combobox. So I guess the handler is executed before I even select anything from the combobox.

How can I change the code inside the <combobox> tags so that the option is sent to the querystring of input3 exactly after it's selected from the combobox ?


...

dataset name="d1" request="true" type="http" src="http://.../getcontactinfo.php" />
<dataset name="d3" request="false" type="http" src="http://.../updateinfo.php"/>

...

<combobox width="130" editable="false">
<textlistitem datapath="d1:/contact_info/company" text="$path{'@Company_Name'}" value="$path{'@Company_Name'}"/>
<handler name="onselect">
var company_selected = this.getText();
var d3=canvas.datasets.d3;
var parameter=new LzParam();
parameter.addValue("company_selected", company_selected, true);
d3.setAttribute('querystring', p);
d3.doRequest();
</handler>
</combobox>

updateinfo.php
<?php
{
$company_selected =$_GET["company_selected"];
include("connect_db.php"); // connect to database
mysql_query(" UPDATE user_settings SET Company_Selection ='$company_selected' WHERE userid='user1'");
}
?>

Thanks a lot for any comments

rcyeager
04-07-2008, 04:37 PM
What I usually do in these situations is to have an init flag attribute that ignores the first event which is being triggered when the control initializes.

Robert
http://www.qrowd.com
http://www.cooqy.com

opensource2000
04-10-2008, 06:35 AM
thanks a lot rcyeager!
can you show me how to do it, an example or where in the Developer Guide I can learn about setting the "init flag attribute that ignores the first event which is being triggered when the control initializes"
(I am new to OL)
thanks

rcyeager
04-10-2008, 06:57 AM
It's dead simple. Add an attribute to the combobox:

<attribute name="isInit" type="boolean" value="true"/>

Then, gate the onselect handler like so:

if (this.isInit)
{
this.isInit = false;
}
else
{
main logic...
}

That will skip the first select event being caused when the control initializes. Subsequent selects done by the user will perform the main logic flow.

Robert
http://www.qrowd.com
http://www.cooqy.com

opensource2000
04-10-2008, 11:40 AM
thank a lot rcyeager!!!
it works now (not exactly sure why lol)

some of the changes I made were
i3.setQueryString(parameter);
instead of
i3.setAttribute('querystring', parameter);

and changed the PHP file to:
<?php
if ( isset( $_GET["selection"] ) )
{
$company_selected=$_GET["selection"];
include("connect_steelappdb.php"); // connect to database
$result=mysql_query(" UPDATE user_settings SET Company_Selection ='$company_selected' WHERE userid='user1'", $con);
echo "<result>" . ( $result ? "Success" : "Failure") . "</result>";
mysql_free_result($result);
mysql_close($con) or die("Couldn't close connection to database!");
}
?>

I'll report the topic to be closed because the problem was solved