|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi.
I'm still at beginner mode for PHP and Javascript, working out of books. If I have a form on a page, and I want to validate the 2 input fields, and display the result in a third field, is it best to use Javascript or PHP? The rest of the site is already using PHP for menu includes. With PHP, how do you make the result stay on the same page? So far I've only practised pages that go to a new page when you hit submit. What percentage of people/browsers would have Javascript disabled? - is it generally worth excluding Javascript function if there is an alternative work around? ta Chris |
|
||||
|
Quote:
2. refer page back to itself and use if (isset($var1) and isset($var2)) {to change output:} 3. http://www.w3schools.com/browsers/browsers_stats.asp
__________________
Irony: That for most people the most "trusted" web site on the planet is for a company the has been convicted of criminal activity. Both Security and SuSe start with "S". www.oldslides.com |
|
|||
|
I agree - the more server side coding you can use - the less chances you have something worrying about wiht the way the browser will (not) handle your coding.
|
|
|||
|
Thanks mushroom.
I found onlamp.com, which had a great example on what you suggest. I have put my first version at http://womens-health-and-fitness.com...mass-index.php Problems so far: 1. It seems to reset the input values to blanks when it redisplays the screen. 2. When you try to refresh the screen, you get the message 'cannot refresh, retry or cancel'. Is that normal with forms calling the same page? 3. I couldnt test this offline. I have e-novative's WAMP environment on my PC to test PHP, and this exact code would NOT process the isset command offline. I had echos coming out of my seat trying to see why it wouldn't go into my if statement. After 2 hours I uploaded it and it worked. Is this normal for offline PHP environments? I put the php code immediately above the form, as follows: <? $bminum = ""; $bmitext = ""; if (isset($metric_bmi_entered)) { $height = $_POST["bheight"]; $weight = $_POST["bweight"]; $squareheight = $height * $height; $bmi = $weight / $squareheight; $bminum = sprintf ("%1.2f", "$bmi"); if ($bminum < 18.5) { $bmitext = "underweight"; } elseif ($bminum < 25) { $bmitext = "normal" ; } elseif ($bmitext < 30) { $bmitext = "overweight"; } else { $bmitext = "obese";} } ?> I spent time looking at the php switch command, but couldn't see how to put a range of values, or >< in the case statement. Definite beginner. ta Chris |
|
||||
|
I would suggest "both".
This would give you the benefit of reducing calls to your server for form validation when it isn't necessary (i.e. when the user has Javascript enabled), while providing a backup plan in case someone has it disabled.
__________________
Toronto Web Design | Search Engine Friendly, Standards-Compliant Layouts | Walk on my Path (my blog) |
|
|||
|
Quote:
The reason for that is most likely a PHP setting called REGISTER_GLOBALS, see http://at2.php.net/register_globals In order not to rely on this setting, use $_POST['metric_bmi_entered'] instead of $metric_bmi_entered. Quote:
Code:
switch (TRUE) {
case ($bminum < 18.5):
...
}
- Sam
__________________
Software-Pointers.com - Directory of Software Development Sites - Free submission. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |