Page 1 of 1

Select drop down box value

Posted: Wed Jun 16, 2010 2:29 am
by tomnoble
Hi all,

I need a piece of PHP code to do the following:

Make a value in a drop down box, the selected value.

E.G DropDownBox1.selectedvalue = "EU"

Where EU is a value already set in the dropdown box. This is a piece of code I use in VB.

Kind Regards

Tom Noble

Re: Select drop down box value

Posted: Wed Jun 16, 2010 2:40 am
by aravona
You can easily use a HTML form with a select/option set up:

[text]<select name="box">
<option>one</option>
<option>two</option>
</select>[/text]

Then you post your form to whatever page you're sending it to and use something like $value = $_POST['box'];

I'm assuming thats what you meant ^^?

Re: Select drop down box value

Posted: Wed Jun 16, 2010 3:07 am
by tomnoble
Sorry, I think I need to give further explanation. I am writing a module for Drupal which is running a block. The following code is already running:

Code: Select all

<?php

//Return the string after the domain name e.g /home
$currentpage = $_SERVER['REQUEST_URI'];

if (stripos($currentpage, "/Catalog/") !== false)
{

// set up a switch and set the currency value appropriately

switch ($currentpage) {

case stripos($currentpage, "/catalog/UK");
//Set the currency value
break;

case stripos($currentpage, "/catalog/EU");
//Set the currency value
break;

case stripos($currentpage, "/catalog/NonEU");
//Set the currency value
break;

case stripos($currentpage, "/catalog/US");
//Set the currency value
break;

case stripos($currentpage, "/catalog/ROTW");
Echo $currentpage;
break;
   }
}
?>
When the block is made, a drop down box is made. When the selected value of the drop down box is changed some JS runs.

E.g
Drop down box values:
  • EU
    UK
    US

Current Selected: US
User clicks on drop down and selects UK: JS is run.

I need some PHP code to go in the procedure posted above. So when it hits the case statement, it changes the selected value of the drop down box, so then the module automatically runs the JS for me. Does this make sense? I realise its a very loose description.

A working flow would be:

URL is changed
If statement becomes true
case statment match found
selected value changed
end case statement
If statement is not true, end
Selected value changed "onchange"
Run JS

Kind Regards

Tom Noble

Re: Select drop down box value

Posted: Wed Jun 16, 2010 3:16 am
by aravona
You should of clarified to begin with ^^ I know nothing of Drupal, I either us WP or start from scratch, sorry mate, can't help you.

Re: Select drop down box value

Posted: Wed Jun 16, 2010 4:47 am
by tomnoble
The code I am writing is just being made for a Drupal module. The actually code is just normal PHP code.

Thankyou for your help so far.

Kind Regards

Tom