Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the value in a form before sending

Status
Not open for further replies.

ale77

Programmer
Joined
Jul 18, 2003
Messages
38
Location
US
I have a problem. I have a form and before sending the information I have to change the phoennumber format. For example, if a user enters 333-333-3333, I have to get rid of the character "-". I know how to do that, but it doesn't take it. This is my code:

function validForm() {
var stripped;
var msg="";
var result = true;
var phoneval = document.cust_name_addrs.phone.value;
var faxval = document.cust_name_addrs.fax.value;
//strip out acceptable non-numeric characters

if ( phoneval == "" ) {
msg = msg + 'Please enter your Phone Number\n';
result = false;
} else if ( faxval == "" ) {
msg = msg + 'Please enter your Fax Number\n';
result = false;

if (!result)
alert(msg);

document.cust_name_addrs.phone.value = document.cust_name_addrs.phone.value.replace(/[\(\)\.\-\ ]/g, '');
return result;
}
When I submit the form it doen't change the value, only if there is an error it changes, otherwise it sends the info with the "-". Other problem is that when it finds and error it shows the phone without the "-".

Hope sompeone helps. Bye
 
I really struggled to figure out what you meant in your post there, mate. :)

The first problem I can see if that you need an
Code:
}
after your if-else block. Other than that it should work. Though it might be easier to change your regexp code around a bit so it only allows certain characters, rather than disallowing a bunch of them.

HTH.
 
Hi, thanks for your reply. The missing } is because I deleted other things before putting it here. I don't know a lot about javascript so I don't know about regexp. The problems is that when I want to submit the form, I want the phone to be send like this: 1112223333 instead of 111-222-3333.
 
Right, so it'll do that already (if you fix the missing
Code:
}
).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top