Home: Perl Programming Help: Intermediate:
Altering values in Textfield and re-displaying



mango
Novice

Mar 18, 2007, 2:48 PM


Views: 2845
Altering values in Textfield and re-displaying

I have this cgi program that contains a form with a textfield. The textfield accepts a phone number. If the user enters something like (999) 999-9999 or 999 999 9999, my program contains code to reformate the entered phone number to the 999-999-9999 format. That is the easy part. Now how do you get the reformated phone number (i.e. the altered parameter value) to display in the textbox after the user presses the Submit button?

For example I have :

$phone = param("phone");

Now I change the value of $phone to a 999-999-9999 format after the user enters his/her format. How do I get my altered $phone value to display in the textbox?

Does this require some fancy javascripting?


KevinR
Veteran


Mar 18, 2007, 11:48 PM


Views: 2838
Re: [mango] Altering values in Textfield and re-displaying

If you are displaying the reformated phone number after the submit button is clicked on, you would not use javascript. You would use the $phone variable. How you do it depends on your perl code though. You are using the CGI module to parse your form fields, are you also using the CGI module to generate the form widgets?
-------------------------------------------------


mango
Novice

Mar 19, 2007, 7:08 AM


Views: 2835
Re: [KevinR] Altering values in Textfield and re-displaying

Its just a simple program that generates the form widgets (i.e. a few textfields and a password_field). The user enters the information and presses submit; if all fields are OK, it redirects to another file.

I can change the format of the $phone value entered by the user and print it outside of the textfield widget, this is pretty standard (i.e. print "Your phone # is" , $phone;). But how do you get that value to change in the widget itself? The textfield is sticky...it just retains the value enterd by the user after you press the submit button.


KevinR
Veteran


Mar 19, 2007, 1:03 PM


Views: 2830
Re: [mango] Altering values in Textfield and re-displaying

The documentation for the CGI module should cover your situation.

http://perldoc.perl.org/CGI.html
-------------------------------------------------


mango
Novice

Mar 19, 2007, 3:28 PM


Views: 2827
Re: [KevinR] Altering values in Textfield and re-displaying

Ahh thanks you are a genius...

I used a simple code; param('phone', $phone) to take over the value, it worked.

Yes documentation manuals can be useful...patience, patience...