Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2007, 10:51 AM   PM User | #1
murali1983
New Coder

 
Join Date: Oct 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
murali1983 has a little shameless behaviour in the past
how to search the given text in the particular <div> tag..

hi
my requirement is to search for the text available in the table, the table is inside the <div>, not in the entire web page.
<div>
<table>
</table>
</div>

how can i acheive this...

once the search result is found in the table..., i want the subsequent search for the same criteria to be made using a shortcut key..
ex:

i am having a text box for the search criteria...
and a search button to search the entered criteria...

first the user enters the search criteria in the text box and then clicks on the search button...., now if the search is found, then the particular text is highlighted....and i want to have a short cut key....after pressing that key...the subsequent search should be made...for the same given criteria...


thnx
murali
murali1983 is offline   Reply With Quote
Old 02-13-2007, 12:56 PM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
what is the DOM structure of your table? Is it relatively simple -- i.e.:

Code:
<table id="data">
    <tr>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio.</p>
        </td>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio.</p>
        </td>
    </tr>
    <tr>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio.</p>
        </td>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio.</p>
        </td>
    </tr>
</table>
where each <p> tag is uninterrupted by further child nodes (again, for example)....

Or is it more like this:

Code:
<table id="data">
    <tr>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. <b>Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum</b> sem non odio.</p>
        </td>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. <span style="color:red">Morbi auctor, sapien ut posuere porta, magna nisl tempus leo</span>, ut dictum ipsum sem non odio.</p>
        </td>
    </tr>
    <tr>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. <img src="picture.jpg" alt="a picture" /> Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio.</p>
        </td>
        <td>
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis suscipit ultricies tortor. <b><i>Morbi auctor, sapien ut posuere porta, magna nisl tempus leo, ut dictum ipsum sem non odio.</i></b></p>
        </td>
    </tr>
</table>
where each <p> tag is interrupted by further child nodes....

The latter version is much harder to traverse, either with the DOM or regular expressions, using Javascript (at least for me)...

With PHP, I could do this a lot easier, because the regex functions seem more powerful to me (regardless of the complexity of the table's DOM structure)....

Do you have to use all Javascript for this?..I think I might use some AJAX to to send the table's innerHTML to a PHP script, use some regex there (to create the text highlighting), and then send the innerHTML back to your javascript to be reinserted into the DOM...And keep doing that every time the shortcut key is pressed thereafter...
__________________
Regards, R.J.

Last edited by chump2877; 02-13-2007 at 12:59 PM..
chump2877 is offline   Reply With Quote
Old 02-13-2007, 01:37 PM   PM User | #3
murali1983
New Coder

 
Join Date: Oct 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
murali1983 has a little shameless behaviour in the past
here in my case the <p> tag is uninterrupted.

i am not very sure wheather i can use AJAX...,i should ask my TL n check...
can u give me the code to acheive this using ajax as u told.....
murali1983 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 08:37 PM.


Advertisement
Log in to turn off these ads.