tags:

views:

189

answers:

1

What really needs to happen here is.. A session takes my data from the drop down listed below. Its gonna take it to the process page then bring it back to this page with a header on the process page. Then when it gets back to the first page the dropdown will populate with the session or the same client as when I left that page and the on change of the drop down will work. Can anyone help me with this. Thank you Right now this returns the client to the drop down but the onchange for the drop down does not work which is what I really need to work.

session_start();


$current = isset($_SESSION['ClientNamefour']) ? $_SESSION['ClientNamefour'] : 0;


while ($row = mysql_fetch_array($result)) { 


    $id = $row["Client_Code"]; 
    $thing = $row["Client_Full_Name"];
    $value = "$id, $thing";


    $sel=($id==$current)?'SELECTED':'';

    $options4.="<OPTION $sel VALUE=\"$value\">".$thing;


} 


?>
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

<select name="ClientNamefour" onchange="this.form.submit()">

    <option value=0>Client
    <?php echo $options4?> 

  </select>
</form>

Process page header

session_start();
$_SESSION['ClientNamefour'] = $_POST['txtclientcode'];

// Do the redirect





// Do the redirect
header("Location: test.php");
exit();
+1  A: 

I don't know your question or problem but I just guess that it should be

$_SESSION['ClientNamefour'] = $_POST['ClientNamefour'];

instead of

$_SESSION['ClientNamefour'] = $_POST['txtclientcode'];

Also don't forget to put closing </option> tags into your code.

Of course you have to send the the form data to the process page, but

<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

looks like the data gets send back to the same page.

And never trust data submitted by the user.

Edit:

Try:

onChange="Javascript:document.forms[0].submit()"

or

onChange="Javascript:document.forms['form'].submit()"

But that is only what I found using Google.

Felix Kling
I have it returning the data to the dropdown but when it does the onchange event does not automatically go because the drop down is not changing. It is just selecting the last client.
Eric
how do i make it so the onchange does go?
Eric
@Eric: I updated my answer btw.
Felix Kling