Page 1 of 1
LABEL UPDATE and FORM VALIDATION - Need Help
Posted: Mon Sep 20, 2010 8:07 pm
by webbiz
I'm trying to create an ORDER FORM.
On my form there is a Textbox with the name="country". The default value = "United States".
I also have a <Label> </Label> on the page.
If the user leaves the Textbox with "United States", I would like to Echo "$10.00 US" in the Label.
If the user enters anything other than "United States" in the Textbox, I would like to Echo "$18.00 US".
Can this be done in PHP dynamically without the need to click a button or change pages?
Thanks.
Webbiz
Re: LABEL UPDATE and FORM VALIDATION - Need Help
Posted: Mon Sep 20, 2010 8:16 pm
by young buck
You could do it with some Javascript.
Perhaps use "onkeyup" to check the value of "country" textbox.
If it doesn't equal United States, do innerHTML = '18.00 US'
else do innerHTML = '10.00 US'
Re: LABEL UPDATE and FORM VALIDATION - Need Help
Posted: Tue Sep 21, 2010 4:34 pm
by webbiz
Thanks youngbuck.
Is it possible that some browsers may have their javascript turn off? If so, my order form would not work correctly for them, right?
I'm about as familiar with Javascript as I am with PHP...not much. So I'm trying to find a solution that would work for virtually everyone who lands on the page with a common browser.
Webbiz
Re: LABEL UPDATE and FORM VALIDATION - Need Help
Posted: Tue Sep 21, 2010 4:59 pm
by Jonah Bron
No. If you want to do it without changing pages, you must do it with Javascript. You must understand the difference between a client-side script and a server-side script.
PHP is a server-side scripting language. It does it's thing, and then gives the final result to the browser.
Javascript is a client-side scripting language. It runs in the client's browser, allowing you to do things dynamically.
Re: LABEL UPDATE and FORM VALIDATION - Need Help
Posted: Wed Sep 22, 2010 10:08 am
by webbiz
Okay. Thanks Jonah.
You're right, I do have to get those two concepts in my head. Not there yet.
Since I only dabble in these languages to just solve a problem I have at the moment and then move on, I'm not strong in them. Right now I want to get this order form up and running for a new product release. If the customer is in the US, shipping is included in price. If outside US, there is a small shipping charge. So I was hoping to update my existing PHP page to update the displayed price based on what the customer enters into the COUNTRY textbox.
Guess I'll go check out the javascript side of things and see if I can get this happening.
Thanks for your time.
