This topic is locked

getting a lookup box to trigger an event

9/3/2006 10:16:25 AM
PHPRunner General questions
T
thesofa author

Is there a way I can get the selection of a value in a combo box to trigger an event?

I would like to show a list of existing records for a given pupil when his/her name is picked from a lookup box, rather like the use of the code example shown for orders from a custome in the code examples in the help file

J
Jane 9/4/2006

Hi,
unfortunately there is no easy way to do it.

You need to edit generated files manually.

We don't have a ready to go solution for this.

T
thesofa author 9/6/2006

Hi,

unfortunately there is no easy way to do it.

You need to edit generated files manually.

We don't have a ready to go solution for this.



can you point me in the right direction, I am a bodger and I may be able to make it work!!!!!

J
Jane 9/7/2006

Hi,
to do what you want you should be familiar with JavaScript.

Here some JavaScript tutorials:

http://www.webcheatsheet.com/javascript/

http://www.w3schools.com/js/default.asp
You need to add some javascript code to the ..._add.php or ..._edit.php file and modify BuildSelectControl function in the include/..._functions.php file.

M
mmponline 9/7/2006

This seems to be similar to my need to be able to select a category from a given field and only have corresponding records displayed. Sort of a quick search.
Maybe this should be considered to be implimented in the 3.1 update.

T
thesofa author 9/7/2006

This seems to be similar to my need to be able to select a category from a given field and only have corresponding records displayed. Sort of a quick search.

Maybe this should be considered to be implimented in the 3.1 update.



no no, do not delay it any more

D
Dale 9/7/2006

I solved this issue using the onchange property of the picklist.
I have a look up table that has the inventory in it, when a item is selected or changed in the picklist, it fires the onchange event and then I run a ajax script to fetch all the pricing and other needed information of the selected inventory item back into the invoice record.
What I did was, identify the generated value# of the picklist, then add a script at the end of the _add.php _edit.php in question.
I added this snippet to the add.php and the edit.php in my template folder. The snippet as you can see is just above the existing superbottom.php file check.
<?php

if(file_exists("include/##SHORTTABLENAME##_divtabs.php"))

include("include/##SHORTTABLENAME##_divtabs.php");

else

if(file_exists("include/default_divtabs.php"))

include("include/default_divtabs.php");

?>

<?php

if(file_exists("include/superbottom.php"))

include("include/superbottom.php");

?>
Then I would manually create a file ie purchases_divtabs.php file and save it in the include folder.
Inside the purchases_divtabs.php file I would put any script that I wanted to run AFTER the page is loaded.

(An event of After Load would be nice new feature in PHPRunner. Then the extra file could be dropped, hint hint.)
Anyway, you could put a snippet
<script type="text/javascript" language="javascript">

document.getElementById('value15[]').onchange = calcpurchase;

<script>
The calcpurchase function can be written in the same javascript snippet.
<script type="text/javascript" language="javascript">

document.getElementById('value15[]').onchange = calcpurchase;
function calcpurchase()

{

if ((document.getElementById('value64').value) == 0)

document.getElementById('tax3row').style.display = 'none';

// this will hide the tax 3 row if it does not apply.

}

<script>
The field name given by PHPRunner on generating a project will never change if you keep to the rule, Any additions to tables is done at the end of the table. Whenever you delete or rename a field or create a field within an existing database table will or possibly change the value# and then you must recheck your scripts.
Lastly I reference a getElementId and NOT use the
document.forms.editform.value15[].onchange = calcpurchase;
Getting attributes by id is much more flexible than referring to form names. Your scripts are cross compatible between, list.php edit.php add.php etc when using the getElementById. Of course to do this I had to hack the functions.php in the template folder to create the id attribute on each input field along with current Name attribute. If you stick with the form name, things should still work out. (I suggested many months ago that PHPRunner should generate Id's along with the Name attribute when generating the pages. along with the point that the generated code should be strict xhtml compliant as well.)
Anyway, this method works great for me. I can have a lot of flexibility over the look and feel of the generated pages, AND I dont loose anything when I regenerate.
A lot of this can be done using the events, but I went this direction so I could do things After the page was loaded and I am no expert at any of this. Whack away till it works is my method. As I learn I find you can find tune things easier.
Hope this helps.

T
thesofa author 9/7/2006

Dale, many thanks for all that, it is way above my head, I have no idea what most of it means, BUT I shall keep looking....

Thanks for your time.

George