bhawin
bhawin

Reputation: 285

Events in javascript not working

<html>
<head>
    <link href="admin.css.css" rel="stylesheet" type="text/css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript" ></script>
    <script type="text/javascript">
    function hello(ele)
    {
        //alert(ele);
        $("#text"+ele.id).show();
        //alert(ele);
        $(ele.id).hide();
        if(typeof $(ele.id).addEventListener != 'undefined')
            {
                $(ele.id).addEventListener("keyup", printhello, false)
            }
        else if(typeof $(ele.id).attachEvent != 'undefined')
            {
                $(ele.id).attachEvent("onkeyup",printhello);
            }

        function printhello()
        {
            alert("hello");
        }
    }
</script>
</head>
<div class="content">
<?php
$conn = mysqli_connect("localhost","root","","fashion");
if(!$conn)
{
    die("connection not made ". mysqli_error($conn));
}
$query="select * from styles";
$result=mysqli_query($conn,$query);
if(mysqli_num_rows ($result)>0)
{
    $str="<table class='styles-table'><th>id</th><th>name</th><th>image</th>";
    while($dr=  mysqli_fetch_array($result))
    {
        $str .= "<tr><td>".$dr["id"]."</td><td><input type='textbox'     id='text".$dr["id"]."' style='display:none;' value='".$dr["name"]."' /><div ondblclick='hello(this)' style='border:solid 2px black;' id='".$dr["id"]."'>".$dr["name"]."</div></td><td>".$dr["image1"]."</td></tr>" ;
    }
}
echo($str);
?>
</div>
</html>

In the above code no event is working, and the jquery hide() event is working without even including jquery. i don't know the problem , please help!

Upvotes: 0

Views: 49

Answers (2)

Voonic
Voonic

Reputation: 4775

Its seems you change this

$(ele.id) to $('#'+ele.id)

Example

$('#'+ele.id).hide();  // and every where

Upvotes: 2

Liad Livnat
Liad Livnat

Reputation: 7475

I guess the element you bind them event are not on dom yet. please add

$(document).ready(function(){//place you events bind here});

Upvotes: 3

Related Questions