Call Javascript on condition

Discussion in 'PHP' started by vikaspa, Feb 12, 2011.

  1. #1
    Dear All

    Please help Help

    I have page for checkout ( shopping cart)
    When person leaves a page I have a javascript called
    which gives alert

    Are you sure you want to leave this page?
    OK and Cancel button


    Which works fine

    However I donot want this alert when shopping cart is empty
    or

    I want this alert only when the page is left with entries in shopping cart
     
    vikaspa, Feb 12, 2011 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    You will need to have a javascript variable which holds current cart status. Make it either 1 / 0 flag OR total number of items in cart OR whichever way you feel good.

    When user tries to leave off, check the variable status first and then decide whether exit popup to be displayed or not.
     
    mastermunj, Feb 12, 2011 IP
  3. vikaspa

    vikaspa Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    like to clarify more here

    When cart is not empty, I will make javascript variable say

    var cartempty=1

    I have javascript onunload="onul()" which is called when page leave

    In this function i need to check for cartempty variable value

    if cartempty =1 (display message)
    else
    no Message
     
    vikaspa, Feb 12, 2011 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Yes, that seems on track.
    Try implementing it and lets resolve difficulties you may face.
     
    mastermunj, Feb 12, 2011 IP