Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Show file info at mouseover with Ajax and PHP
Old 08-09-2011, 05:04 AM Show file info at mouseover with Ajax and PHP
Novice Talker

Posts: 12
Name: Teodorescu Mihail
Location: Romania
Trades: 0
Hi
I have a list of files made by my PHP code
Code:
    if ($handle = opendir($director))   
    {
        $path="images/files/nou/";
        if(Files::is_empty_dir($director))
            {
                echo "<p>There are no script available.</p>";
            }
        else
            {
       while (false !== ($file = readdir($handle))) 
       {
             if ($file != "." && $file != "..")
                 {
            $size=Files::getSize($director."/".$file);
            $exts=Files::getExtension($file);
                    $filex = str_replace(".".$exts,"",$file);
                if(strlen($filex)>10)
                    {
                        $filex=substr($filex,0,6);
                    }
                    echo "<div class='file' title='".$file."'>".$filex."</div>";
There are functions defined in my own class "Files".
Good. I want that on mouseover to show file information with this code
Code:
    function getInfo($file)
            {
                $info="<div class='info_public'><table border=0 cellpadding=2><tr>";
                $info.="<td>File : </td><td>".$file."</td></tr>";
                $info.="<tr><td>Extension : </td><td>".Files::getExtension($file)."</td></tr>";
                $info.="<tr><td>Size : </td><td>".Files::getSize($file)."</td></tr>";
                
                return $info;
            }
I want to show info dynamically with JQuery. I wrote this
Code:
$(function() {
    $(".file").mouseover(function()
        {
            data=$(this).attr("title");
            alert(data);
        });
});
It alerts always first filename not what I mouseover. But if I quit to use mouseover JQuery function, the title appears correctly for each file in part. If I use mouseover function again, the selected value from title doesn't appear correctly, it shows first filename in alert no matter what file I crossed with mouse.

I called the alert function to see results before implementing $.ajax function to avoid bad responses.
What's the problem in my script ?

Thank you
Sonic3R is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-09-2011, 05:43 AM Re: Show file info at mouseover with Ajax and PHP
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
The javascript part looks correct to me. Do the files evan have different title values, if you view the source code?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-09-2011, 05:53 AM Re: Show file info at mouseover with Ajax and PHP
Novice Talker

Posts: 12
Name: Teodorescu Mihail
Location: Romania
Trades: 0
every file has own title there are no same title value. Yes , I saw source code from browser and every file has their title. If I quit mouseover or onmouseover or anything related to jquery,if I move the cursor over one file, no matter which, browser triggers the tooltip with correct filename.
I think the problem is from JQuery but I don't know why and where is the mistake. As you said, the code is good, works except JQuery title value.
Sonic3R is offline
Reply With Quote
View Public Profile
 
Old 08-09-2011, 06:30 AM Re: Show file info at mouseover with Ajax and PHP
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Could you supply a link to your page, so it can be seen in action?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-09-2011, 06:36 AM Re: Show file info at mouseover with Ajax and PHP
Novice Talker

Posts: 12
Name: Teodorescu Mihail
Location: Romania
Trades: 0
I solved
the correct JS code is :
Code:
$(".file").each(function()
    {
        $(this).mouseover(function()
        {
            var fis=$(this).attr("title");
        console.log(fis);
        alert(fis);
        });
        
    });
Sonic3R is offline
Reply With Quote
View Public Profile
 
Old 08-09-2011, 07:13 AM Re: Show file info at mouseover with Ajax and PHP
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by Sonic3R View Post
I solved
the correct JS code is :
Code:
$(".file").each(function()
    {
        $(this).mouseover(function()
        {
            var fis=$(this).attr("title");
        console.log(fis);
        alert(fis);
        });
        
    });
Yes, the each() function is an alternative. But the following should also work
Code:
$(".file").mouseover(function() {
   var fis = $(this).attr("title");
   console.log(fis);
   alert(fis);
});
But anyhow, it's good that you got it working!
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-09-2011, 10:41 AM Re: Show file info at mouseover with Ajax and PHP
Novice Talker

Posts: 12
Name: Teodorescu Mihail
Location: Romania
Trades: 0
Code:
$(".file").mouseover(function() {    var fis = $(this).attr("title");    console.log(fis);    alert(fis); });
This part doesn't work !

Because in HTML there are more than one div with class "file".
Each of div has different title value so I need to show correct filename depdending that title value.
If I wouldn't use each function, the alert will display first value. Why ? I don't know, this is strange.
Sonic3R is offline
Reply With Quote
View Public Profile
 
Old 08-10-2011, 04:43 AM Re: Show file info at mouseover with Ajax and PHP
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by Sonic3R View Post
Code:
$(".file").mouseover(function() {    var fis = $(this).attr("title");    console.log(fis);    alert(fis); });
This part doesn't work !

Because in HTML there are more than one div with class "file".
Each of div has different title value so I need to show correct filename depdending that title value.
If I wouldn't use each function, the alert will display first value. Why ? I don't know, this is strange.
In jQuery, if you use a class name for your selector ( like $(".file") ) it returns a list of all matching objects, not just the first one. You can see an example of this at the jQuery documentation, where they select "myClass" and add a red border to it. Both elements with that class gets the red border.
http://api.jquery.com/class-selector/

But again, if you got it working, thats great
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 08-10-2011, 05:04 AM Re: Show file info at mouseover with Ajax and PHP
Novice Talker

Posts: 12
Name: Teodorescu Mihail
Location: Romania
Trades: 0
I solved my problem with "each" JQuery function.
Thank you 4 suggestion lizciz
Sonic3R is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Show file info at mouseover with Ajax and PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31512 seconds with 12 queries