1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How change value variable javascript

Discussion in 'JavaScript' started by floriano, Aug 30, 2015.

  1. #1
    I have this variables in file javascript:

    // when number 10 is changed in database with another number... number 10 must change and here ( column is: repeat_sec )
    var repSec = 10;
    // when number 30 is changed in database with another number... number 30 must change and here ( column is: duration_Ad )
    var duAd = 30;
    // when number 8 is changed in database with another number... number 8 must change and here ( column is: close_Button )
    var closeButt = 8;

    how this change value when is changed in database ?

    Can someone help me?
     
    floriano, Aug 30, 2015 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    What type of database? What server side language are you accessing the database with? How are you passing values TO the database. Do you need this realtime async, or just on page loads?

    Instead of hard declaring those values in your script, or worse dynamically loading / building the script, you should probably be pulling those values with AJAX using something like JSON. If you need 'realtime' updates that could involve getting into setting up websockets, or if you don't need it 100% instant you could use the more predictable "polling" method.

    Really you haven't told us enough to provide you an answer.
     
    deathshadow, Aug 30, 2015 IP
  3. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #3
    I use db mysql, server apache... I need async only page loads...
     
    floriano, Aug 30, 2015 IP
  4. ketting00

    ketting00 Well-Known Member

    Messages:
    772
    Likes Received:
    27
    Best Answers:
    3
    Trophy Points:
    128
    #4
    One way to find out is to declare global variable and see if it worked. Something like this:
    
    <script>
        var repSec
         , duAd
         , closeButt;
    
        repSec = "<?php echo $repSec; ?>";
        duAd = "<?php echo $duAd; ?>";
        closeButt = "<?php echo $closeButt; ?>";
    </script>
    
    Code (markup):
    Put it above a link to your JS files, make sure you don't declare local variable again in the JS file. And don't use async, it would load and execute JavaScript before your website finished loading PHP variables.

    I'm not sure if async attribute compatible with W3C standard.
     
    ketting00, Sep 6, 2015 IP
  5. tryclofus

    tryclofus Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    better use any javascript frameworks like angularjs etc
     
    tryclofus, Sep 7, 2015 IP