I'm working on a "form" class that lets me add fields dynamically to it.
I have a addDropDownBoxTest method that creates a drop-down box as its name says it:
/**
* Adds a drop-down box to the current form
* @param string $elementId ID for the drop-down box
* @param string $label Label for the dp box
* @param Array $values
* @param Array $selected Selected values (Subset of $values)
* @param String $onChangeBehavior URL to forward the page to (i.e. 'users.php?id=' )
*/
public function addDropDownBoxTest($elementId, $label, $values, $selected = '', $onChangeBehavior = ''){ //...
}
I'm attaching a screenshot of my interface so you can understand it easier. When someone clicks on 'edit' the div with the red border is replaced by the contents of a php file (let's call it roles.php).
Inside roles.php I use the drop-down box to let the user view the "rights" of the roles and then click on ok. By clicking ok they will be changing the data on the DB, so I use the drop-down box so that they can navigate between "roles".
Everything works fine when I hard code the value of the variable to send to my js function, but I can't get it to read/know the value the user actually selected in the dd box.
I've tried different ways, but the following code is the one that I think is closest, except that ff's error console displays a "missing ) after argument list" error on the makerequest funciton.
This is what I have inside my addDropDownBoxTest method:
if(!empty($onChangeBehavior)){
// $tmp = 'onChange="makerequest(\'' . $onChangeBehavior . 7 . '\',\'details\');"'; //Works
$tmp = 'onChange="makerequest(\'' . $onChangeBehavior . '\'+document.role_edit.role_edit_team_id.options[selectedIndex].value' . '\',\'details\');"';
$this->html .= $tmp;
}
where role_edit = form's ID
role_edit_team_id = drop-down box's id
details = id of div to be replaced
Could anyone please help with this?
I will really appreciate it!