Subject | Re: [firebird-php] Grid data entry |
---|---|
Author | Milan Babuskov |
Post date | 2003-10-13T16:19:14Z |
Rajesh Kumar wrote:
<input type=text name=field_name[x] onChange="changedField(x);">...
This can be easily created when showing form for the first time. X and Y
are variables that show row/column number, so each cell knows what row
it's in. At end of each row, you should have something like this:
<input type=hidden name=changedX value=false>
Where X is the same number. At the end of form, you can add one field
(to make things easier later):
<input type=hidden name=rowcount value=<? echo $number_of_rows; ?>>
The changedField function looks like this:
function changedField(x)
{
eval ('document.form.' + x + '.value = true;');
}
So if user changes any data in that row, the hidden fields value changes
to true. Of course, you can use 0/1 instead of true/false, and you can
shorten the variable names to save bandwidth... Now on to PHP part.
In PHP you'll get arrays of $field_name variables for each field. And a
lot of changedX variables. Now you can do this:
for ($i=0; $i<$rowcount; $i++)
{
$varname = 'changed' . $i;
if ($$varname == 'true') // row "i" has changed
{
$sql = "UPDATE table SET ....";
}
}
Well, that's just one of the ways to do it... hope it gives you ideas.
--
Milan Babuskov
http://fbexport.sourceforge.net
> Ya, you're right. Its not that I hate JS. I was just surprised to seeIn each row, you should use variables like this:
> someone achieve what I wanted easily with only PHP. I'm no JS expert
> here, but I'd love to learn how one could achieve this with JS. Atleast
> a pseudo code?
>
> Something like:
>
> onChange(textBox1)
> populate someArray ?
>
> But then how would one go about transferring this array, so that it can
> be handled with PHP?
<input type=text name=field_name[x] onChange="changedField(x);">...
This can be easily created when showing form for the first time. X and Y
are variables that show row/column number, so each cell knows what row
it's in. At end of each row, you should have something like this:
<input type=hidden name=changedX value=false>
Where X is the same number. At the end of form, you can add one field
(to make things easier later):
<input type=hidden name=rowcount value=<? echo $number_of_rows; ?>>
The changedField function looks like this:
function changedField(x)
{
eval ('document.form.' + x + '.value = true;');
}
So if user changes any data in that row, the hidden fields value changes
to true. Of course, you can use 0/1 instead of true/false, and you can
shorten the variable names to save bandwidth... Now on to PHP part.
In PHP you'll get arrays of $field_name variables for each field. And a
lot of changedX variables. Now you can do this:
for ($i=0; $i<$rowcount; $i++)
{
$varname = 'changed' . $i;
if ($$varname == 'true') // row "i" has changed
{
$sql = "UPDATE table SET ....";
}
}
Well, that's just one of the ways to do it... hope it gives you ideas.
--
Milan Babuskov
http://fbexport.sourceforge.net