We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8895
    • 76 Posts
    Hi again

    ive reached a big questionmark! huh
    ive just made 2 dropdowns that get filled dynamicly, yet i have several problems...
    1. it wont select the correct entry from the dropdown as "selected"
    2. when i select something from dropdown 1 - what is an easy way to update the other dropdown without having to post the form?
    3. later im also going to need a list of records where i should be able to select multiple records (using ctrl) - and these should get posted by the form somehow

    can anyone help me out plz?
    here’s the code sofar..

    if ($_POST)
    {
    
    // . . .
    
    }
    
    
    //----------------------------------------------------------------------------------------------------------------------
    //	Form
    //----------------------------------------------------------------------------------------------------------------------
    $form = '
    <form enctype="multipart/form-data" action="" method="post">
    	Media: <select name="media">';
    
    	$dbmedia = $modx->db->select("media_id, type_idfs, media_name", "media", "media_id >= 0 ORDER BY log DESC");
    	$media = $modx->db->makeArray($dbmedia);
    	$media_check = $modx->db->getRecordCount($dbmedia);
    	
    	if($media_check > 0)
    	{
    		$x = 0;
    		while($media_check > $x)
    		{
    			if ($media==$media[$x][media_name])
    			{
    				$sel = "SELECTED";
    			}
    			$form .= "<option value=".$media[$x][media_id]." ".$sel."> ".$media[$x][media_name]."</option>";
    			$sel = "";
    			$x++;
    		}
    	}
        else
    	{$msg = "<br /><b>Could not find any Media!</b>";}
    //======================================================================================================================
    $form .= '<br /> Type: <select name="type">';
    
    	$dbtype = $modx->db->select("type_id, type_name", "types", "type_id >= 0 ORDER BY type_id DESC");
    	$type = $modx->db->makeArray($dbtype);
    	$type_check = $modx->db->getRecordCount($dbtype);
    	
    	if($type_check > 0)
    	{
    		$x = 0;
    		while($type_check > $x)
    		{
    			if ($media[$x][type_idfs]==$type[$x][type_id])
    			{
    				$sel = "SELECTED";
    			}
    			$form .= "<option value=".$media[$x][type_id]." ".$sel."> ".$type[$x][type_name]."</option>";
    			$sel = "";
    			$x++;
    		}
    	}
        else
    	{$msg = "<br /><b>Could not find any Types!</b>";}
    //======================================================================================================================
    
    $form .= '	
    	<br />
    	<input type="submit" value="Update" />
    </form>';
    
    
    return $form.$msg; 
    


    thank you tons!