0

I am trying to pass the the td value to java script,from java script i post that value to the php page where it contains query.can any one guide me how to pass the td value to java script,i tried but i don't know how to pass this value .thanks

Below is my js code :

<script>

function myFunction() {

 // Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var mcc = document.getElementById("mcc").value;
var mnc = document.getElementById("mnc").value;
var url = "testpage2/config.php";
var vars = "mcc="+mcc+"&mnc="+mnc;
hr.open("POST", url, true);
hr.send(vars); 

        }
</script>

Html

<?php    
$sql = mysql_query("SELECT * FROM supplierprice ");   
    while($rows=mysql_fetch_array($sql))
{    
if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }           
echo '  <td class="edit region '.$rows["supp_price_id"].'">'.$rows["region"].'</td>
        <td class="edit country '.$rows["supp_price_id"].'">'.$rows["country"].'</td>
        <td class="edit networkname '.$rows["supp_price_id"].'">'.$rows["networkname"].'</td>
        <td id="mcc" class="edit mcc '.$rows["supp_price_id"].'">'.$rows["mcc"].'</td>   
        <td id="mnc" class="edit mnc '.$rows["supp_price_id"].'">'.$rows["mnc"].'</td>
        <td class="edit mnp '.$rows["supp_price_id"].'">'.$rows["mnp"].'</td>';           
    $ColumnNames = mysql_query("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'supplierprice' AND column_name NOT
IN ('supp_price_id','region', 'country', 'networkname', 'mcc', 'mnc', 'mnp'
)") or die("mysql error"); 
$columnArray=array();
$i=0;
while($rows1=mysql_fetch_array($ColumnNames))
{           
    $columnArray[]=$rows1[0];    
echo '<td  width="0px;" class="edit '.$columnArray[$i].' '.$rows["supp_price_id"].'">'.$rows[$columnArray[$i]].'</td>';   
        echo '<td><input type="button" onclick="myFunction()" value="" /></td>';        
                           $i++;
}
            echo '</tr>';
    }
            ?>

1 Answer 1

2

value is for input elements. For others(like td, th, div, span...) use innerHTML:

var mcc = document.getElementById("mcc").innerHTML;
var mnc = document.getElementById("mnc").innerHTML;
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the reply ,i tried but its not posting the mcc ans mnc to the config.php can you guide me pls and can you check the java script i think something wrong there
First of all check your dev tools(f12) network tab and check if the desired content was sent and the http code was *200*(request complete). If checks, try a print_r($_POST); on your php file and see if those vars has arrived.
thanks i checked the content not sent its shows 'Array ( )' can you guide me how to pass it i am new to javascript its very helpfull for me
Look at this. Reload you page, open dev tools(f12), open network tab and then start your ajax action. On that tab will appear a new item like is shown on the second image on the post. On the tab headers will appear your parameters, check if they're right. On tab response will appear the response(the print_r) content. If there was shown empty, then the parameters are no sent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.