...

View Full Version : Forms Help



ziguana_man
04-11-2005, 12:26 PM
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

snowieken
04-11-2005, 01:11 PM
1.
<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.
<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:

<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).

Philip M
04-11-2005, 07:42 PM
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

ziguana_man
04-12-2005, 08:23 AM
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

Philip M
04-12-2005, 08:17 PM
Sorry, double posted.

Philip M
04-12-2005, 08:23 PM
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.

ziguana_man
04-13-2005, 03:12 AM
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!

JohnKrutsch
04-13-2005, 03:30 AM
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)">

ziguana_man
04-13-2005, 06:38 AM
Cheers guys all going good now :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum