www.webdeveloper.com
Results 1 to 3 of 3

Thread: function error: 'x' is null or not an object

  1. #1
    Join Date
    Dec 2008
    Posts
    1

    function error: 'x' is null or not an object

    I have a website i'm creating and i'm having a problem I click on say a category and it displays through javascript data from php and mysql. I click login into the admin account and go back to try to click on a category and it won't display anything and displays an error. 'x' is null or not an object. Why does it work once but not work after another function is called or in this case the admin function.

    <html>
    <head>
    <script language="javascript">
    function toggleBlock(elementId)
    {
    var element = document.getElementById(elementId);

    if (element.style.display == 'block')
    {
    element.style.display = 'none';
    }
    else
    {
    element.style.display = 'block';
    }
    }

    function show()
    {
    // find the paragraph with an ID of 'example1'
    x=document.getElementById('main_inner');

    //Make the innerHTML blank

    x.innerHTML="<html><head></head><body><?php $host="p3nl50mysql21.secureserver.net"; $user = "compbarnes";

    $pass = "Waterski1"; $db = "compbarnes"; $conn = mysql_connect($host, $user, $pass) or die("unable to connect");

    mysql_select_db($db) or die("unable to select database"); $sql="select * from appetizers"; $result = mysql_query

    ($sql); while ($row = mysql_fetch_array($result)) { echo "<font color=#4A7E33>".$row['title']."</font><br>From:

    ".$row['from']."<br><br><hr>"; } mysql_close($conn); ?></body></html>";
    }

    function admin()
    {
    var i = document.getElementById('u');
    var k = document.getElementById('p');
    w = document.getElementById('main');
    if (i.value == 'user' && k.value == 'pass')
    {
    w.innerHTML = 'Hello';
    }
    else
    {
    w.innerHTML = 'Access Denied';
    }

    }

    </script>
    <style type="text/css">


    table.menu a
    {
    width:165px;
    border:1px solid #333333;
    display: block;
    }

    div.menu a
    {
    color: #000000;
    background: #F6FEB5;
    text-decoration:none;
    font-size:11px;
    line-height:16px;
    padding: 2px 5px;
    font-family: Tahoma, verdana, sans-serif;
    }

    div.menu a:link
    {
    color: #333333;
    text-decoration: none;
    background: #cccc99;
    }

    div.menu a:active
    {
    color: #000000;
    text-decoration: none;
    background: #ffffff;
    }

    div.menu a:visited
    {
    color: #333333;
    text-decoration: none;
    background: #ffffff;
    }
    div.menu a:hover
    {
    color: #eeeeee;
    text-decoration: none;
    background: #333333;
    border:1px solid #000000;
    }

    a:link
    {
    color: #FFFFFF;
    text-decoration: none;
    }

    .header
    {
    display: block;
    height: 125px;
    width: 966px;
    border-bottom: solid 1px black;
    }

    .sidebar
    {
    text-indent: 20px;
    display: block;
    height: 400px;
    width: 170px;
    border-right: solid 1px black;
    filterrogidXImageTransform.Microsoft.Gradient
    (endColorstr='white', startColorstr='#568b3c', gradientType='1')
    }

    .heading
    {
    display: block;
    height: 25px;
    width: 170px;
    filterrogidXImageTransform.Microsoft.Gradient
    (endColorstr='black', startColorstr='#568b3c', gradientType='0')
    }

    #main
    {
    position: absolute;
    top: 133px;
    left: 201px;
    height: 400px;
    width: 766px;
    background-color: white;
    }

    #main_inner
    {
    position: absolute;
    top: 100px;
    left: 201px;
    height: 300px;
    width: 350px;
    background-color: white;
    }

    .navigation
    {
    display: block;
    height: 30px;
    width: 966px;
    border-top: solid 1px black;
    background-color: black;
    }

    .nav_continue
    {
    display: block;
    height: 2px;
    width: 966px;
    background-color: #79292A;
    }

    #admin
    {
    display: none;
    height: 100px;
    width: 170px;
    border-bottom: solid 1px black;
    }

    </style>
    </head>
    <body topmargin=0 leftmargin=0>
    <div class="header"><img src="food_banner.jpg"></div>
    <div class="sidebar">
    <div class="heading">
    <b><font color="white"><center><a href="#" onclick="toggleBlock('admin'); return

    false;">Administration</a></center></font></b>
    </div>
    <div id="admin">
    <form>
    <table>
    <tr>
    <td><b>Username:</b></td>
    </tr>
    <tr>
    <td><input type="text" id="u"></td>
    </tr>
    <tr>
    <td><b>Password:</b></td>
    </tr>
    <tr>
    <td><input type="password" id="p"></td>
    </tr>
    <tr>
    <td><input type="button" value="submit" onclick="javascript:admin()"><input type="reset" value="reset"></td>
    </tr>
    </table>
    </form
    <br>
    </div>
    <div class="heading">
    <center>
    <b>
    <font color="white"><a href="#" onclick="toggleBlock('menu'); return false;">Categories</a></font>
    </b></center></div>
    <div class="menu">
    <table summary="" cellpadding="1" cellspacing="1" class="menu" align="center" 1 width="100%">
    <tr>

    <td align="left"><br><a href="javascript:show()" onfocus="this.blur()"><b>APPETIZERS</b></a></td>
    </tr>
    <tr>
    <td align="left"><a href="javascript:show()" onfocus="this.blur()"><b>ENTREES</b></a></td>
    </tr>
    <tr>
    <td align="left"><a href="javascript:show()" onfocus="this.blur()"><b>BREADS</b></a></td>
    </tr>
    <tr>
    <td align="left"><a href="javascript:show()" onfocus="this.blur()"><b>MEATS</b></a></td>
    </tr>
    <tr>
    <td align="left"><a href="javascript:show()" onfocus="this.blur()"><b>PASTA</b></a></td>
    </tr>
    </table>
    </div>
    </div>
    <div id="main"><div id="main_inner"></div></div>
    <div class="navigation"></div>
    <div class="nav_continue"></div>
    </body>
    </html>

  2. #2
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    Well the one thing is you are creating really bad html since you should not have a head inside of a div. Why are you doing that?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  3. #3
    Join Date
    Dec 2008
    Posts
    79
    as A1ien51 said, remove <html><head>... tags
    don't expose username, password and host you are in a dangerous world
    instead of post php, post what php was supposed to "print", like:

    HTML Code:
    <font color=#4A7E33>Title</font><br>From: mail@domain.com<br><br><hr>
    I think the error ocurs because the script don't enter in the while ...

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