views:

46

answers:

2

I have a page with a form with data filled by ajax post; on form page fields values are loaded correctly but I cannot get loaded value from a function inside the page; here is an example:

<input type="text" id="mela">
<div style="border:1px solid black; display:none" id="vv">aaa</div>

<script>
  alert($("#mela").val());
  if ($("#mela").val()) {
    $("#vv").show();
  }
</script>

The question is: how can I get "mela" value loaded?

+1  A: 

This happened to me once. I solved the problem by downgrading (or upgrading?) the JQuery. Why don't you give it a try as well?

William
Excuse me William what do you mean for downgrade or upgrade Jquery?
haltman
I simply called jquery in my form loaded page and all works correctly! thanks again William!
haltman
By downgrading, I meant if you are using jquery 1.4.2, try to use 1.4.1 instead. It seems that you have solved the problem anyway :)
William
@haltman: Indeed. You have to include jQuery….js in every page.
Marcel Korpel
@Marcel Korpel I'll add it but It will be interesting to understand why all other loaded page with code inside works without jquery included codeing mystery LOL thanks again! ciaoh
haltman
+1  A: 

If the value is loaded via AJAX, the safest way to ensure that the new value is accessible is to access it from within a callback for the AJAX request.

If you're using jQuery .load() method, it can accept a callback that executes when the request is complete.

$('someElement').load('/some/path', function() {
    alert($("#mela").val());
    if ($("#mela").val()) {
        $("#vv").show();
    }
});
patrick dw