Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

phone number

Links for php scripts

Moderators: macek, egami, gesf

phone number

Postby icu90ucme » Thu Aug 07, 2003 7:06 pm

using a form field a customer is going to enter his phone number in this format 1234567890.

can i have php "when the form field loses focus" to change this number into (123)456-7890

or do i have to use javascript i know it's possible in javascipt by using the onBlur=myphonescript command
icu90ucme
New php-forum User
New php-forum User
 
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Postby swirlee » Thu Aug 07, 2003 7:11 pm

PHP is a server-side language, and cannot do anything on the client side after the page has loaded in the user's browser. In other words, use JavaScript. It's not terribly complicated. Though I'm not sure why you'd want to do it (why not just wait until the user submits the form and make the change internally?).
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby sigix » Thu Aug 07, 2003 11:16 pm

yep you can do in Javascript :idea:
sigix
php-forum Active User
php-forum Active User
 
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby icu90ucme » Fri Aug 08, 2003 8:39 am

well im gonna have a lot of users inputting at the same time and i wanted to put the least amount of strain on my server and if i can do it client sider rather than server side it'll help a little
icu90ucme
New php-forum User
New php-forum User
 
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Postby swirlee » Fri Aug 08, 2003 8:56 am

But if you're worried about having accurate data, you're going to have to validate the phone numbers again on the server side anyway, since anybody with JavaScript turned off could enter an arbitrarily-formatted value. Since you're probably doing form validation anyway (right?), doing this on the server side isn't going to make much of a difference.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby nathanwebb6 » Mon Sep 01, 2003 2:51 pm

on the process page after the form you could put this?

$p1 = substr($number, 1, 3);
$p2 = substr($number, 4, 6);
$p3 = substr($number, 7,10);

$finalnumber = "(" . $p1 . ")" . $p2 . "-" . $p3;
nathanwebb6
New php-forum User
New php-forum User
 
Posts: 27
Joined: Sat Jul 05, 2003 5:08 pm
Location: england uk

Postby nathanwebb6 » Mon Sep 01, 2003 2:52 pm

nathanwebb6 wrote:o wait, you wanted it when you lose focus. well u could still use that method if it will work for your needs
nathanwebb6
New php-forum User
New php-forum User
 
Posts: 27
Joined: Sat Jul 05, 2003 5:08 pm
Location: england uk


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.