JQuery numbers of cell, calculate sum in PHP -


I am trying to send the number of each cell, and I calculate the sum in php. Then show results in the text input but it does not work. How can I do this?

This is my php code:

  & lt ;? Php if (isset ($ _POST ['keep'])) {$ sum1 = $ _POST ['sum1']; $ Sum2 = $ _POST ['sum2']; $ Sum3 = $ _POST ['sum3']; $ Resultado = $ sum1 + $ sum2 + $ sum3; Echo "Resultado:". '& Lt; Input type = "text" name = "resultado" value = "'. $ Resultado.'" & Gt; '; }? & Gt;   

Thank you in advance

I looked at your full code quickly and it appears that the form tags are unavailable. You need to include your code in the middle of the form tag. Which will execute a script

  & lt; Form action = "yourphpfile" method = "post" & gt; & Lt; / Form & gt;   

If you do not want to load a new page, then you need to use Ajax which is a bit more complex. More information about the form can be found here.

Edit the action script when it comes to clicking on any type of input button.

The second edit I saw in some older projects how I refreshed a page with Ajax which goes as follows.

  // This function will need to call a button click for example function login () {var sum1 = document.getElementById ("sum1"); var sum2 = document.getElementById ("sum2"); Var sum3 = document.getElementById ("sum3"); // If necessary, here are some additional refining depending on how the data gets. Sum1 = sum1.value; Sum2 = sum2.value; Sum3 = sum3.value; // Call functions below AZ (sum1, sum2, sum3); } // Javascript Call this function on a button click // or create an additional function that calls and loads the amount from the page. Function ajax (sum1, sum2, sum3) {var xml; Xml = setXML (xml); Xml.onreadystatechange = function () {if (xml.readyState == 4 & amp; amp; xml.status == 200} {document.getElementById (DIV will need to be retained here). WinnerHTML = xml.responseText;} Xml.open ("POST", URLTOYOURSCRIPT.php, true); xml.setRequestHeader ("content-type", "application / x-www form-urlencoded"); xml.send ("sum1 =" + sum1 + "& Sum2 =" + sum2 + "& sum3 =" + sum3 +);} Function setXML (xml) {if (window.XMLHttpRequest) {// code for IE7 +, Firefox, Chrome, Opera, Safari Xml = new XMLHttpRequest (); return xml;} Else {// code for IE6, IE5 xml = new ActiveXObject ("Microsoft.XMLHTTP"); return xml;}}   

and then Your php script will need the following.

  // Receives the amount from the postal data sent by the tax. $ Sum1 = $ _POST ["sum1"]; $ Sum2 = $ _POST ["sum2"]; $ Sum3 = $ _POST ["sum3"]; // countless numbers Check out some extra checks like this, to see if they are real numbers etc. If (is_numeric ($ sum1) & amp; Amp; Is_numeric ($ sum2) & amp; Amp; Is_numeric ($ sum3) {// yoga and resonates it on your current page. $ Totalsum = $ sum1 + $ sum2 + $ sum3; $ Totalsum echo;} and {resonant "you have not inserted numbers"}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -