Thread JS: Frage zur Parameterübergabe mit JSON (51 answers)
Opened by Kuerbis at 2011-08-26 19:59

Kuerbis
 2011-08-27 10:48
#151854 #151854
User since
2011-03-20
947 Artikel
BenutzerIn
[default_avatar]
Ist das so in Ordnung?

Code (html): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE HTML>
<html>
<head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <script type="text/javascript">
                function ad_row()
                {
                        var data = {    
                                menge :         { type : 'number' },
                                bezeichnung :   { type : 'text' },
                                euro_stueck :   { type : 'text' },
                                count :         { type : 'hidden' } };

                        var table_id = 'product';
                        var table = document.getElementById( table_id );
                        var rows = table.getElementsByTagName( 'tr' ).length;
                        var tr = table.insertRow( rows );
                        for ( name in data ) 
                        {       
                                var td = document.createElement( 'td' );
                                var input = document.createElement( 'input' );
                                if ( name == 'count' ) 
                                {       input.name = name;
                                        input.value = rows;
                                }
                                else
                                {
                                        input.name = name + '_' + rows;
                                }
                                for ( attr in data[name] )
                                {
                                        input[attr] = data[name][attr];
                                }
                                td.appendChild( input );
                                tr.appendChild( td );
                        }

                }
        </script>
</head>
<body>
<form action="print">
        <table id="product">
                <tr><th>Menge</th><th>Bezeichnung</th><th>Euro/Stück</th></tr>
                <tr>
                        <td><input type="number" name="menge_1" /></td>
                        <td><input type="text" name="bezeichnung_1" /></td>
                        <td><input type="text" name="euro_stueck_1" /></td>
                        <td><input type="hidden" name="count" value="1" /></td>

                </tr>
        </table>
        <br />
        <input type="button" value="Eintrag hinzufügen" onclick="ad_row()" />
        <br /><br />
        <br /><input type="submit" value="OK"/>
</form>
</body>
</html>


Parameterabfrage im 'print'-script:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
        
my $count = ( $self->param( 'count' ) )[-1];
my @rows;
for my $i ( 1 .. $count ) {
    push @rows, {       
        menge => $self->param( "menge_$i" ), 
        bezeichnung => $self->param( "bezeichnung_$i" ), 
        euro_stueck => $self->param( "euro_stueck_$i" ),
        euro_gesamt => $self->param( "menge_$i" ) * $self->param( "euro_stueck_$i" ) };
}



View full thread JS: Frage zur Parameterübergabe mit JSON