Robert Dickey
Robert Dickey

Reputation: 834

Turning a Javascript Object Value into a Global Variable

I have an object from FullCalender

events: [

                <?

                $sql =   "Query removed";

                 if ($result=mysqli_query($link,$sql))
                {
                    // Fetch one and one row
                    while ($row=mysqli_fetch_assoc($result))
                    {

                    echo "  {
                    title: '".$row['eName']."',
                    backgroundColor: 'green',
                    start: '".$row['scheduledDate']."',
                    eventID: '".$row['eID']."'

                }, " ;

                    }
                    // Free result set
                    mysqli_free_result($result);
                }
                ?>
            ],
            eventClick: function(event) {

                    $('#modifydialog').dialog('open');
                    $("#notes").val(event.eventID);
                    var eID = event.eventID;
            }

I am trying desperately to make an object (the event.eventID into a global variable so I can use it here:

   var eID = '';
// handles the click event for link 1, sends the query
function getOutput() {
    getRequest(
        'checkDelete.php?sID=<?echo $sID;?>&eID='+eID, // URL for the PHP file
        drawOutput,  // handle successful request
        drawError    // handle error
    );

Basically, I'm trying to take the value, and pop it into the ajax url for the get statement - I am open to suggestions if there are better ways. Thank you for any advice.

Upvotes: 1

Views: 50

Answers (1)

Titus
Titus

Reputation: 22474

I think you can use:

 'checkDelete.php?sID=<?echo $sID;?>&eID='+$("#notes").val()

that is if the value of this element won't be changed in the meantime. You can also declare eID in the global scope and use eID = event.eventID; to set it.

var eID;
events: [
          ....
        ],
        eventClick: function(event) {
                .....
                eID = event.eventID;
        }

you can even do this:

window.eID = event.eventID;

Upvotes: 4

Related Questions