BioBob Posted January 29, 2009 Share Posted January 29, 2009 Youre lucky, you get the short version this time. I have a webpage, with a couple of check boxes. These check boxes MAY correspond to what php normally refers to as a $_GET['var'] argument. For simplicity sake, I'll call the argument Im looking for LANG. I also totally suck at javascript. Never bothered to learn it. Everything else is a piece of cake that I ate a long time ago, and it made me fat. But thats besides the point. How do I check the GET arguments in Javascript? For example: Page URL: index.htm?lang=english Javascript: function test() { if (isset($_GET['lang']) if ($_GET['lang'] == "foo") { alert ("Hello Foo!"); //replacing javascript with any other function I want obviously } else { alert("Hello Bar!"); } } I know its not the right syntax, as Im totally unfamiliar with javascript, how do I do the equivilant in javascript? Quote Link to comment https://forums.phpfreaks.com/topic/142940-solved-i-suck-at-javascript-need-something-to-read-the-php-equiv-of-_get-args/ Share on other sites More sharing options...
Mchl Posted January 29, 2009 Share Posted January 29, 2009 I use this http://snippets.dzone.com/posts/show/4681 Quote Link to comment https://forums.phpfreaks.com/topic/142940-solved-i-suck-at-javascript-need-something-to-read-the-php-equiv-of-_get-args/#findComment-749465 Share on other sites More sharing options...
RichardRotterdam Posted January 29, 2009 Share Posted January 29, 2009 If you can't use php(or any other serverside language) the function Mchl posted is the way to go. How ever if you can use a combination of php and javascript it would look like the following <script> var getValue=<?php echo $_GET['lang'] ;?>; </script> Quote Link to comment https://forums.phpfreaks.com/topic/142940-solved-i-suck-at-javascript-need-something-to-read-the-php-equiv-of-_get-args/#findComment-749500 Share on other sites More sharing options...
BioBob Posted January 29, 2009 Author Share Posted January 29, 2009 Ok I formatted my CD rom but it didnt have any cd's in it, now what? I already had php doing form validation, I just wanted to make the form a little more user friendly by showing the user I was going to force a default option, and instead of resubmitting the form and providing an ugly error msg, to do it on the fly. Basically 3 languages using check boxes, not radio buttons or drop down menus (I know I can set a drop down to allow to select multiple languages but half of the time people are too stupid to know what a drop down menu is or they can select multiple items, so I have to resort to the checkbox. Essencially, of the 3 language boxes, if they are all unchecked, the default language one will recheck itself now with onblur event. I think DJ Kat had a better answer for me. Thx. $lang = if ( (isset($_GET['lang'])) && (is_valid_lang($_GET['lang'])) ) ? $_GET['lang'] : 'en'; //is_valid_lang is defined elsewhere, just an htmlspecialchars($var,ENT_NOQUOTES,return_charset() //and in_array(array(valid_langs)) echo "function check_lang() { ( (!document.form.en.checked) && (!document.form.fr.checked) && (!document.form.es.checked) ) { document.form.$lang.click(); //if all boxes are empty, recheck the default box from $_GET['lang'] } }\n"; //--> HTML <input name="en" type="checkbox" onblur="check_lang()">English? <input name="fr" type="checkbox" onblur="check_lang()">French? <input name="es" type="checkbox" onblur="check_lang()">¿Spanish? Quote Link to comment https://forums.phpfreaks.com/topic/142940-solved-i-suck-at-javascript-need-something-to-read-the-php-equiv-of-_get-args/#findComment-749535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.