Reputation: 21
Problem solved. Check working code on bottom.
first, sorry for my english. If possible pls rewrite my question.
I can not change input value with jquery from calling ajax page.
(jquery version http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js)
My main page is index.php and ajax page is ajax.php. I called ajax.php with
$.ajax(...
But after working ajax codes then input value didnt change on index.php.
here is index.php input code
<input name="guncel_fiyat" type="hidden" id="guncel_fiyat" value="old value">
here is index.php ajax calling code:
$.ajax(
{
type: "POST",
url: "../ajax.php",
data: post_edilecek_veri,
cache: false,
success: function(donen_veri)
{
some code here;
}
}
here is ajax.php code (i did try 3 different method but nothing change)
$(".guncel_fiyat").val("new value");
or
$("#guncel_fiyat").val("new value");
or
$(".guncel_fiyat input").val("new value");
after calling ajax then try get new value on index.php but only getting "old value" val.
var guncel_fiyat_degeri = $("#guncel_fiyat").val();
alert(guncel_fiyat);
HERE IS WORKING CODE
CALL_AJAX.HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function peyfunc()
{
"use strict";
var current_price = $("#current_price").val();
alert ("current_price="+current_price);
$.ajax(
{
url: "ajax_test.php",
cache: false,
success: function(html)
{
$("#display").html(html);
}
}
);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<input name="current_price" type="hidden" id="current_price" value="5">
<input type="button" name="button" id="button" value="Button" onclick="peyfunc()">
</form>
<div id="display"></div>
</body>
</html>
AJAX_TEST.PHP
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
test
<script type="text/javascript">
//alert("aaa");
$("#current_price").val("new value");
alert ($("#current_price").val());
</script>
Upvotes: 0
Views: 1707
Reputation: 21
HERE IS WORKING CODE
CALL_AJAX.HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function peyfunc()
{
"use strict";
var current_price = $("#current_price").val();
alert ("current_price="+current_price);
$.ajax(
{
url: "ajax_test.php",
cache: false,
success: function(html)
{
$("#display").html(html);
}
}
);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<input name="current_price" type="hidden" id="current_price" value="5">
<input type="button" name="button" id="button" value="Button" onclick="peyfunc()">
</form>
<div id="display"></div>
</body>
</html>
AJAX_TEST.PHP
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
test
<script type="text/javascript">
//alert("aaa");
$("#current_price").val("new value");
alert ($("#current_price").val());
</script>
Upvotes: 1