To call the Value of the drop down box in function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toamanz
Forum Newbie
Posts: 3
Joined: Thu Jun 05, 2008 2:53 pm

To call the Value of the drop down box in function

Post by toamanz »

Guys,
I am having a tough time getting the value of this drop down box. Here is the drop down code i got..

<select size="1" name="DDList" id="DDList"
onChange="xajax_changeScrapAccess(this.options[this.options.selectedIndex].value)">
{$DD_options}

Where DD_options is as below
<option selected>friends</option>
<option>friends of friends</option>
<option>everyone</option>

Now here is the function

function changeScrapAccess($arg)
{

$access_mode = $arg['scrpr'];

if($access_mode=="everyone")
{
$access_mode = "EVERY";
}
}

I just want to get the value in $access_mode liek if the user select private, i should get the value private in access_mode variable?

Help will be much appreciated

Thanks
Aman
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: To call the Value of the drop down box in function

Post by [UW] Jake »

To do that traditionally, you must submit a form to pass it to a php script. To do it "on the fly", you'll need to utilize AJAX, which is a world in its own.

EDIT: Ugh I didn't realize you're already using ajax functions! Hehe sorry if my reply doesn't help.
toamanz
Forum Newbie
Posts: 3
Joined: Thu Jun 05, 2008 2:53 pm

Re: To call the Value of the drop down box in function

Post by toamanz »

I am already using ajax...i just need the value once its been submittied through the form.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: To call the Value of the drop down box in function

Post by RobertGonzalez »

Can you please wrap your original posted code in bbCode tags? You can highlight the code then click on the CODE button that is just above the textarea.

Can't you just hit the $_POST array?
toamanz
Forum Newbie
Posts: 3
Joined: Thu Jun 05, 2008 2:53 pm

Re: To call the Value of the drop down box in function

Post by toamanz »

Code: Select all

<form method="post">
<select size="1" name="DDList" id="DDList" onChange="xajax_changeScrapAccess(this.options  [this.options.selectedIndex].value)">
 
   <option selected>friends</option>
   <option>friends of friends</option>
   <option>everyone</option>
 
/select>
 
<?
$xajax->registerFunction("changeScrapAccess");
 
function changeScrapAccess($arg)
{
    global $conn;
    global $profile_id, $profile_info;
    
    $access_mode = $arg['scrpr'];
    
    if($access_mode=="everyone")
    {
        $access_mode = "EVERY";
    }
    elseif($access_mode =="friends")
    {
        $access_mode = "FRIENDS";
    }
        elseif($access_mode=="friends of friends")
        {
            $access_mode = "NEXTFRIENDS";
        }
        else $access_mode = $access_mode;
    
    $UID = $_SESSION['UID'];
    
    $sql =  "INSERT INTO privacy SET security_scraps = '".$access_mode."', UID = '".$_SESSION['UID']."' ON DUPLICATE KEY UPDATE security_scraps= '".$access_mode."'";
    
    $objResponse = new xajaxResponse();
 
    if( $conn->Execute($sql) ) $objResponse->addAlert('Successfully changed!');
    else $objResponse->addAlert('Error happened');
            
    return $objResponse;
}
?>
Post Reply