Jump to content

[SOLVED] I suck at javascript. Need something to read the php equiv of $_GET Args


Recommended Posts

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?

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>

Ok I formatted my CD rom but it didnt have any cd's in it, now what?  :P

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.