bambie Posted January 9, 2008 Share Posted January 9, 2008 Hello - I have to start with the fact that I'm an absolute beginner with php but am familiar enough that I can find my way around it (at least, I think so). So here's the problem. I have a dropdown list in a form edit that will show the current selected value (after reading from the database). But if you select a different item, the value does not change. If the current item is 'Sponsor..' and I change the selection to 'None', when the page refreshes it will remain 'Sponsor..' So whatever your original choice was always comes back. Here are two pieces of code that seem to be controlling this dropdown: // build invoice system list function buildInvoiceSystem($value = 3) { if($value <= 0) { $value = 3; } $newHTML = "<select class=\"required\" name=\"InvoiceSystem\">\n"; $tmparray = array(1=>'Sponsor System', 2=>'Invoice System', 3=>'None'); foreach ($tmparray as $id => $system) { if($value == $id) { $newHTML = $newHTML . " <option value=\"$id\" selected>$system</option>\n"; } else { $newHTML = $newHTML . " <option value=\"$id\">$system</option>\n"; } } $newHTML = $newHTML . "</select>\n"; return $newHTML; } // get invoice type from id function IDtoInvoiceSystem($value = 3) { $tmparray = array(1=>'Sponsor System', 2=>'Invoice System', 3=>'None'); $newHTML = $tmparray[$value]; return $newHTML; } If anyone can point me in the right direction, I would greatly appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/85210-dropdown-list-selection-changed-but-not-handled-correctly/ Share on other sites More sharing options...
chronister Posted January 9, 2008 Share Posted January 9, 2008 <?php // build invoice system list function buildInvoiceSystem($value = 3) { if($value <= 0) { $value = 3; } $newHTML = "<select class=\"required\" name=\"InvoiceSystem\">\n"; $tmparray = array(1=>'Sponsor System', 2=>'Invoice System', 3=>'None'); foreach ($tmparray as $id => $system) { if($value == $id) { $newHTML = $newHTML . " <option value=\"$id\" selected>$system</option>\n"; } else { $newHTML = $newHTML . " <option value=\"$id\">$system</option>\n"; } } $newHTML = $newHTML . "</select>\n"; return $newHTML; } ?> You are setting $value equal to 3 no matter what gets chosen in this line buildInvoiceSystem($value = 3) { So no matter what you chose your setting this to none. set it to buildInvoiceSystem($value) { Start with that and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/85210-dropdown-list-selection-changed-but-not-handled-correctly/#findComment-434780 Share on other sites More sharing options...
bambie Posted January 9, 2008 Author Share Posted January 9, 2008 Thank you for the fast response. What you say makes sense. But it didn't change the outcome. I can change my selected item but the refresh will still give back the old item. I've included a print statement so I can see that the value still hasn't changed when it writes to the database. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/85210-dropdown-list-selection-changed-but-not-handled-correctly/#findComment-434831 Share on other sites More sharing options...
chronister Posted January 9, 2008 Share Posted January 9, 2008 I would echo out the $id and the $value and see if they match somewhere.... Can you give a URL so we can see it in action? Thanks, Nate Quote Link to comment https://forums.phpfreaks.com/topic/85210-dropdown-list-selection-changed-but-not-handled-correctly/#findComment-434927 Share on other sites More sharing options...
bambie Posted January 11, 2008 Author Share Posted January 11, 2008 Sorry for the delay -- this portion of the site is not public so I can not provide a URL. It seems to me that I'm missing some type of OnChange event? Thanks, Bambie Quote Link to comment https://forums.phpfreaks.com/topic/85210-dropdown-list-selection-changed-but-not-handled-correctly/#findComment-436395 Share on other sites More sharing options...
chronister Posted January 11, 2008 Share Posted January 11, 2008 There is no need for an onChange event unless your using Ajax to make this change. If your using a standard refresh type thing, then when the page loads the code should see that the 2 vars match and set selected="selected" for the proper one. Thats the only thing I can think of. Quote Link to comment https://forums.phpfreaks.com/topic/85210-dropdown-list-selection-changed-but-not-handled-correctly/#findComment-436519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.