Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Is thr any way to run php script on click of javascript??

    Hey all

    I am not that much good in JS and J* kind of thigs ..
    help me out on this ..
    I am opening a Dhtmml poopup ,and it's having two buttons
    say YES and NO

    if user click on YES
    (mysql table) field say Yes should increse
    else if No
    (mysql table) field No should increse

    I hope understand the problem
    bascically on onclick I m using "window.open "
    a phpFile which is updating this all ..

    but I dont want to do this with window.open


    any help would be appreciated
    Thanks
    ayiamas

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Yes, use AJAX.

    Of you could just post to a hidden <iframe>. That's even simpler.

    Maybe something like this:

    Your DHTML popon DIV:
    Code:
    <div ...>
    <form action="recordAnswer.php" method="post" target="hiddenFrame">
    <input type="submit" name="answer" value="Yes"/>
    <input type="submit" name="answer" value="No"/>
    </form>
    </div>
    (Naturally, you can have other stuff in the <div>. But just so long as you have that minimal <form>.

    And then, at the bottom of your page perhaps, you add:
    Code:
    <iframe name="hiddenFrame" style="width: 100%; height: 200px; display: none;"></iframe>
    While you are DEBUGGING, you can change "display: none;" to "display: block;", so that you can see what your PHP page ("recordAnswer.php") is posting to the iframe. Makes it easy to fix problems. Then just change to "display: none;" when you are ready to go live.

    Your PHP page is of course very simple:
    Code:
    <?php
    if ( is_set($_REQUEST["answer"]) )
    {
        if ( $_REQUEST["answer"] == "Yes" ) {
            $sql = "UPDATE yourtable SET yes=yes+1";
        } else {
            $sql = "UPDATE yourtable SET no=no+1";
        }
        // for debugging purposes!!
        echo "SQL: " . $sql . "<br/>\n";
    
        ... execute the sql ...
    
    } else {
        // more debugging!
        echo "Got to answer page but with NO ANSWER chosen!<br>\n";
    }
    ?>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts
    oh thanks

    I will have to check what ur script is saying
    but got the answer
    whatI did , I just AGAIN open one more DHTML popup
    like this
    function YES()
    {
    var newWin1 = dhtmlwindow.open('email_friend', 'iframe', 'xxxx.php?yes', 'Coup On', 'width=0px,height=0px', "recal")
    window.print();
    parent.newWin.close() ;
    }

    THANKS A LOT

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    That works, but it's more obtrusive. The user sees the thing open briefly then go away.

    Note that dhtmlwindow.open(), when used with a URL like that, is *also* using an <iframe> to hold the results from the PHP page. So, really, it's completely equivalent.

    My answer is really doing the same thing, but without showing anything to the user.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts
    window.open("coupon_print_update.php?print1=1", "_self");
    window.print();
    parent.newWin.close() ;


    which is closing currnetly open DHTML


    all things are woring fine , except it is tkaing little time to close in mozilla

    any ideaa ??

    thanks

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Pull the same trick: Open into a *HIDDEN* <iframe> instead.

    Code:
    ...
    <a target="HiddenFrame" href="coupon_print_update.php?print1=1">print coupon</a>
    ...
    <iframe name="HiddenFrame" style="width: 100%; height: 300px; display: none;"></iframe>
    ...
    Again, that nice thing about this is that you can change "display: none;" to "display: block;" while you are developing it and see the PHP page appear in the <iframe>. Makes it easier to debug. Once it all works, change it back to "none" and the user sees nothing.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Dec 2009
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts
    gr8 work can we put ur code insode JAVASCRIPT .. not sure


    but I got the solution
    window.print();
    parent.newWin.close() ;
    window.open("coupon_print_update.php?print1=1", "_self");



    it is working fine on both browsers

  • #8
    New Coder
    Join Date
    Dec 2009
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I am opening DHTML popup and it is having two buttons print and "no"
    on click of print it increament the yess filed of the table
    close that DHTML popup
    ,
    print that page

    and same thing is happenig w/o printing with no buttons

    Thanks
    aayiamasa


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •