SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small bit of coding guidance

    I'm hoping that one of the javascript experts amongst us here will be able to help me out...

    I have a form and within that form are two text fields... with the id's subject_1 and content_1. What I would like is for the user to be able to click a link and have a second pair of text fields open underneat with the id#s subject_2 and content_2. And then, should they choose, click the link again and open another pair of text fields called subject_3 and content_3.

    How can I do that ? Thanks for any help..

  2. #2
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK so you want a script to generate two <input> text boxes when clicked.

    Code:
    function addMoreBoxes()
    {
    //Get Form
    var formElm = document.getElementById('formID');
    var inputTotal = formElm.getElementsByTagName('input').length;
    inputTotal/=2;
    formElm.innerHTML += '<input id="subject_'+inputTotal+'" name="subject_'+inputTotal+'" /> <input id="content_'+inputTotal+'" name="content_'+inputTotal+'" />';
    }
    Then on your link add this

    Code:
    <a href="javascript:addMoreBoxes()">Add more</a>
    I can't believe I ate the whole thing

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a TON I tried adapting it but I didn't get very far, what I should have posted was the code that I am using to illustrate what I actually have on the page right now...

    This is the code that creates the two boxes

    Code:
    Archive Headline : <input value="" type="text" name="ARCHEAD_1" />
    
    Archive Story :<br><textarea name="ARCNEWS_1" rows="6" cols="60" wrap="virtual">
    How can I adapt the code you have posted so that it creates two more boxes with the names ARCHEAD_2 and ARCNEWS_2 followed by two more named ARCHEAD_3 and ARCNEWS_3, etc.. ?


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
  •