phpecono
05-15-2008, 01:30 PM
Hey guys i need to find a way to send the "i" auto imcrementation var from this script to to the order imput field every time the HTML of the forme are generated but it had to send it only in the one bein created ... Anybody can help?
<script type="text/javascript">
var fields;
function HTMLBlock(el) {
var instance = 1, elementNames = [], i, item, container;
/* remove source element */
container = el.parentNode;
container.removeChild(el);
/* cache input elements' name attributes */
for (i = 0; item =
el.getElementsByTagName("input").item(i); i++) {
elementNames[i] = item.getAttributeNode("name");
}
/* method to modify and insert a clone of the original element */
this.insert = function () {
for (var i = elementNames.length; i--; ) {
/* replace digits with instance # */
elementNames[i].nodeValue =
elementNames[i].nodeValue.replace(/\d+/, instance);
}
instance++;
container.appendChild(el.cloneNode(true));
};
}
function createHTMLBlock(id) {
var d = document, el;
/* test browser supports the methods we'll be using */
if (d.getElementById && (el = d.getElementById(id)) &&
el.getElementsByTagName && el.cloneNode &&
el.getAttributeNode) {
/* ... etc. */
return new HTMLBlock(el); // yes
}
return null; // no
}
function addHTML() {
if (fields) {
fields.insert();
}
}
</script>
<center><input type="button" onclick="addHTML()" value="Add Fields"></center><br>
<div id="new_link_fields"><div id="form_source"><span class="r">Nom: <input type='text' name='nom_[]' value='' size='20'><input type='hidden' name='i[]' value='1'> <input type='file' name='mp3_' size='30'><input type='text' name='ordre' value=''><br></span></div></div>
<script type="text/javascript">
/* remove the HTML and set up the object down here, before
anything's displayed */
fields = createHTMLBlock("form_source");
</script>
<script type="text/javascript">
var fields;
function HTMLBlock(el) {
var instance = 1, elementNames = [], i, item, container;
/* remove source element */
container = el.parentNode;
container.removeChild(el);
/* cache input elements' name attributes */
for (i = 0; item =
el.getElementsByTagName("input").item(i); i++) {
elementNames[i] = item.getAttributeNode("name");
}
/* method to modify and insert a clone of the original element */
this.insert = function () {
for (var i = elementNames.length; i--; ) {
/* replace digits with instance # */
elementNames[i].nodeValue =
elementNames[i].nodeValue.replace(/\d+/, instance);
}
instance++;
container.appendChild(el.cloneNode(true));
};
}
function createHTMLBlock(id) {
var d = document, el;
/* test browser supports the methods we'll be using */
if (d.getElementById && (el = d.getElementById(id)) &&
el.getElementsByTagName && el.cloneNode &&
el.getAttributeNode) {
/* ... etc. */
return new HTMLBlock(el); // yes
}
return null; // no
}
function addHTML() {
if (fields) {
fields.insert();
}
}
</script>
<center><input type="button" onclick="addHTML()" value="Add Fields"></center><br>
<div id="new_link_fields"><div id="form_source"><span class="r">Nom: <input type='text' name='nom_[]' value='' size='20'><input type='hidden' name='i[]' value='1'> <input type='file' name='mp3_' size='30'><input type='text' name='ordre' value=''><br></span></div></div>
<script type="text/javascript">
/* remove the HTML and set up the object down here, before
anything's displayed */
fields = createHTMLBlock("form_source");
</script>