/    Sign up×
Community /Pin to ProfileBookmark

need extendible forms like here…


[url]http://www.quirksmode.org/dom/domform.html[/url]

but i can’t reproduce or even copy it. the “give me more fields button” never works. only the remove fields button and the initial execuring of the script seems to work. so i have one set of removable form fields. but can’t add a second set.

does anybody know how to use the script?

(i’am a javascript noob and learning i by doing it :-|)

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@dermoritzauthorApr 12.2007 — need a "push", because its urgent...
Copy linkTweet thisAlerts:
@toicontienApr 12.2007 — We need the code you're working with, though.
Copy linkTweet thisAlerts:
@dermoritzauthorApr 12.2007 — thats a copy from the site: http://www.quirksmode.org/dom/domform.html

(extracted the essential parts?!)

"

<html>

<head>

<script type="text/javascript">


var counter = 0;

function init() {

document.getElementById('moreFields').onclick = moreFields;

moreFields();

}

function moreFields() {

counter++;

var newFields = document.getElementById('readroot').cloneNode(true);

newFields.id = '';

newFields.style.display = 'block';

var newField = newFields.childNodes;

for (var i=0;i<newField.length;i++) {

var theName = newField[i].name

if (theName)

newField[i].name = theName + counter;

}

var insertHere = document.getElementById('writeroot');

insertHere.parentNode.insertBefore(newFields,insertHere);



}

window.onload = moreFields;

moreFields;

</script>

</head>

<body>

<div id="readroot" style="display: none">



<input type="button" value="Remove review"
onclick="this.parentNode.parentNode.removeChild(this.parentNode);" /><br /><br />

<input name="cd" value="title" />

<select name="rankingsel">
<option>Rating</option>

<option value="excellent">Excellent</option>
<option value="good">Good</option>
<option value="ok">OK</option>
<option value="poor">Poor</option>
<option value="bad">Bad</option>
</select><br /><br />

<textarea rows="5" cols="20" name="review">Short review</textarea>
<br />Radio buttons included to test them in Explorer:<br />
<input type="radio" name="something" value="test1" />Test 1<br />
<input type="radio" name="something" value="test2" />Test 2


</div>

<form method="post" action="/cgi-bin/show_params.cgi">

<span id="writeroot"></span>

<input type="button" onclick="moreFields" id="moreFields" value="Give me more fields!" />
<input type="submit" value="Send form" />


</form>

</body>

</html>

"
Copy linkTweet thisAlerts:
@dermoritzauthorApr 12.2007 — ok i got a trace:

if saved as a local html file, firefox saves some additional resources:

"domform-Dateienquirksmode.js" for example. i think i only need some parts of this file.

what i need to know what parts of them ar needed for this single script/ purpose.

thx in advance
Copy linkTweet thisAlerts:
@dermoritzauthorApr 12.2007 — ok i condensed it:

i need:

"

window.onload = function () {

if (self.init)
init();

}

"

from the included .js

it is somehow related to:

"

function init() {

document.getElementById('moreFields').onclick = moreFields;

moreFields();

}

"

from the script part in html.

(now i have both in html)

i know this makes the button working (adding a set of fields)

but what does it do exactly and is this necessary in it's entirety?
×

Success!

Help @dermoritz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...