GrahamBoyd Posted December 29, 2008 Share Posted December 29, 2008 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> Quote Link to comment Share on other sites More sharing options...
GrahamBoyd Posted December 29, 2008 Author Share Posted December 29, 2008 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. Quote Link to comment Share on other sites More sharing options...
jggretton Posted December 29, 2008 Share Posted December 29, 2008 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... Quote Link to comment Share on other sites More sharing options...
GrahamBoyd Posted December 29, 2008 Author Share Posted December 29, 2008 Hi jggretton, Thank you for your response. It is 'b' unselecting checkboxes does not unselect them in the db They are always visible unless the advertiser changes the property type - hmmm, I can see problems arising in that eventuality. Quote Link to comment Share on other sites More sharing options...
jggretton Posted December 29, 2008 Share Posted December 29, 2008 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? Quote Link to comment Share on other sites More sharing options...
GrahamBoyd Posted December 29, 2008 Author Share Posted December 29, 2008 Here is the page with all irrelevant stuff and paths to includes removed - most of it is visible from the site using 'view page source' anyway. Hope it helps [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
GrahamBoyd Posted December 30, 2008 Author Share Posted December 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
GrahamBoyd Posted January 14, 2009 Author Share Posted January 14, 2009 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. Quote Link to comment 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.