Form field duplication

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Darby

    #1

    Form field duplication

    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="retur n validateForm(th is)" method="post"
    action="http://telemat.open.ac .uk/tt281/testform/decode_form.cfm "
    name="myForm">
    <table cellspacing="0" >
    <tr>
    <td><h3>Shippin g 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="familyNam e"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td>Contact telephone number</td>
    <td><input type="text" name="phoneNumb er"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td>Mobile telephone number</td>
    <td><input type="text" name="mobileNum ber" 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>Billi ng Information</h3></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>First Name</td>
    <td><input type="text" name="firstName 2"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td>Family Name</td>
    <td><input type="text" name="familyNam e2"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td>Email address</td>
    <td><input type="text" name="emailAddr ess"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td>Contact telephone number</td>
    <td><input type="text" name="phoneNumb er2"
    maxlength="30"> </td>
    </tr>

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

    <tr>
    <td>Credit Card Number</td>
    <td><input type="text" name="cardNumbe r"
    maxlength="30"> </td>
    </tr>
    <tr>
    <td>Credit Card Type</td>
    <td>
    <input type="radio" value="visa" name="cardType" >Visa
    <input type="radio" value="masterca rd" name="cardType" >Mastercard
    </td>
    </tr>
    <tr>
    <td>Special Instructions</td>
    <td>
    <textarea name="instructi ons" 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>Othe r 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="newSli de(-1)" VALUE="&laquo; Previous">
    <INPUT TYPE="BUTTON" onClick="newSli de(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","Wit h Standard Lid"
    )

    thisImg = 0

    imgCt = captionText.len gth



    function newSlide(direct ion) {

    if (document.image s) {

    thisImg = thisImg + direction

    if (thisImg < 0) {

    thisImg = imgCt-1
    }

    if (thisImg == imgCt) {

    thisImg = 0
    }

    document.slides how.src = "images/slideImg" + thisImg + ".jpg"
    document.imgFor m.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.








  • Dietmar Meier

    #2
    Re: Form field duplication

    Steve Darby wrote:
    [color=blue]
    > 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.[/color]

    <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 : '' }"[color=blue]
    >[/color]

    ciao, dhgm

    Comment

    Working...