shadowcaster Posted July 10, 2007 Share Posted July 10, 2007 Hello guys. I have a simple form on a page and I want to copy some field's data from one set to another, from the address field (a1) to another address field (pa1). Here is the JavaScript I'm using: <script language="JavaScript1.2" type="text/JavaScript"> function copyOver(){ document.form.pa1.value = document.form.a1.value; document.form.pa2.value = document.form.a2.value; document.form.pa3.value = document.form.a3.value; }</script> and the html: <form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <tr><td width="260" valign="top">Current Address <font color="#FF0000">*</font> </td> <td width="340"><input type="text" name="a1" style="width: 200;" class="contact" maxlength="50"><br> <input type="text" name="a2" style="width: 200;" class="contact" maxlength="40"><br> <input type="text" name="a3" style="width: 200;" class="contact" maxlength="30"></td> <td> </td></tr> <tr><td width="260" valign="top">Permanent Address <font color="#FF0000">*</font> </td> <td width="340"><input type="text" name="pa1" style="width: 200;" class="contact" maxlength="50"><br> <input type="text" name="pa2" style="width: 200;" class="contact" maxlength="40"><br> <input type="text" name="pa3" style="width: 200;" class="contact" maxlength="30"></td> <td width="100" valign="top"><input name="copyOver" type="button" onClick="copyOver();" value="Same As Current"></td></tr> When I click the button it doesn't do anything Quote Link to comment Share on other sites More sharing options...
emehrkay Posted July 11, 2007 Share Posted July 11, 2007 give everything unique id's and do document.getElementById('pa1').value = document.getElementById('a1').value; where pa1 and a1 are the field ids Quote Link to comment Share on other sites More sharing options...
mainewoods Posted July 11, 2007 Share Posted July 11, 2007 using a form starting between tr's is a bad practice and will give you a problem on some browsers(I had that problem with ff I believe) . I don't believe that will validate either. either put the form tag before the table tag and then put the /form tag after the /table tag, or nest the entire form within a td /td Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.