Results 1 to 2 of 2

Thread: Send auto imcrementation var to last created order imput field

  1. #1
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Send auto imcrementation var to last created order imput field

    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?

    Code:
    <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>

  2. #2
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i tryed this but it's not working
    Code:
    <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();
    }
    }
    
    var o=1;
    
    function vars() {
    o=o+1;
    }
    </script>
    <b>Cliquez sur (Ajouter un espace) pour ajouter une ligne au formulaire d'ajout de MP3</b><br><br>
    <input type="button" onclick="addHTML()" onclick="vars()" value="Ajouter un espace"><br><br>
    
    <div id="new_link_fields"><div id="form_source"><span class="r">Ordre: <script type="text/javascript">document.write('<input type="text" name="ordre'+i+'" size="3" value="'+o+'">');</script> Nom: <input type='text' name='nom_[]' value='' size='20'><input type='hidden' name='i[]' value='1'> MP3: <input type='file' name='mp3_' size='30'><br></span></div></div>
    
    <br><input type="button" onclick="addHTML()" onclick="vars()" value="Ajouter un espace">
    
    <script type="text/javascript">
    /* remove the HTML and set up the object down here, before
    anything's displayed */
    fields = createHTMLBlock("form_source");
    </script>
    everytime i try to use "i" it says it's undifined ... so i made a new var called "o" but it's not incrementing at all ... ... o.0 did i miss something?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •