Bitcoin Forum
May 07, 2024, 09:28:26 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: div value to jquery or php variable  (Read 1976 times)
spy100 (OP)
Sr. Member
****
Offline Offline

Activity: 658
Merit: 257


View Profile WWW
February 26, 2016, 09:28:29 AM
 #1

In my js file i have this:

var updateInterval = setInterval(function() {
 $('#thealert').load('alertprice.php');
},1*1000);

In my php file i SELECT the latest price from MYSQL database for example 453.33

In html it shows at time 14:00:01 :

<div id="thealert">453.33</div>

Then at time 14:00:02 :

<div id="thealert">463.33</div>

How do i get the updated value in a jquery or php variable so i can use it for an alert script ?

I want always to have in variable:

$latestprice = "463.33";

Or what ever latest price is at current time.

I want to store the updated value inside the div in a php variable or jquery or javascript variable to be used by other scripts ,if div value changes then $latestprice should change also.

Update:$latestprice needs to go in here:

   <script>
    $(document).ready(function(){



    $( "#myHigh" ).keyup(function(e) {

    var key = e.which || e.keyCode;

    if ( key == Cool{}else{


    nHigh = $( "#myHigh" ).val();
    $('#myHigh').append(nHigh);

    if (nHigh <= <?php echo $latestprice; ?> ) {
    document.getElementById('play').play();
    }else
    {
    document.getElementById('play').pause();
                return false;
    }}
    });


    $( "#myLow" ).keyup(function() {
    nLow = $( "#myLow" ).val();
    if (nLow >= <?php echo $latestprice; ?>

) {
    document.getElementById('play').play();
    }else
    {
    document.getElementById('play').pause();
    }
    })


    $( '#cleara' ).click(function() {
            $('input:text').val('');
        });






    });
    </script>


1715117306
Hero Member
*
Offline Offline

Posts: 1715117306

View Profile Personal Message (Offline)

Ignore
1715117306
Reply with quote  #2

1715117306
Report to moderator
1715117306
Hero Member
*
Offline Offline

Posts: 1715117306

View Profile Personal Message (Offline)

Ignore
1715117306
Reply with quote  #2

1715117306
Report to moderator
1715117306
Hero Member
*
Offline Offline

Posts: 1715117306

View Profile Personal Message (Offline)

Ignore
1715117306
Reply with quote  #2

1715117306
Report to moderator
Even in the event that an attacker gains more than 50% of the network's computational power, only transactions sent by the attacker could be reversed or double-spent. The network would not be destroyed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715117306
Hero Member
*
Offline Offline

Posts: 1715117306

View Profile Personal Message (Offline)

Ignore
1715117306
Reply with quote  #2

1715117306
Report to moderator
Moloch
Hero Member
*****
Offline Offline

Activity: 798
Merit: 722



View Profile
February 26, 2016, 06:06:40 PM
 #2

Not quite sure I follow...

If you have the number in php, you can send it to javascript like this:
Code:
<script>
var latestPrice = <?php echo $latestPrice?>;
</script>

But, this would only run when the page first loads... if you are updating via $.ajax() or curl(), I would send a callback function to update the variable with the response data



If you are trying to update a div using jquery, I use something like:

Code:
$('#latestPrice').change(function() {
  $("#latestPriceDisplay").html($(this).val());
});
spy100 (OP)
Sr. Member
****
Offline Offline

Activity: 658
Merit: 257


View Profile WWW
February 28, 2016, 05:39:32 AM
 #3

Not quite sure I follow...

If you have the number in php, you can send it to javascript like this:
Code:
<script>
var latestPrice = <?php echo $latestPrice?>;
</script>

But, this would only run when the page first loads... if you are updating via $.ajax() or curl(), I would send a callback function to update the variable with the response data



If you are trying to update a div using jquery, I use something like:

Code:
$('#latestPrice').change(function() {
  $("#latestPriceDisplay").html($(this).val());
});


Problem is that my div or variable is updating when price changes  and when you do this

var latestPrice = <?php echo $latestPrice; ?>;

you will not get updated price until page refresh.I want the variable to update with price change without refresh

benATstib
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile WWW
March 02, 2016, 08:49:36 PM
 #4

Edit for a better title and we will get more responses!
spy100 (OP)
Sr. Member
****
Offline Offline

Activity: 658
Merit: 257


View Profile WWW
March 05, 2016, 06:23:06 PM
 #5

up

music8mycomputer
Newbie
*
Offline Offline

Activity: 51
Merit: 0


View Profile WWW
March 05, 2016, 07:01:21 PM
Last edit: March 05, 2016, 07:12:32 PM by music8mycomputer
 #6

Not sure if this will help but this is how I get a changing php value into javascript.

Code:
<script>
function latestprice() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("thealert").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "alertprice.php?random=" + Math.random(), true); // random for IE
xhttp.send();

setTimeout(latestprice, 2500);
  
}
latestprice();
</script>


<div id="thealert">453.33</div>


<?php // alertprice.php

$resultmysqli_query($conn"SELECT price FROM latestprice");
while($row mysqli_fetch_array($result)){ 
$latest_price $row['price'];
}

echo 
$latest_price;



?>


And to get the div back into javascript

Code:
latestPrice = document.getElementById("thealert").innerHTML;

or

latestPrice = xhttp.responseText;
bitspill
Legendary
*
Offline Offline

Activity: 2058
Merit: 1015



View Profile
March 06, 2016, 11:13:42 AM
 #7

It looks like you've got pretty much what you need already however you are directly placing you're update into the div with jQuery instead of saving it.

Change
Code:
var updateInterval = setInterval(function() {
 $('#thealert').load('alertprice.php');
},1*1000);

To something like
Code:
var alertPriceVariable;
var updateInterval = setInterval(function() {
$.get( "alertprice.php")
  .done(function( data ) {
    alertPriceVariable = data;
   $('#thealert').text(alertPriceVariable);
  });
},1*1000);

{ BitSpill }
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!