www.webdeveloper.com
Results 1 to 6 of 6

Thread: javascript function calling from another php file

  1. #1
    Join Date
    May 2010
    Posts
    26

    javascript function calling from another php file

    i am building a website:
    i have the files index.php, contact.php, etc... in witch there is a main function that it's call in the template.php file...
    and at the end of these files a call the template.php to run the page

    in index.php i try to run this script
    PHP Code:
        <style type="text/css">
          .
    accordionItem h2 margin0font-size1.1empadding0.4emcolor#fff; background-color: #944; border-bottom: 1px solid #66d; }
          
    .accordionItem h2:hover cursorpointer; }
          .
    accordionItem div margin0padding1em 0.4embackground-color#eef; border-bottom: 1px solid #66d; }
          
    .accordionItem.hide h2 color#000; background-color: #88f; }
          
    .accordionItem.hide div displaynone; }
        </
    style>

        <
    script type="text/javascript">
        
    //<![CDATA[

        
    var accordionItems = new Array();

        function 
    init() {

          
    // Grab the accordion items from the page
          
    var divs document.getElementsByTagName'div' );
          for ( var 
    0divs.lengthi++ ) {
            if ( 
    divs[i].className == 'accordionItem' accordionItems.pushdivs[i] );
          }

          
    // Assign onclick events to the accordion item headings
          
    for ( var 0accordionItems.lengthi++ ) {
            var 
    h2 getFirstChildWithTagNameaccordionItems[i], 'H2' );
            
    h2.onclick toggleItemmm;
          }

          
    // Hide all accordion item bodies except the first
          
    for ( var 1accordionItems.lengthi++ ) {
            
    accordionItems[i].className 'accordionItem hide';
          }
        }

        function 
    toggleItemmm() {
          var 
    itemClass this.parentNode.className;

          
    // Hide all items
          
    for ( var 0accordionItems.lengthi++ ) {
            
    accordionItems[i].className 'accordionItem hide';
          }

          
    // Show this item if it was previously hidden
          
    if ( itemClass == 'accordionItem hide' ) {
            
    this.parentNode.className 'accordionItem';
          }
        }

        function 
    getFirstChildWithTagNameelementtagName ) {
          for ( var 
    0element.childNodes.lengthi++ ) {
            if ( 
    element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
          }
        }
        
         
    //]]>
        
    </script>




        <div class="accordionItem">
          <h2>How to use a JavaScript accordion</h2>
          <div>
            <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
          </div>
        </div>

        <div class="accordionItem">
          <h2>How to use a JavaScript accordion</h2>
          <div>
            <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
          </div>
        </div>

        <div class="accordionItem">
          <h2>How to use a JavaScript accordion</h2>
          <div>
            <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
          </div>
        </div> 
    and in template.php i call the init function like that:
    <body onLoad="init()">

    and the script doesnt work....
    if put the script in template.php and call in browser the template.php then it works...


    what is happening????

  2. #2
    Join Date
    Jul 2007
    Posts
    386
    Your explanation is rather vague. Can you post an example of how you load the templates? Do you use includes or something else?

  3. #3
    Join Date
    May 2010
    Posts
    26
    index.php:
    PHP Code:
    function main(){

    ....
        <
    style type="text/css">
          .
    accordionItem h2 margin0font-size1.1empadding0.4emcolor#fff; background-color: #944; border-bottom: 1px solid #66d; }
          
    .accordionItem h2:hover cursorpointer; }
          .
    accordionItem div margin0padding1em 0.4embackground-color#eef; border-bottom: 1px solid #66d; }
          
    .accordionItem.hide h2 color#000; background-color: #88f; }
          
    .accordionItem.hide div displaynone; }
        </
    style>

        <
    script type="text/javascript">
        
    //<![CDATA[

        
    var accordionItems = new Array();

        function 
    init() {

          
    // Grab the accordion items from the page
          
    var divs document.getElementsByTagName'div' );
          for ( var 
    0divs.lengthi++ ) {
            if ( 
    divs[i].className == 'accordionItem' accordionItems.pushdivs[i] );
          }

          
    // Assign onclick events to the accordion item headings
          
    for ( var 0accordionItems.lengthi++ ) {
            var 
    h2 getFirstChildWithTagNameaccordionItems[i], 'H2' );
            
    h2.onclick toggleItemmm;
          }

          
    // Hide all accordion item bodies except the first
          
    for ( var 1accordionItems.lengthi++ ) {
            
    accordionItems[i].className 'accordionItem hide';
          }
        }

        function 
    toggleItemmm() {
          var 
    itemClass this.parentNode.className;

          
    // Hide all items
          
    for ( var 0accordionItems.lengthi++ ) {
            
    accordionItems[i].className 'accordionItem hide';
          }

          
    // Show this item if it was previously hidden
          
    if ( itemClass == 'accordionItem hide' ) {
            
    this.parentNode.className 'accordionItem';
          }
        }

        function 
    getFirstChildWithTagNameelementtagName ) {
          for ( var 
    0element.childNodes.lengthi++ ) {
            if ( 
    element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
          }
        }
         
    //]]>
        
    </script>

      

        <div class="accordionItem">
          <h2>How to use a JavaScript accordion</h2>
          <div>
            <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
          </div>
        </div>

        <div class="accordionItem">
          <h2>How to use a JavaScript accordion</h2>
          <div>
            <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
          </div>
        </div>

        <div class="accordionItem">
          <h2>How to use a JavaScript accordion</h2>
          <div>
            <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
          </div>
        </div>

    }
    //at the and of the file i call:
    include_once"template.php"; 
    template.php is my main file where called all javascript-jquery functions and alla css files...looks like that:
    PHP Code:
    <html>
    <head>
    ...css...
    ...functions...
    </head>
    <body onLoad="init()">
    ...
    <?php main(); ?>
    ...
    </body>
    </html>
    is it better now??? nay help...i stack alla day in this...

  4. #4
    Join Date
    Jul 2007
    Posts
    386
    Everything should be working. Post the full HTML from the browser's source code please.

  5. #5
    Join Date
    May 2010
    Posts
    26
    the wierd is that if i put the code in the template.php file and run it from browser the script run...
    the code is:
    [PHP]
    <script language="JavaScript" src="details_j.js"></script>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function sb_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>

    <script language="JavaScript">
    function emailCheck (emailStr)
    {
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray=emailStr.match(emailPat);
    if (matchArray==null)
    {
    alert("Please verify Email Address (check @ and .'s)");
    document.form_sub.sbemail_id.select();
    document.form_sub.sbemail_id.focus();
    return(false);
    }
    var user=matchArray[1];
    var domain=matchArray[2];
    if (user.match(userPat)==null)
    {
    alert("Please Specify a valid username in Email Address!");
    return(false);
    }
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null)
    {
    // this is an IP address
    for (var i=1;i<=4;i++)
    {
    if (IPArray[i]>255)
    {
    alert("Destination IP address is invalid!");
    return(false);
    }
    }
    return(true);
    }
    var domainArray=domain.match(domainPat);
    if (domainArray==null)
    {
    alert("Please Specify a valid domain name!");
    return(false);
    }
    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)
    {
    alert("The address must end in a valid domain, or two letter country.");
    return(false);
    }
    if (len<2)
    {
    var errStr="This address is missing a hostname!";
    alert(errStr);
    return(false);
    }
    return true;
    }


    function validate_signup(){

    if(document.form_sub.sbemail_id.value==''){
    alert("Please Specify Email Address!");
    document.form_sub.sbemail_id.focus();
    return(false);
    }
    else if(document.form_sub.sbemail_id.value.match(/[&;<>]+/)){
    alert("Please remove Invalid characters from Email Address (e.g. & ; < >)");
    document.form_sub.sbemail_id.select();
    document.form_sub.sbemail_id.focus();
    return(false);
    }
    else{
    if(!document.form_sub.sbemail_id.value.match(/[a-zA-Z\.\@\d\_]/)) {
    alert('Please Specify a valid Email Address.');
    document.form_sub.sbemail_id.select();
    document.form_sub.sbemail_id.focus();
    return false;
    }
    if (!emailCheck (document.form_sub.sbemail_id.value) ){
    document.form_sub.sbemail_id.select();
    document.form_sub.sbemail_id.focus();
    return (false);
    }
    }
    return (true);
    }

    function validate_login(){

    if(document.form2.username.value==''){
    alert("Please Specify Username!");
    document.form2.username.focus();
    return(false);
    }
    if(document.form2.userpwd.value==''){
    alert("Please Specify Password!");
    document.form2.userpwd.focus();
    return(false);
    }
    return (true);
    }

    </script>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <head>
    <title>foodsociety</title>
    <meta name="description" content="Heart Internet Specialise in Domain Names, Domain Name Registration, Domain Name Hosting, Domain Name Search and Buy Domain Name" />
    <meta name="keywords" content="domain names, domain name registration, domain name hosting, domain name search, buy domain name" />

    <!-- Standar -->
    <link rel="stylesheet" type="text/css" media="screen" href="styles/jquery.tabs.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/main.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/header-nav.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/upload-nav.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/footer.css"/>

    <link rel="stylesheet" type="text/css" media="screen" href="styles/tooltip.min.css"/>
    <!-- Other -->
    <link rel="stylesheet" type="text/css" media="screen" href="styles/day-recipe.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/list.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/dropdown.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/button.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="styles/buttons.css"/>
    <!-- Custom -->






    <script type="text/javascript" src="javascript/scripts/jquery.js"></script>

    <!-- hide main advertisment -->
    <script type="text/javascript">
    $(document).ready(function(){
    $(".pane .delete").click(function(){
    $(this).parents(".pane").animate({ opacity: 'hide' }, "slow");
    });
    });
    </script>
    <!-- close hide main advertisment -->

    <!-- search downdrop -->
    <script type="text/javascript" src="javascript/scripts/dropdown.js"></script>
    <!-- end search downdrop -->

    <!-- INDEX -->
    <!-- end INDEX -->

    <!-- FAQ -->
    <!-- end FAQ -->

    <!-- login showhide -->
    <script type="text/javascript">
    $(document).ready(function(){

    $(".btn-slide").click(function(){
    $("#sidelogin").slideToggle("slow");
    $(this).toggleClass("active"); return false;
    });
    $(".btn-login").click(function(){
    $("#sidelogin").slideToggle("slow");
    $(this).toggleClass("active"); return false;
    });

    });
    </script>
    <!-- end login showhide -->





    <!-- nav reflection -->

    <script type="text/javascript" src="javascript/scripts/execute.js"></script>
    <!-- end nav reflection -->

    <!-- tooltip -->
    <script src="javascript/scripts/bubblepopup.js" type="text/javascript" ></script>
    <script type="text/javascript">
    $(function() {
    $('#slideshow').tabs({ fx: { opacity: 'toggle' } }).tabs({ fx: { opacity: 'toggle' }}).tabs('rotate',5000);
    $('a.popup').lightBox({fixedNavigation:true});
    $.fn.supersized.options = {
    startwidth: 1200,
    startheight: 619,
    vertical_center: 1,
    slideshow: 0
    };
    $('#supersize').supersized();
    });
    </script>
    <!-- end tooltip -->

    <!-- Tooltips -->
    <script type="text/javascript" src="javascript/scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript"> $j = jQuery.noConflict(); </script>
    <script type="text/javascript" src="javascript/scripts/tooltip/jquery.cluetip.min.js"></script>

    <script type="text/javascript" src="javascript/scripts/tooltip/toolTipOptions.js"></script>
    <!-- end Tooltips -->

    <!-- small accordion -->
    <script type="text/javascript" src="javascript/scripts/jquery.small.accordion.js"></script>
    <!-- endsmall accordion -->


    </head>
    <body onLoad="init()">




    <style type="text/css">
    .accordionItem h2 { margin: 0; font-size: 1.1em; padding: 0.4em; color: #fff; background-color: #944; border-bottom: 1px solid #66d; }
    .accordionItem h2:hover { cursor: pointer; }
    .accordionItem div { margin: 0; padding: 1em 0.4em; background-color: #eef; border-bottom: 1px solid #66d; }
    .accordionItem.hide h2 { color: #000; background-color: #88f; }
    .accordionItem.hide div { display: none; }
    </style>

    <script type="text/javascript">

    var accordionItems = new Array();

    function init() {

    // Grab the accordion items from the page
    var divs = document.getElementsByTagName( 'div' );
    for ( var i = 0; i < divs.length; i++ ) {
    if ( divs[i].className == 'accordionItem' ) accordionItems.push( divs[i] );
    }

    // Assign onclick events to the accordion item headings
    for ( var i = 0; i < accordionItems.length; i++ ) {
    var h2 = getFirstChildWithTagName( accordionItems[i], 'H2' );
    h2.onclick = toggleItemmm;
    }

    // Hide all accordion item bodies except the first
    for ( var i = 1; i < accordionItems.length; i++ ) {
    accordionItems[i].className = 'accordionItem hide';
    }
    }

    function toggleItemmm() {
    var itemClass = this.parentNode.className;

    // Hide all items
    for ( var i = 0; i < accordionItems.length; i++ ) {
    accordionItems[i].className = 'accordionItem hide';
    }

    // Show this item if it was previously hidden
    if ( itemClass == 'accordionItem hide' ) {
    this.parentNode.className = 'accordionItem';
    }
    }

    function getFirstChildWithTagName( element, tagName ) {
    for ( var i = 0; i < element.childNodes.length; i++ ) {
    if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
    }
    }


    </script>





    <div class="accordionItem">
    <h2>How to use a JavaScript accordion</h2>

    <div>
    <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
    </div>
    </div>

    <div class="accordionItem">
    <h2>How to use a JavaScript accordion</h2>
    <div>

    <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>
    </div>
    </div>

    <div class="accordionItem">
    <h2>How to use a JavaScript accordion</h2>
    <div>
    <p>Click an accordion item's heading to expand it. To collapse the item, click it again, or click another item heading.</p>

    </div>
    </div>

  6. #6
    Join Date
    Jul 2007
    Posts
    386
    ...

    I said the BROWSER'S SOURCE CODE as in the final parsed HTML, not the PHP source code.

    Edit your post above if you still can please.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles