Click here to Skip to main content
14,693,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,
I have one label and button. when i click button, i need display button value into label    
in same page without page reload in php


What I have tried:

$(function (){
$(".1234").click(function() {
$(".123").toggle();
var CID = $(this).val();

$.ajax({
type: "POST",
url: "php/test.php",
 
data:{C_ID:CID},
 success: function(data){
 alert(data);
});
});
});
 
in test.php;
$id = $_REQUEST["C_ID"];
 
but i can't get the button value 
Posted
Updated 24-Nov-19 20:38pm

Why do you want to make a round trip to the server just to copy the button value to a label on the same page, can't you just do it with JavaScript or jQuery?
However,, if you insist:
This
success: function(data){
alert(data);
is missing a closing
}

I wonder why this
$(".123").toggle();
for?
You did not show your html code, make sure you button look similar to this:
<button class="1234" value="The button value that you want">click me</button>
In the test.php,
<?php
	if (isset($_REQUEST["C_ID"]))
   		echo $_REQUEST["C_ID"];
?>

Last but not least, you can achieve the same objective using just jQuery:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
	
  $(".1234").click(function() {
	  
	  $('label').html($(this).val());

  })
	
})

</script>
</head>

<body>

<label></label>
<button class="1234" value="Hello, Button!">click me</button>

</body>
</html>
   
v2
Comments
Nataraj Pandiyan 10-Feb-17 11:57am
   
Tthank you Peter Leow,but how to get that label value in php?
Peter Leow 10-Feb-17 19:57pm
   
similar to sending the button value to the server, but this time use text() to get the value in jQuery first before Ajaxing. http://www.w3schools.com/jquery/html_text.asp
If seems that you are familiar with jQuery and PHP, then google and learn.
$.ajax({
type: 'post',
dataType: 'json',
data: {id: testId},//Pass the id
});



`if(isset($_POST['id']) ){
$te = $_POST['id'];
echo $te;
}

else
{

echo $te;

}
   
Comments
CHill60 25-Nov-19 6:42am
   
An unformatted, unexplained code dump is not a solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900