Page 1 of 1

To call the Value of the drop down box in function

Posted: Thu Jun 05, 2008 2:58 pm
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

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

Posted: Thu Jun 05, 2008 4:59 pm
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.

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

Posted: Thu Jun 05, 2008 10:06 pm
by toamanz
I am already using ajax...i just need the value once its been submittied through the form.

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

Posted: Fri Jun 06, 2008 12:51 am
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?

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

Posted: Fri Jun 06, 2008 8:17 am
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;
}
?>