"Add a field" to add input fields

Discussion in 'JavaScript' started by LazyD, May 14, 2007.

  1. #1
    Let me preface this by saying im a PHP programmer, I dont know any javascript, at all..

    Ive seen a tutorial on the net about adding and subtracting divs from a page, I guess it could similar but as I said before, I dont know javascript and even how to edit a pre made script... What im looking for is something that will do the following:

    There will be 5 Certifications standard, each Certification has 2 text input fields, the Cert name and Cert Expiration Date. I would like under the 5th to have a link that says "Add another Certification", if they click that, it will give 2 more fields, one for the cert name and cert date. I would like this to happen til they have 20 total on the page.

    If anyone would be willing to do that I would appreciate it greatly...
     
    LazyD, May 14, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Any PHP programmer knows some javascript. why don't you search for some JS manuals and read them?
    google is your friend!! ;)
     
    gibex, May 14, 2007 IP
  3. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #3
    <script language="javascript">
    nr=5;
    function addCertification(nr){
    if(nr<=20){
    holder=document.getElementById("your_certifications_holder");
    holder.innerHTML+="Some label <input type='text' name='certification1"+nr+"' /><br />";
    holder.innerHTML+="Some label2 <input type='text' name='certification2"+nr+"' />";
    }
    }
    </script>
    <a href="#" onclick="addCertification(nr)">Add another Certification</a>
     
    bibel, May 14, 2007 IP
  4. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    bibel thank you so much, after a little setting up that script worked perfect, the only thing is that it doesnt seem to be incrementing the number, I tried doing:

    nr++;

    at the end of the if statement but it didnt seem to help
     
    LazyD, May 15, 2007 IP
  5. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #5
    <a href="#" onclick="addCertification(nr);nr++;">Add another Certification</a>
     
    bibel, May 15, 2007 IP