Jump to content

problems updating fields from within showhide tables


GrahamBoyd

Recommended Posts

I'm having a problem with checkbox data not updating from within javascript showhide tables. The data is incremented not updated.

 

I have multiple options and when the page content is edited, the new values are added but the old ones are still present in the db.

 

If I disable the showhide divisions then the data is updated correctly, but this is not an option as the page becomes very confusing for visitors.

 

Below is the javascript for the showhides - the tags for the showhide tables are - <div id="showhide1" style="display:none">

 

If anyone can help with this I'll be very grateful, as it has been driving me nuts for days and I've tried everything to make it work.

 

My site was created by a php programmer in Nepal who either can't or won't put it right. I know very little about php myself.

 

<script language=JavaScript>

function display(val)

{

if(val=='')

{

var value=frmeditpropertyadvert.property_type.options[frmeditpropertyadvert.property_type.options.selectedIndex].value;

alert(value);

}

if(val=='1' || val=='2' || val=='3' || val=='4' || val=='5' || val=='6')

  {

  document.getElementById('showhide1').style.display="block";

  document.getElementById('showhide3').style.display="block";

  }

  else

    {

document.getElementById('showhide1').style.display="none";

document.getElementById('showhide3').style.display="none";

  }

if(val=='7')

  {

  document.getElementById('showhide2').style.display="block";

  }

  else

  {

  document.getElementById('showhide2').style.display="none";

  }

if(val=='8')

  {

  document.getElementById('showhide2b').style.display="block";

  }

  else

  {

  document.getElementById('showhide2b').style.display="none";

  }

if(val=='7' || val=='8')

  {

  document.getElementById('showhide4').style.display="block";

  }

  else

    {

  document.getElementById('showhide4').style.display="none";

  }

}

</script>

Link to comment
Share on other sites

I should add that the data is sent to the db via php and mySql.

 

The site offers people the ability to upload their own 'property for sale' adverts and then to edit them if they require.

 

The edit page is a clone of the upload page, with the exception that the edit page calls the data from the db into the relevant fields. This all works perfectly, except for deleting discarded data fields via the edit page.

 

Both pages have the same showhides, etc.

Link to comment
Share on other sites

Hello Graham, is the problem that:

a) checkboxes that are not visible on the page are still submitting data to the db

 

or

 

b) unselecting checkboxes does not unselect them in the db

 

?

 

Just to warn you: either way, I think you'll probably end up having to edit the php...

Link to comment
Share on other sites

Well if it's (b) you'll need to make some changes to the PHP code that submits the property to the database.

 

When I submit data from checkboxes to a db, I usually clear all the db fields that store the checkbox first and then resubmit everything. How and what you'll need to clear will depend on your PHP code so I can't help you right off I'm afraid.

 

You could try submitting the code to the forum, but if you're not experienced in PHP you will need to be very careful not to submit any sensitive data such as passwords within the code... You might be better off getting a professional to have a look?

 

 

 

Link to comment
Share on other sites

Thank you for your input jggretton,

 

After looking through all of the code from lots of well-designed php sites I came up with the following:

 

I broke the edit_property_advert_details.php page down into three separate pages, got rid of the showhide code and used -

 

<? if(($propertytype=="1") || (propertytype=='2') || (propertytype=='3') ||(propertytype=='4') || (propertytype=='5') || (propertytype=='6')) include "./edit_building_advert_details.php"; else {include "./edit_land_advert_details.php";}

 

?>

 

I don't know if this is good php code, but it appears to work and updates the fields .... I'm almost excited that I got something to work for a change.

 

Perhaps you might be able to refine it a little as I am clueless.

 

Link to comment
Share on other sites

  • 3 weeks later...

Problem solved without re-designing the page. Thanks to my friend Kai Schönefeld.

 

Perhaps this might be of use to someone else.

 

The problem lay in the fact that some of the checkboxes were duplicated inside two of the showhides, so the code was passing the value twice when checked and only once when unchecked.

 

When I removed the duplicates it works perfectly.

 

 

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.