Reputation: 19307
There is a HTML element of type text
whose name is fiche_tache_ref. Inside a javascript
file (.js) outside of the page's folder I want to set its value according to the value of a listbox selected :
function changerNatureRefTache(nature_tache_id) { // nature_tache_id is from a listbox
var http_ajax = $('#http_ajax').val();
var html = $.ajax({
data: "nature_tache_id="+nature_tache_id ,
type: "POST",
url: http_ajax+"referentiel/AjaxTacheChangerNatureTache.php" ,
async: false
}).responseText;
// here I want to set the value of the field
}
Code of AjaxTacheChangerNatureTache.php is :
<?php
if (isset($_POST['nature_tache_id'])) {
define("ROOT_PATH", "../../");
require_once ROOT_PATH . 'config.inc.php';
require_once RP_MODELS . 'nature_tache.class.php';
$db = new DbConn();
$obj = new nature_tache($db->getInstance());
$ret = $obj->recupererNatureTache($_POST['nature_tache_id']);
$code = $ret['nat_code'];
echo $code;
}
?>
So how to set the value of the field using JQuery
?
Upvotes: 1
Views: 2076
Reputation: 2789
you'll get lots of the same answer to this question, because this is kind of the low hanging fruit in the jquery docs.
$("selector").val("new value");
but one tip I'll give you that will make your php a little cleaner is instead of defining a root path like this:
define("ROOT_PATH", "../../");
you can set an include path in an .htaccess file using the following code:
php_value include_path ".:/path/to/your/application"
and then you can require files relative to that path (i.e. require_once('config.inc.php')
as opposed to what your essentially doing, which is require_once('../../config.inc.php')
.
The .htaccess file should live in the main directory that holds your application.
Upvotes: 0
Reputation: 6996
Use the val()
function of Jquery
.
$('#IdOfTextbox').val("Some Text");
Upvotes: 1
Reputation: 8476
I dont get you correctly but something like this is used to set the value of input element in jquery:-
$("#elementid").val("myvalue");
Upvotes: 2
Reputation: 7905
Use the val()
function
$('#idofinput').val("text you want in the field");
Since you are using name you can do the following
$('input[name=fiche_tache_ref]').val("text you want in the field");
Since names are not necessarily unique be careful with using the name as a selector. I would generally advise using an id instead.
Upvotes: 4