SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    at end of a successful php if statement call javascript function

    Can this be done guy?

    Below I have my php

    PHP Code:
    if($_FILES['logo']['name']=="") {
    copy("$src","$fname2");
    $q24=mysql_query("update category set category_Name='$name', category_metaTitle='$meta', category_Image='$fname2', category_Description='$desc1', category_Active='$active' where cat_Id=$sr") or die (mysql_error());
    $flag=1;
    $conf="Data Updated Successfully 1";
    } else {
    copy("$src","imgdata/category/$fname");
    $q24=mysql_query("update category set category_Name='$name', category_metaTitle='$meta', category_Image='imgdata/category/$fname', category_Description='$desc1' where cat_Id=$sr") or die (mysql_error());
    $flag=1;
    $conf="Data Updated Successfully 2";

    At the bottom of each I have a successful call, ($conf="Data Updated Successfully 1") but what I would like to do is call a javascript function instead of the script being called using a button as below.

    Code:
    <input type="button" onclick="javascript:cover();" value="fade now" />
    Can this be done

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $conf='<input type="button" onclick="javascript:cover();" value="fade now" />';
    echo 
    $conf
    This code will generate your required button after successful completion of code.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Susen,

    I cant test it at the moment, but will that code produce a button instead of what I want to do which is to call the function that that button would call when clicked.

    So basically, at the end of the script where I would call $conf="Data Updated Successfully 1", I wont it to call the javascript function instead of calling the javascript function by clicking the button.

    Thanks for getting back to me.

  4. #4
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the javascript Im talking about

    <script type="text/javascript">
    var vis=1;
    function cover()
    {
    var cover=document.getElementById('cover');
    if(vis)
    {
    vis=0;
    cover.style.display='block';
    }
    else
    {
    vis=1;
    cover.style.display='none';
    }
    }
    </script>

    And also what that does.

    <div id="cover">
    <div id="warning">
    <p align="center">
    <input type="button" onclick="javascript:cover();" value="I LIKE THIS PAGE" /> <input type="button" onclick="javascript:location.href=('http://www.#.com/');" value="I WANT TO SEE SOMETHING DIFFERENT" />
    </p>
    </div>
    </div>

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you already define the JavaScript functions in a separate js file. If so then you only need to call the function to run it. In such case use code,
    PHP Code:
    $conf='<script type="text/javascript">FunctionToRun();</script>';
    echo 
    $conf
    But if you want to load the function with the page load then you have to define the function also.
    The function cover() actually switch the visibility of the division ID 'cover' (and all of its child elements) from visible to non-visible state and vice versa.

  6. #6
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Susen,

    Your code looks fine to me, but cant seem to get the jscript function to run.

    I'm using below

    PHP Code:
    echo '<script type="text/javascript">cover();</script>'
    Which is referencing this function.

    Code:
    <script type="text/javascript">
    alert ("0");
    var vis=1;
    function cover()
    alert ("1");
    {  
    var cover=document.getElementById('cover');
    if(vis)
    {
    vis=0;
    cover.style.display='block'; 
    alert ("2");   
    } 
    else 
    {   
    vis=1;
    cover.style.display='none'; 
    alert ("3");
    }
    }
    </script>
    Which turns on this div to create a greyed out cover that sits over the page.

    Code:
    <div id="cover">
    <div id="warning">
    <p align="center">
    <input type="button" onClick="javascript:location.href=('http://www.accendsandbox.co.uk/adminSallam/admin_categories.php');" value="Return to admin" />
    </p>
    </div>
    </div>
    Cheers


Bookmarks

Posting Permissions

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