0

I'm trying to retrieve a value from the mysql db to be posted to a textbox on the admin panel.

I have everything working and connecting and returning the correct values. When I step through the debugger, I see the values being assigned to the correct variables etc.

Problem I'm experiencing however, is that the values I retrieve, seem to disappear from the textbox after the function has finished processing.

phtml code:

function valChecker()
{

  var val = document.getElementById("test_attrib").value;

var url = '<? echo Mage::helper('adminhtml')->getUrl('machines/index/death'); ?>';

var response = "";

 new Ajax.Request(url, {
                    parameters:{test_attrib:val},
                onSuccess: function(transport){ 

        response = transport.responseText;
        document.getElementById("test_attrib").value = response;

                },
                  onFailure:  function(failer){
                  }
             });

}

if anyone would be so kind to assist please?

3
  • What is the value of retval? Apr 5 '16 at 10:02
  • @ Jayesh Patel, my bad, typo
    – u_jansen
    Apr 5 '16 at 10:14
  • Not an issue, see my answer and let me know if its fix the issue or not. Apr 5 '16 at 10:16
0

Try to set textbox value on AJAX onSuccess callback. Please find revised code as below:

var url = '<?echo Mage::helper('adminhtml')>getUrl('machines/index/death');?>'; 

var response = "";

new Ajax.Request(url, {
    parameters:{test_attrib:val},
    onSuccess: function(transport){ 
        response = transport.responseText;
        document.getElementById("test_attrib").value = response;
    },
    onFailure:  function(failer){
    }
});

It should worked.

6
  • okay, I made those changes, still the same. Values retrieved from the ajax call and assigned to response variable do not show up in test_attrib textbox
    – u_jansen
    Apr 5 '16 at 10:30
  • Please add whole function code in your question Apr 5 '16 at 10:32
  • alright, i edited my initial post with the code of the entire function
    – u_jansen
    Apr 5 '16 at 10:41
  • I guess the issue is getElementbyId, it should be getElementById. See updated answer. Apr 5 '16 at 10:56
  • facepalm ofcourse! Guess it was just one of "those days" again
    – u_jansen
    Apr 5 '16 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.