xwishmasterx Posted December 29, 2008 Share Posted December 29, 2008 Hello I have a very simple question. I need a button to change a single value in a table: How should the code look, if I want to change a value to 1 (without the database connection)? Quote Link to comment Share on other sites More sharing options...
UpcomingPhpDev Posted December 29, 2008 Share Posted December 29, 2008 I think you need Js for the way you wrote the question. Php would do it, But it would have to refresh the page Quote Link to comment Share on other sites More sharing options...
xwishmasterx Posted December 29, 2008 Author Share Posted December 29, 2008 refreshing the page will not be a problem. Quote Link to comment Share on other sites More sharing options...
Zane Posted December 29, 2008 Share Posted December 29, 2008 function changeCell(o, n) { o = document.getElementById(o) o.innerHTML = n; } </pre> <table> </table> <br><inut type="'button'" name="'change'" value="'Change" cell onclick="changeCell('2a', 'New Value')"></inu Quote Link to comment Share on other sites More sharing options...
xwishmasterx Posted December 29, 2008 Author Share Posted December 29, 2008 I mean changing the value of a mysql database table. A single cell value needs to be changed to 1 with the push of a button. I am a noob at php, but it can't be to hard....any ideas of a code? Quote Link to comment Share on other sites More sharing options...
Zane Posted December 29, 2008 Share Posted December 29, 2008 I would use AJAX myself, if of course you're going to have a lot of these buttons. function startAJAX() { try { xmlhttp = new XMLHttpRequest(); } catch(e) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } } return xmlhttp; } function action(x, target) { var ajax = startAJAX(); var url = "update.php?id=" + x; ajax.open('GET', url); ajax.onreadystatechange = function() { if(ajax.readyState == 4) { target.value= "1"; } } // ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajax.send(null); } then have update.php do your updating and return the update, based on $_GET['id'] then make your buttons 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.