1

Here My script code

page 1 / index.php

$(document).ready(function(){
  $("#list").load("load_list.php");
  function reloadlist(){
     var total_list = $("#total").val();
     $.get('load_list.php', function(data){
        var values = $("input[name='total']", data).val();
        alert(values);
     });
  } setInterval(reloadlist, 3000);
})

<body>
  <div id="list"></div>
</body>

page 2 / load_list.php

[My query for get the total data]

<input type="hidden" name="total" id="total" value="<?=$total?>">

When i load that index page, and alert value will be undefined. how to get text field value from load_list.php

3 Answers 3

1

save the value in a cookie and retrive it in next page

Sign up to request clarification or add additional context in comments.

Comments

0

The element is at root level, and the contex selector uses find() internally, and that only works on descendants.

You can avoid any and all issues with elements being descendants or at root level by appending the content to another element, and then using find(), or you could use filter() directly

 $.get('load_list.php', function(data){
    var values =  $('<div />', {html: data}).find("input[name='total']").val();
    alert(values);
 });

Also, the element has an ID, and it would be more efficient to use that in the selector.

1 Comment

It's still undefined . . .
0

You're in kind of a bad situation since you're just reloading the list after 3 seconds even if the call failed. You should try to clean up the whole idea a bit.

function reloadList = setTimeout(function(){
  $.get('load_list.php', function(result){
    var value = $(data).filter('#total').val();
    alert(value);
    reloadList();
  });
}, 3000);

reloadList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.