Skip to main content
Known Participant
July 29, 2008
Question

A little javascript help

  • July 29, 2008
  • 1 reply
  • 217 views
On my form, I have a field for contact name and another for email. I then have a java controlled button and if clicked, it should popup another field for contact and and another for email, side, by side, If the button is clicked again, two more popup, etc.

Here is the javascript that I am using and the corresponding button :
<script type="text/javascript">
function addsupplier_email() {

input.setAttribute("type","text");
input.setAttribute("name","supplier_email");
input.setAttribute("required","yes");
input.setAttribute("size","30");
input.setAttribute("maxlength","200");
document.getElementById("additional_email").appendChild(input);
document.getElementById("additional_email").appendChild(document.createElement("br"));
input.focus();
}
</script>

<div id="additional_contact">
<input type="button" value="Add Additional Supplier Contact" onclick="addsupplier_email();" />
</div>

The problem that I am having is that this works fine for just one field, but when I copy the javacode and try to add two fields, it does not seem to work. It will just add fields across instead of the next rowl.

Can somebody please help me fix the code ?

Thanks
    This topic has been closed for replies.

    1 reply

    Inspiring
    August 4, 2008
    Here is one way that you could do it by using the innerHTML property. It may throw off some of the formatting when a new row is added so you probably want to keep the contact and email in it's own table.