Jump to content

DropDown list selection changed but not handled correctly


bambie

Recommended Posts

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.

 

Link to comment
Share on other sites

<?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

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.