问题描述:

I have

<td>

<?php $var=$arrayD[ 'Structural Data Loaded']; echo "<a data-id='$id' class='StructuralDataLoaded'>" . $var . "<img id='$id' class='img' onclick='javascript:SelectStatus(id);' src='images/edit.png'></a>"; ?>

</td>

and

function SelectStatus(id) {

var idvalue=id;

console.log(idvalue); /* I can see the idvalue at console */

var SelectingStatus = $('#SelectingStatus');

SelectingStatus.dialog({

close: function(event, ui) {

},

modal: true,

title: 'id' ,

width: 600,

height: 'auto',

overlay: {

backgroundColor: '#000000',

opacity: 0.5

},

buttons: {

'Save' : function PostStructuralDataLoadedData(idvalue){

var data = $('#selected option:selected').val();

console.log(idvalue);/* I can not see the idvalue at console */

$(this).dialog('destroy');

var request = $.ajax({

url: "InsertData.php",

type: "POST",

data: {

id : idvalue,

data : data,

type : "StructuralDataLoladed"

},

dataType: "html"

});

request.done(function( ) {

location.reload();

});

request.fail(function( jqXHR, textStatus ) {

alert( "Request failed: " + textStatus );

});

},

'Return': function(){$(this).dialog('destroy');}

}

});// End AddDocument dialog

}

When clicking on the Save button and calling PostStructuralDataLoadedData function, I want to send datavalue to that function,I wrote console.log(datavalue) in the PostStructuralDataLoadedData function, but I do not see anything in the console. How can I send datavalue to PostStructuralDataLoadedData function?

网友答案:

I would suggest that instead of id try to send the control as parameter to your function as below:

onclick='javascript:SelectStatus(this)'

and in your function

function SelectStatus(ctrl) {

    var idvalue=$(ctrl).attr('id'); //get the id attribute
    console.log(idvalue); 
    ........
    ........
}
网友答案:

You need to pass the $id to onclick='javascript:SelectStatus($id); instead of id to onclick='javascript:SelectStatus(id);'

It should be -

<?php $var=$arrayD[ 'Structural Data Loaded']; echo "<a data-id='$id' class='StructuralDataLoaded'>" . $var . "<img  id='$id' class='img' onclick='javascript:SelectStatus('$id');' src='images/edit.png'></a>"; ?>
网友答案:

I found the soultion. So when I am calling PostStructuralDataLoadedData functionI shoudl cal it like:

       function PostStructuralDataLoadedData()

so have to remove idvalue.

相关阅读:
Top