'Gebruik Gegevens' knop
Ik heb een formuliertje met daarin velden van naam, adres dat soort dingen. Nu wil ik met 1 druk op de knop dat mensen op 'Gebruik mijn gegevens' hun gegevens daarin kunnen zetten. Dit gebruik ik als JavaScriptje:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
function domainowner() {
with (document.forms[1]) {
ownername.value = dbname.value;
ownerlast.value = dblast.value;
ownercompany.value = dbcompany.value;
owneraddress.value = dbaddress.value;
ownercity.value = dbcity.value;
ownerpostal.value = dbpostal.value;
ownerhousenumber.value = dbhousenumber.value;
ownertelephone.value = dbtelephone.value;
ownerfax.value = dbfax.value;
ownermail.value = dbmail.value;
}
}
with (document.forms[1]) {
ownername.value = dbname.value;
ownerlast.value = dblast.value;
ownercompany.value = dbcompany.value;
owneraddress.value = dbaddress.value;
ownercity.value = dbcity.value;
ownerpostal.value = dbpostal.value;
ownerhousenumber.value = dbhousenumber.value;
ownertelephone.value = dbtelephone.value;
ownerfax.value = dbfax.value;
ownermail.value = dbmail.value;
}
}
Mijn form klopt ook gewoon:
Code (php)
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
60
61
62
63
64
65
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
60
61
62
63
64
65
<form method="post" action="panel.php?page=register">
<input type="hidden" name="dbname" value="Niels">
<input type="hidden" name="dblast" value="xxxx">
<input type="hidden" name="dbcompany" value="xxxx">
<input type="hidden" name="dbaddress" value="xx">
<input type="hidden" name="dbcity" value="xxxx">
<input type="hidden" name="dbpostal" value="5821JR">
<input type="hidden" name="dbhousenumber" value="21">
<input type="hidden" name="dbtelephone" value="124567890">
<input type="hidden" name="dbfax" value="124567890">
<input type="hidden" name="dbmail" value="[email protected]">
<tr>
<td><strong>Houder gegevens:</strong></td>
<td><input name="copyOwnerButton" type="button" onClick="domainowner()" value="Gebruik mijn gegevens"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Voornaam:</td>
<td><input type="text" name="ownername" />*</td>
</tr>
<tr>
<td>Achternaam:</td>
<td><input type="text" name="ownerlast" />*</td>
</tr>
<tr>
<td>Bedrijf/Organisatie:</td>
<td><input type="text" name="ownercompany" /></td>
</tr>
<tr>
<td>Adres:</td>
<td><input type="text" name="owneraddress" />*</td>
</tr>
<tr>
<td>Huisnummer:</td>
<td><input type="text" name="ownerhousenumber" />*</td>
</tr>
<tr>
<td>Woonplaats:</td>
<td><input type="text" name="ownercity" />*</td>
</tr>
<tr>
<td>Postcode:</td>
<td><input type="text" name="ownerpostal" />*</td>
</tr>
<tr>
<td>Land (2 letter bv: nl):</td>
<td><input type="text" name="ownercountry" />*
<a href="javascript:MM_openBrWindow('landcodes.html','','width=650,height=400,scrollbars=yes"><img border="0" src="img/globe.gif" width="20" height="20" /></a></td>
</tr>
<tr>
<td>Telefoon:</td>
<td><input type="text" name="ownertelephone" />*</td>
</tr>
<tr>
<td>Fax:</td>
<td><input type="text" name="ownerfax" /></td>
</tr>
<tr>
<td>E-mail adres:</td>
<td><input type="text" name="ownermail" />*</td>
</tr>
<input type="hidden" name="dbname" value="Niels">
<input type="hidden" name="dblast" value="xxxx">
<input type="hidden" name="dbcompany" value="xxxx">
<input type="hidden" name="dbaddress" value="xx">
<input type="hidden" name="dbcity" value="xxxx">
<input type="hidden" name="dbpostal" value="5821JR">
<input type="hidden" name="dbhousenumber" value="21">
<input type="hidden" name="dbtelephone" value="124567890">
<input type="hidden" name="dbfax" value="124567890">
<input type="hidden" name="dbmail" value="[email protected]">
<tr>
<td><strong>Houder gegevens:</strong></td>
<td><input name="copyOwnerButton" type="button" onClick="domainowner()" value="Gebruik mijn gegevens"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Voornaam:</td>
<td><input type="text" name="ownername" />*</td>
</tr>
<tr>
<td>Achternaam:</td>
<td><input type="text" name="ownerlast" />*</td>
</tr>
<tr>
<td>Bedrijf/Organisatie:</td>
<td><input type="text" name="ownercompany" /></td>
</tr>
<tr>
<td>Adres:</td>
<td><input type="text" name="owneraddress" />*</td>
</tr>
<tr>
<td>Huisnummer:</td>
<td><input type="text" name="ownerhousenumber" />*</td>
</tr>
<tr>
<td>Woonplaats:</td>
<td><input type="text" name="ownercity" />*</td>
</tr>
<tr>
<td>Postcode:</td>
<td><input type="text" name="ownerpostal" />*</td>
</tr>
<tr>
<td>Land (2 letter bv: nl):</td>
<td><input type="text" name="ownercountry" />*
<a href="javascript:MM_openBrWindow('landcodes.html','','width=650,height=400,scrollbars=yes"><img border="0" src="img/globe.gif" width="20" height="20" /></a></td>
</tr>
<tr>
<td>Telefoon:</td>
<td><input type="text" name="ownertelephone" />*</td>
</tr>
<tr>
<td>Fax:</td>
<td><input type="text" name="ownerfax" /></td>
</tr>
<tr>
<td>E-mail adres:</td>
<td><input type="text" name="ownermail" />*</td>
</tr>
(Ik heb wat stukken code uit het formulier gehaald, dus het is niet slordig gemaakt hehe)
Iemand een oplossing? Onderin IE staat ook 'Fout op de pagina' als ik op de knop druk.
Bedankt, Niels.
Gewijzigd op 01/01/1970 01:00:00 door Niels van K
I.p.v. de namen gebruik je document.getElementById("id"). Ipv "id" zet je de id van het veld ; ).
Wat bedoel je precies, ik heb dit scriptje ook op internet gevonden.. Voor mij is JavaScript echt chinees hehe..
Code (php)
1
2
3
4
5
6
2
3
4
5
6
function domainowner() {
with (document.forms[1]) {
document.getElementById("owner_name").value = document.getElementById("db_name").value;
// etc.
}
}
with (document.forms[1]) {
document.getElementById("owner_name").value = document.getElementById("db_name").value;
// etc.
}
}
Je HTML wordt dan:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<form method="post" action="panel.php?page=register">
<input type="hidden" name="dbname" id="db_name" value="Niels">
<tr>
<td><strong>Houder gegevens:</strong></td>
<td><input name="copyOwnerButton" type="button" onClick="domainowner()" value="Gebruik mijn gegevens"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Voornaam:</td>
<td><input type="text" name="ownername" id="owner_name" />*</td>
</tr>
// etc.
<input type="hidden" name="dbname" id="db_name" value="Niels">
<tr>
<td><strong>Houder gegevens:</strong></td>
<td><input name="copyOwnerButton" type="button" onClick="domainowner()" value="Gebruik mijn gegevens"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Voornaam:</td>
<td><input type="text" name="ownername" id="owner_name" />*</td>
</tr>
// etc.
Het werkt nog niet:
JS:
Code (php)
1
2
3
4
5
2
3
4
5
function domainowner() {
with (document.forms[1]) {
document.getElementById("ownername").value = document.getElementById("dbname").value;
}
}
with (document.forms[1]) {
document.getElementById("ownername").value = document.getElementById("dbname").value;
}
}
HTML:
Code (php)
1
2
2
<input type="hidden" name="dbname" id="dbname" value="Niels">
<td><input type="text" name="ownername" id="ownername" />*</td>
<td><input type="text" name="ownername" id="ownername" />*</td>
Krijg nog steeds 'Fout op de pagina' in IE.
Trouwens, volgens mij kan dat with() wel weg. Dus:
Nu werkt ie wel, lag aan die with tag, staat geincluded in een js bestandje, bedankt!!