By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Form field duplication

P: n/a
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.


Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Steve Darby wrote:
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[i].type=='text') {
r=new RegExp('^' + e[i].name + '\\d+$');
for (j=0; j<l; j++) if (r.test(e[j].name) && e[j].type==e[i].type)
e[j].value = checked? e[i].value : '' }"


ciao, dhgm
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.