Log in

View Full Version : Combining fields in a Form



Jim Weinberg
02-13-2006, 07:14 PM
Does anyone know how to combine form fields? I have 3 separate fields for a phone number (areacode, prefix, and number). I'd like to pass a single, formatted field to the CGI script [(areacode) prefix-number]. Is that possible?

Thanks.

Twey
02-13-2006, 07:47 PM
Not reliably so, no. Why would you want to do such a thing?

Jim Weinberg
02-13-2006, 08:20 PM
Because, as I said, I've separated the phone number into three input fields but I only want a single formated field sent to the CGI script.

Twey
02-13-2006, 08:52 PM
Ah - you have no control over the CGI script, I take it.
Well, try:
<form onsubmit="
var a = elements['area'],
p = elements['prefix'],
n = elements['number'];
elements['phone'].value = a + " " + p + "-" + n;
return true;
">... where "phone" is a hidden input element.

However, as I said, this is very unreliable; if you can possibly alter the CGI script to take the three seperate fields, I strongly suggest you do so.

Jim Weinberg
02-14-2006, 12:29 PM
Twey.

Thanks, I'll try it. No, I don't have any control over the CGI. Based on what you said about its reliability though, I may end up just making it a single Phonenumber field and let the submitter enter the number however they want. Not as neat, but a lot easier to implement.

Thanks again.

Twey
02-14-2006, 12:49 PM
True. Neatness counts for something, but efficiency and user-control is nicer, in my opinion.