Form field duplication

S

Steve Darby

Hi there,

I wonde if anyone can help me. I have a couple of problems which I am
having trouble resolving. Firstly, I have written a form which includes
field for First Name, Surname and Address, etc I wish to add either a
checkbox or button to enable the user to click and copy details into fields
further down the form to avoid the need to retype. Here is the relevant
section of the form:

<h2>Sample Order Information Form</h2>
<FORM onSubmit="return validateForm(this)" method="post"
action="http://telemat.open.ac.uk/tt281/testform/decode_form.cfm"
name="myForm">
<table cellspacing="0">
<tr>
<td><h3>Shipping Information</h3></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstName" maxlength="30"></td>
</tr>
<tr>
<td>Family Name</td>
<td><input type="text" name="familyName"
maxlength="30"></td>
</tr>
<tr>
<td>Contact telephone number</td>
<td><input type="text" name="phoneNumber"
maxlength="30"></td>
</tr>
<tr>
<td>Mobile telephone number</td>
<td><input type="text" name="mobileNumber" maxlength="30"></td>
</tr>


<tr>
<td>Delivery Address</td>
<td>
<textarea name="delivery" rows="8" cols="30">Enter the
delivery address.</textarea></td>
</tr>


<tr>
<td><h3>Billing Information</h3></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>First Name</td>
<td><input type="text" name="firstName2"
maxlength="30"></td>
</tr>
<tr>
<td>Family Name</td>
<td><input type="text" name="familyName2"
maxlength="30"></td>
</tr>
<tr>
<td>Email address</td>
<td><input type="text" name="emailAddress"
maxlength="30"></td>
</tr>
<tr>
<td>Contact telephone number</td>
<td><input type="text" name="phoneNumber2"
maxlength="30"></td>
</tr>

<tr>
<td>Mobile telephone number</td>
<td><input type="text" name="mobileNumber2" maxlength="30"></td>
</tr>

<tr>
<td>Credit Card Number</td>
<td><input type="text" name="cardNumber"
maxlength="30"></td>
</tr>
<tr>
<td>Credit Card Type</td>
<td>
<input type="radio" value="visa" name="cardType">Visa
<input type="radio" value="mastercard" name="cardType">Mastercard
</td>
</tr>
<tr>
<td>Special Instructions</td>
<td>
<textarea name="instructions" rows="8" cols="30">Enter your
requirements here or comments.</textarea></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
<td><input type="reset"></td>
<td>&nbsp;</td>
</tr>
</table>
</form>

The field I wish to be able to duplicate are First Name, Family Name,
Contact Telephone Number and Mobile Telephone Number. I would like these
field to be duplicated when the user clicks on a button, link of checkbox at
the end of Shipping Information section of the form.

Secondly, I have written a piece of script which produces a wraparound
slideshow, with buttons to move forward and backwards, that allows the user
to view various views of a product. The images used are of varying size and
if I rescale them all to the same size, some images become distorted. If
there a way to produce a box of a specific size into which the images may be
placed, which will remain a constant size, irrespective of the image within,
i.e. one that does not resize to the size of the image within. Here is the
relevant script:<H3>Other images of the sample pan:</H3>
<br>

<FORM NAME="imgForm">

<IMG SRC="images/slideImg0.jpg" HEIGHT="155" WIDTH="250" ALT="Our Vacation
Pix" NAME="slideshow" ALIGN="LEFT" HSPACE="10">
<INPUT TYPE="BUTTON" onClick="newSlide(-1)" VALUE="&laquo; Previous">
<INPUT TYPE="BUTTON" onClick="newSlide(1)" VALUE="Next &raquo;">

<P><TEXTAREA NAME="imgText" ROWS="1" COLS="16" READONLY></TEXTAREA></P><TR>
</FORM>

And this is the function that handles the image and caption cycling:

captionText = new Array("Front View","Optional Glass Lid","Side
Elevation","With Standard Lid"
)

thisImg = 0

imgCt = captionText.length



function newSlide(direction) {

if (document.images) {

thisImg = thisImg + direction

if (thisImg < 0) {

thisImg = imgCt-1
}

if (thisImg == imgCt) {

thisImg = 0
}

document.slideshow.src = "images/slideImg" + thisImg + ".jpg"
document.imgForm.imgText.value = captionText[thisImg]

}

}


Finally, I have been trying to write a function that will check that a name
begins with a capital letter and alerts the user accordingly, using a
regular expression. As an alternative a function that reformats the name
into the correct format would be good.

Any help would be much appreciated. Many thanks in advance.

Steve.
 
D

Dietmar Meier

Steve said:
I have written a form which
includes field for First Name, Surname and Address, etc I wish to
add either a checkbox or button to enable the user to click and copy
details into fields further down the form to avoid the need to
retype.

<input type="checkbox" onclick="var r, i, j, e=form.elements, l=e.length;
for (i=0; i<l; i++) if (e.type=='text') {
r=new RegExp('^' + e.name + '\\d+$');
for (j=0; j<l; j++) if (r.test(e[j].name) && e[j].type==e.type)
e[j].value = checked? e.value : '' }"
ciao, dhgm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top