CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Client-side concatenated field on editable grid?

Print topic Send  topic

Author Message
VBAjedi


Posts: 34
Posted: 01/02/2004, 1:32 PM

Thought I'd see if anyone is using this forum yet. . .

Using CCS, Apache/PHP/MySQL: I'm setting up an editable grid. The value in field "A" of the grid needs to be a concatenation of the user-specified values in fields "B" & "C" (and yes, I do need to store this concatenated value for performance reasons), but I don't want the user to do it manually.

How can I set up my grid so that as the user inputs/edits the values in columns "B" & "C", the concatenated value appears in column "A" in real-time? It seems obvious that it needs to be a client-side process, but I'm not sure what approach to take.

Thanks!
_________________
VBAjedi
jedi at NOSPAM dot obie dot com
View profile  Send private message
RonB

Posts: 228
Posted: 01/03/2004, 3:36 AM

Use an onchange event in box c (b is filled and after c is filled combine the two values and set field a) :

onchange="document.all['{field_a_Name}'].value=document.all['{field_b_Name}'].value + ' ' + document.all['{field_c_Name}'].value"

In an editable grid you have to use the {field_a_Name} naming because that's the only way to make sure the right field names are inserted for every row.
View profile  Send private message
VBAjedi


Posts: 34
Posted: 01/05/2004, 10:37 AM

Ron,

Thanks for the reply. I get the general idea, but I'm new at this and need clarification on two points:

1) Do I open the CCS HTML window, then add your code directly to Box C from there? Or do I go to the CCS properties/events pane and add custom code to the OnChange event of Box C there?

2)
Quote RonB:
In an editable grid you have to use the {field_a_Name} naming because that's the only way to make sure the right field names are inserted for every row.
Do you mean I need to name my field "field_Box_A", or that I need to name my field "Box_A" but refer to it in this code as "field_Box_A"? In other words, is "field_" a naming convention or part of the object model? (hope that makes sense)

Thanks!

_________________
VBAjedi
jedi at NOSPAM dot obie dot com
View profile  Send private message
JCF
Posted: 01/05/2004, 2:32 PM

Hi

If you need to store the "A" then add another field to the table and at the
time of saveing the record just concatenate the two values.

This new value can be displayed on the grid.

Hope I understand what you are asking.

JCF

"VBAjedi" <VBAjedi@forum.codecharge> wrote in message
news:53ff5e50f9a0e4@news.codecharge.com...
> Thought I'd see if anyone is using this forum yet. . .
>
> Using CCS, Apache/PHP/MySQL: I'm setting up an editable grid. The value in
field "A" of the grid needs to be a concatenation of the user-specified
values in fields "B" & "C" (and yes, I do need to store this concatenated
value for performance reasons), but I don't want the user to do it manually.
>
> How can I set up my grid so that as the user inputs/edits the values in
columns "B" & "C", the concatenated value appears in column "A" in
real-time? It seems obvious that it needs to be a client-side process, but
I'm not sure what approach to take.
>
> Thanks!
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

VBAjedi


Posts: 34
Posted: 01/05/2004, 4:08 PM

Actually, I think Ron's suggestion is on the right track - I just need clarification on the two points stated in my last post.

This is a "hand-holding" concession for less-computer-savvy users. They need to fill out two fields, and I want them to see the third field entry (a concatenation of the first two) being automatically created as they do so. They don't have the faith to trust that the crucial third value will be created after they click "Submit" (and I, on the other hand, don't trust them to be able to manually enter an exact concatenation of the first two values).

The whole process would be really easy if it weren't in the rows of an editable grid (grrr!). But I think I'm close. Any help on those two clarifications?
_________________
VBAjedi
jedi at NOSPAM dot obie dot com
View profile  Send private message
VBAjedi


Posts: 34
Posted: 01/08/2004, 12:57 PM

Aha! Got it (thanks, Helen - you're a CodeCharge angel!). Here's a little tutorial I wrote:

The following procedure will let a field represent the concatenation of two other fields within an editable grid. I won't get into a discussion of whether you really ought to be storing a concatenated value in your database, except to say that in many cases this could be bad database design (because you are essentially storing duplicate information in two columns).

But we'll assume you've already concluded (say, for performance reasons) that you do need to do this. For this example we'll assume you have an editable grid with three fields: FirstN, LastN, and FullName. You want your users to type in FirstN and LastN, and you want their full name to automatically be inserted into FullName. No problem, right? Just put together a little JavaScript code in the OnChange events of FirstN and LastN to insert the concatenated value into FullName.

Well, the thing that makes this tricky is the fact that Code Charge modifies the field names in an editable grid (so each one is unique) by adding an underscore and row number to the end of each field name in each row (take a look at the published HTML for an editable grid and you'll see what I mean). So we need that row number before we can even address the correct fields. Here's what we can do:

1) In the design view, click on the FirstN control. Now in the Properties pane, click on the "Events" tab, then right-click the "On Change" event and select "Add Code". This should switch you to the HTML view and put the cursor at the "Custom Code" section of the "On Change" event.
2) Replace ”// Write your own code here." with the following code:
var name;  
var len;  
var id;  
var pos;  
name = this.name;  
len = this.name.length;  
pos = name.lastIndexOf("_");  
id = name.substr(pos+1, len-pos);  
var corr_nameFullName = "FullName_" +id;  
var corr_nameFirstN = "FirstN_" +id;  
var corr_nameLastN = "LastN_" +id;  
  
var TnamesFullName = document.getElementsByName(corr_ nameFullName);  
var TnamesFirstN= document.getElementsByName(corr_ nameFirstN);  
var TnamesLastN = document.getElementsByName(corr_ nameLastN);  
  
TnamesFullName [0].value = TnamesFirstN[0].value + " " + TnamesLastN[0].value; 
3) Repeat steps 1 and 2 for the LastN control. The code will be the same.
4) (Optional step) In the design view, click on the FullName control. Now in the Properties pane, click on the "Format" tab. Scroll down to the "Read Only" property and select it. This prevents users from directly changing the FullName field.

Now publish your page. Any time you change a "FirstN" field value or a "LastN" field value on any editable grid row, the "FullName" value for that row should now automatically update.

To adapt this approach to an existing page, you will obviously need to edit the code to use the appropriate field names. You will also need to review the last line of code to decide whether you want the values concatenated in that order, seperated by a space.

_________________
VBAjedi
jedi at NOSPAM dot obie dot com
View profile  Send private message
Steve_Ebbrell

Posts: 11
Posted: 01/08/2004, 4:15 PM

Here is the SQL way to do it, please remember that you can do almost anything in SQL and afterwards you can instantly convert your CCS script to another language.
If you use custom script code you would have to manually convert all your custom code if you wanted to move your PHP app to ASP for example.

Select fname, lname, addr1, addr2, concat(fname,' ',lname) as full_name
From table

alternative


Select fname, lname, addr1, addr2, ||(fname,' ',lname) as full_name
From table

Steve...
_________________
Ambition is the last refuge of the failure. - Oscar Wilde
View profile  Send private message
VBAjedi


Posts: 34
Posted: 01/08/2004, 4:21 PM

Thanks Steve, but the key here is that it needed to be CLIENT-side. The user sees the concatenated field change as soon as they change one of the source fields - AFTER the grid is populated but BEFORE changes are submitted to the server.

Your approach is useful in other situations, though.
_________________
VBAjedi
jedi at NOSPAM dot obie dot com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.