Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Forms Help

  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forms Help

    I'm new to html and forms (well actually just havn't done it for a few years like 7)

    I have dreamweaver and I have created a form with all the form elements but there are a few elements I need help with.

    1. I have added a reset and submit button but how to I add a print button?

    2. How do I make the link to this form bring up the form in a separate window without the IE toolbar etc at the top? I don't want people using those buttons.

    3. I have a numeric field that will be filled in with an 11 didget number, you can set a max but i want it to have a min also so they don't get it wrong, then if they submit the form or print it they get an error or a pop up that reminds them to go fix that field.

    Thanks in advance for any help.

    Mike

  • #2
    Regular Coder
    Join Date
    Nov 2004
    Location
    The land of chocolate
    Posts
    226
    Thanks
    1
    Thanked 16 Times in 16 Posts
    1.
    Code:
    <input type="button" value="Print this form" onclick="window.print();">
    This will show the print dialogue to print out the page this button is in.

    2.
    Code:
    <a href="URL" onclick="window.open('URL', 'name', 'options'); return false">Click here for the form</a>
    The method window.open opens a separate window in the browser. It has three attributes: the URL, the name and the options. The URL and the name are pretty straight forward: there you set the URL of your form, and a unique name to give to the window (which you can choose freely, name it "form1" or something). The options are a bit juicier:

    width (value): width of the opened window
    height (value): height of the opened window
    location (0/1): display the address bar
    status (0/1): display the status bar
    menubar (0/1): display the menu bar (File, Edit, ...)
    directories (0/1): display directory buttons
    toolbar (0/1): display the toolbar (Back, Forward,...)
    resizable (0/1): sets whether the window is resizable
    scrollbars (0/1): display scrollbars

    The different options should be separated by a comma. So, in your case you set everything to 0 (except maybe the scrollbars and resizable, that's your call). In IE the default values are 0, but I am not sure if that is the case in Mozilla browsers and/or Opera. If I recall correctly, those defaults are 1, so I suggest you set everything to 0 nonetheless.

    Example:
    Code:
    <a href="URL" onclick="window.open('form.html', 'form1', 'height=200,width=600,status=0,menubar=0,scrollbars=0,resizable=1'); return false">Click here for the form</a>
    Clicking this link will generate a new window which is 600x200, which has no status window, menubar or scrollbars, but which is resizable.

    3. Using a regular expression is the best solution for that problem. I'll get back to you on that (at least, if no one beats me to it).
    -Snow

    Susie, if you want to see your doll again, leave $100 in this envelope by the tree out front. Do NOT call the police. You CANNOT trace us. You CANNOT find us.

    Sincerely,
    - Calvin.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    3. I have a numeric field that will be filled in with an 11 digit number, you can set a max but I want it to have a min also so they don't get it wrong, then if they submit the form or print it they get an error or a pop up that reminds them to go fix that field.

    if (/^\d{11}$/.test(thenumber.value)) {
    alert ("Only an 11-digit number is valid in this box");
    thenumber = "";
    thenumber.focus();
    return false;
    }

    If the minimum number of digits is not 11 you can alter it to (say)

    if (/^\d{8,11}$/.test(thenumber.value)) //Must be min 8 max 11 digits
    Last edited by Philip M; 04-11-2005 at 07:00 PM.

  • #4
    New Coder
    Join Date
    Apr 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    All good guys but a little more help with 3 :)

    Thanks for the replys guys, all works a treat but I could do with a little more help with 3, how do I tag: -

    if (/^\d{11}$/.test(thenumber.value)) {
    alert ("Only an 11-digit number is valid in this box");
    thenumber = "";
    thenumber.focus();
    return false;
    }

    onto

    <input type="text name="textfield"> in my form?

    Thanks again, your help is much appreciated.
    Mike

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Sorry, double posted.
    Last edited by Philip M; 04-12-2005 at 07:24 PM. Reason: Double posted in error

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    function onlyElevenDigits() {
    if (/^\d{11}$/.test(textfield.value)) {
    alert ("Only an 11-digit number is valid in this box");
    textfield = ""; // clear the field
    textfield.focus(); //and focus on it again
    return false;
    }
    }

    <input type="text" name="textfield" size="11" maxlength="11" onBlur="onlyElevenDigits()">

    Note that textfield must be a compulsory field, as
    once the focus has been placed on the field the script will require
    the 11 digits to be entered. That is, the field cannot be jumped over.

  • #7
    New Coder
    Join Date
    Apr 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks but still having a problem

    Thanks, I now get a script error when I run the page, I tab into the feild discussed and type in 6 didgets, when I tab out I get a scrpt error: -

    Line: 9
    Char: 1
    Error: 'textfield' is undefined
    Code:0
    URL: http://bla/bla/sales_form.htm

    I have added your script to the header of my code and the bit to the button.

    Sorry if I'm missing something obveous!

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try making these changes:

    function onlyElevenDigits(fld) {
    if (!/^\d{11}$/.test(fld.value)) {
    alert ("Only an 11-digit number is valid in this box");
    fld.value = ""; // clear the field
    fld.focus(); //and focus on it again
    return false;
    }
    }

    <input type="text" name="textfield" size="11" maxlength="11" onblur="onlyElevenDigits(this)">

  • #9
    New Coder
    Join Date
    Apr 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Cheers guys all going good now


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •