Alex Rivera | Logout

PHP: on select change, post form to self

Asked 2010-10-20T09:03:49.967
9

It's basically what the title says.. I have a form with a select control that I want to force the form to post back to self on change.

$bmsclientlist = $clientobj->getBMSClientList();

echo '<form name="changebmsid" method="post" action="' . $_SERVER['PHP_SELF'] . '"><select name="bmsid">';

foreach($bmsclientlist as $bmsclient) {
    $var = '';
    if($client['bmsid'] == $bmsclient['id']) {
        $var = ' selected="selected"';
    }
    echo '<option value="' . $bmsclient['id'] .'"'. $var .'>' .$bmsclient['clientname'] . '</option>';
}

echo '</select></form>';

$backupobj = new AdminBackup();

if(isset($_POST['bmsid']){
    $statusarray = $backupobj->getStatusTotalsbyId($_POST['bmsid']);
}else{
    $statusarray = $backupobj->getStatusTotals();
}

I know it's going to involve some javascript but I'm not too sure how to achieve this.

Any help most appreciated!

Thanks,

Jonesy

Edit
Report

1 Answer

8

a quick fix is this:

Add an onchange attribute to your selectlist

<select name="bmsid" onchange="javascript: form.submit();">
answered 2010-10-20T09:13:47.977

Your Answer