Get Field value from jQuery onLoad
Hi,
I'm trying to create a process in BonitaSoft that on one form load some data from a MySql database using an script on JQuery. I created a HTML Widget with the next code
<script>
$(document).ready(function (){
var param1 = $("#dfDispID").val();
$.ajax({
type: "POST",
url: "myUrl.php",
datatype: "text/html",
data: {
nTipoDispID: param2
},
success: function (retData) {
$("#dfField2").val(retData);
}
});
});
</script>
$(document).ready(function (){
var param1 = $("#dfDispID").val();
$.ajax({
type: "POST",
url: "myUrl.php",
datatype: "text/html",
data: {
nTipoDispID: param2
},
success: function (retData) {
$("#dfField2").val(retData);
}
});
});
</script>
It "should" get the form field "dfDispID" value and send it to myUrl.php and set the response into the field dfField2.value (plain text).
But.... it doesnt work.
I tried with an alert ($("#dfDispID").val();) on document load and i get a "undefined". I cant reach the field from Firefox
Note: My field has set in General > Options the HTML attribute id='dfINFO_TipoDispositivo'
Any help?
Thanks
No answers yet.
Comments
Hi,
at first there seems to be a couple of issues with your script.
$(document).ready(function (){
var dfDispID = $("#dfDispID").val();
$.ajax({
type: "POST",
url: "myUrl.php",
datatype: "text/html",
data: {
nTipoDispID: dfDispID
},
success: function (retData) {
$("#dfField2").val(retData);
}
});
});
</script>
I had some working examples of what you are trying to achieve. Might help. https://jsfiddle.net/jasdompa/1/
https://jsfiddle.net/jasdompa/2/Vincent
Sorry, i modified the script a bit cause it some variables was in spanish and i screwed it up a bit.
I find the solution while i was taking some screenshots to give more info of my problem. Inspecting a bit the code i found that my field is inside a iframe id="bonitaframe" and i cant reach it directly, need to use iframe.contents() to get it.
worked like a charm
Thanks!!!