Closed Thread Icon

Preserved Topic: m x n matrix of inputs (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18467" title="Pages that link to Preserved Topic: m x n matrix of inputs (Page 1 of 1)" rel="nofollow" >Preserved Topic: m x n matrix of inputs <span class="small">(Page 1 of 1)</span>\

 
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-18-2001 15:28

this is more a html-question, so i though i post it here, if im wrong, please move to the sss forum.

i am dynamically creating n x m matrix of text-input fields, which should be named uniquely because after that im creating a mysql-table with the data of the text-input fields.

i tried php, javascript, but it's all a bit difficult.

PHP:
<input type=text name=<? $tname[m][n] ?>>
therefor i should have declared every single variable because after the form-submitting they are NULL.

JS:
<input type=text name=tname[m][n]>
will give me a unique name, but it's difficult to access, cause it's all one string and not a javascript-array. so i would have to write a string parser, that filters out the m and the n.

is there another solution?



GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-19-2001 12:19

is my story unclear or is the problem too difficult?

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-19-2001 14:13

your problem is not precise, and i can't see a problem while doing that...

so you've got a multi-dim array?

here's an untested code:

code:
<?
// $tname[dimension1][dimension2]
$all = 0;
while (list($key1, $value1) = each($tname))
{
while (list($key2, $value2) = each($value1))
{
?><input type='text' value='<?="$key1.$key2=$value2"?>' name='input<?=$all++?>'><?
}
}
?>



I have no idea how you want to name your input fields, but you can name them whatever...I showed you the code that runs through your multi-dim array....

hope that helps.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-19-2001 14:20

first of all, thanks for your help, lallous!

well, i want to name my inputs so that i can afterwards insert them into a mysql table easily.

in your example the name is just input + a number. "input23" for example. did i understand it right?
or what does the '=' do before $all++ ?

big thanks!

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-19-2001 15:02

yes, you understood me write about the $all

code:
<?[b]=[/b]$all?>


this equal sign is a shorthand to 'echo'
as if <?echo $all;?>

i don't understand what you want to insert afterwards, and why you put them in a matrix instead of a flat array?

perhaps you can build me a simple HTML file that expresses what you want. just make that HTML as if you already coded what you want and that HTML is PHP generated, then i'll figure you a way to make an mxn translation.


GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-19-2001 16:34

ok, here it is:
http://www.wapod.com/~grumble/test/table.php

after you go through that process i want all data in variables.
if possible in the mother-window...
big thanks for helping!

[This message has been edited by GRUMBLE (edited 12-19-2001).]

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-20-2001 13:11

dear Grumble,

I noticed that you're naming your form variables as: tcontent[0][0], tcontent[1][0], tcontent[0][1], ...,tcontent[0..m][0..n]...

oh well, you can do it in another simpler way...just name your vars (in javascript) as:
tcontent0 tcontent1
tcontent2 tcontent3
tcontent4 tcontent5
.....the max is: m (rows) * n (cols)
the heads are located from '0'..n

while you've stored all this in a raw matter, you can still access them as a matrix as:

code:
var maxRow = set value here, maxCol = set value here
// as a human you specify the values not as zero based, therefore decrease one here or in the function below
// i.e: maxRow = [b]2[/b] - [/b] (1 row ZERO based)
// i'll not substract one in the function below
function rawFromMatrix(m, n)
{
// similar function applies for PHP code
return document.theForm.elements['tcontent' + (m*maxCol + n)];
}



you, in the caller window, can have a hidden value called: tcontentArr,
now when you will the values in the popup window, on subject do this:

code:
// get all the values and pass the to caller, then we can access them easily in PHP
for (str=[], i=0;i<maxCol*maxRow;i++)
{
str[i] = document.theform.elements['tcontent'+i].value;
}
parent.window.document.theform.tcontentArr.value = str.join(',');
window.close();



now in caller window you have the values that are comma seperated.......
knowing maxRow, and maxCol you can in PHP or JavaScript build a [m]x[n] array from that raw list...

p.s: there are lots of ways to do it, but this is one way...

good luck.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-20-2001 13:36

oh yes, forgot you the matrixFromRaw:

code:
<?
function matrixFromRaw($raw, &$m, &$n)
{
global $maxCol;
$m = $raw / ($maxCol+1); // maxCol is zero based
$n = $raw % ($maxCol+1);
}
?>





[This message has been edited by lallous (edited 12-20-2001).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-20-2001 15:12

lallous, big thanks for your help!

and there's a much simpler code i found out:

code:
for ($i=0;$i<$rows;$i++) {
for ($j=0;$j<$cols;$j++) {
echo"window.opener.tarray[$i][$j]='";print_r( $tcontent[$i][$j] ); echo"';\n";
}
}


weeee... it works! weeehaaaa!

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-20-2001 15:41

1) your code will need an additional post in order to execute that javascript code
2)how will you read the tarray[$i][$j] variables in PHP?

if you want to pass an array to PHP you pass it as:
<input type='hidden' name='theArray[]' value='element1'>
<input type='hidden' name='theArray[]' value='element2'>
<input type='hidden' name='theArray[]' value='element3'>

that will create an array named $theArray ...
but in your case i'm not sure how PHP will pass you this tarray[][] value...
tell me plz if you try it..

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-20-2001 16:22

that is not a javascript-code, that is php.
maybe i should have posted more of it:

code:
echo" Please wait while inserting data... <br> $rows Rows x $cols Columns \n
<script language=\"JavaScript\" type=\"text/JavaScript\">
<!-- enable Stealth mode to hide from really old browsers
window.opener.editmenu.rows.value=$rows;
window.opener.editmenu.cols.value=$cols;

";
for ($i=0;$i<$rows;$i++) {
for ($j=0;$j<$cols;$j++) {
echo"window.opener.tarray[$i][$j]='";print_r( $tcontent[$i][$j] ); echo"';\n";
}
}
echo"
window.opener.editmenu.isTable.value='1';
window.close();
// disable Stealth mode -->
</script>
";
exit;


and it works.

btw: here's another JS-question:
say, i have a frameset with two frames:
leftframe
rightframe

how do i access form-elements between the two?
is it:
var x=leftframe.document.myform.myinput.value;
?
im gonna try.....

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 12-21-2001 10:16

grumble, you totaly got me wrong there....i knew that was PHP and that other one was JS ....

anyway, glad you solved it...


yes, as: frameName.window.document.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-21-2001 12:24

oh. sorry.
so what was your question then?

thank you again!

« BackwardsOnwards »

Show Forum Drop Down Menu