Skip to main content
Inspiring
August 27, 2009
Answered

Row generation

  • August 27, 2009
  • 1 reply
  • 1651 views

Good morning all,

Is there a way to create a form that will automatically generate a new row after the first is filled but with "reason" for new row?

Thanks in Advance,

DJ Khalif

    This topic has been closed for replies.
    Correct answer BKBK

    If by row you mean input field, then you might want to kick off with something like:

    <script type="text/javascript">
    function checkField() {
    var elementArray = document.forms[0].elements;
    var i=0;
    for (i=0;i<elementArray.length;i++) {
       if (elementArray.value.length != 0) {
        elementArray[i+1].style.display="block";
       }
    }
    }
    </script>
    <form>
    <input name="text1" type="text" onchange="checkField()">
    <input name="text2" type="text" style="display:none;" onchange="checkField()">
    <input name="text3" type="text" style="display:none;" onchange="checkField()">
    <input name="text4" type="text" style="display:none;" onchange="checkField()">
    </form>

    1 reply

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    August 28, 2009

    If by row you mean input field, then you might want to kick off with something like:

    <script type="text/javascript">
    function checkField() {
    var elementArray = document.forms[0].elements;
    var i=0;
    for (i=0;i<elementArray.length;i++) {
       if (elementArray.value.length != 0) {
        elementArray[i+1].style.display="block";
       }
    }
    }
    </script>
    <form>
    <input name="text1" type="text" onchange="checkField()">
    <input name="text2" type="text" style="display:none;" onchange="checkField()">
    <input name="text3" type="text" style="display:none;" onchange="checkField()">
    <input name="text4" type="text" style="display:none;" onchange="checkField()">
    </form>

    djkhalifAuthor
    Inspiring
    August 28, 2009

    BKBK,

    That's exactly what I was looking for. I am learning Javascript one line at a time. Do you have any book recommendations?

    Thanks,

    DJ Khalif

    BKBK
    Community Expert
    Community Expert
    August 29, 2009

    I have "Javascript: The Definitive Guide" by David Flanagan. Be warned, it's a whole lotta book. The current (5th) edition runs to a thousand pages.

    In any case, I refer to the web much more often. Here, Google is worth a bookshelf.