Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mootools 1.1 - Help please for get element

Status
Not open for further replies.

lumoo

Technical User
Feb 18, 2009
3
BE
Hi all,
I'm trying to adapt an exsisting script.
It's a "live search" module for Joomla 1.5 and I'm trying to modify to use with Virtuemart (shopping cart component)

I've got most of it to work but just can't figure how to extract the element I need.
The script makes a url call to a search script which returns the formatted results. (works fine)
The results are "set" in a hidden div. (works fine)
They are in this format...

Code:
<div id="search_tmpdiv">
 <div id="vmMainPage">
 <h3>Search: foo</h3>
     <div id="productlist" style="width:100%; float:none;">
        <div style="margin-right: 5px; width:98%; float:left;" id="row_499a94c33a84d">
             <div class="browseProductContainer">
                  <h3 class="browseProductTitle">
                 <a title="food" href="/index2.php?page=shop.product_details&amp;product_id=3">food</a>
                 </h3>
            </div>
       </div>
     <br class="clr" />
        <div style="margin-right: 5px; width:98%; float:left;" id="row_499a94c33aa68">
             <div class="browseProductContainer">
                <h3 class="browseProductTitle"><a title="foot" href="/index2.php?page=shop.product_details&amp;product_id=4">foot</a>
               </h3>
           </div>
         </div>
    <br class="clr" />
         <div style="margin-right: 5px; width:98%; float:left;" id="row_499a94c33acaa">
            <div class="browseProductContainer">
                 <h3 class="browseProductTitle"><a title="fooz" href="/index2.php?page=shop.product_details&amp;product_id=5">fooz</a>
                 </h3>
            </div>
        </div>
     </div>
 </div>
 </div>

the resulting hidden div (#search_tmpdiv) is then parsed by the following code and the results "should" display..
but what ever I try I get the result_div but without the elements parsed, e.g.

Code:
<div>Results</div>
  <div class="ps_row_1">
        <h3>
       <a href=""></a>
         <h3/>
  </div>
<div class="ps_row_2">
       etc
</div>
<div class="ps_row_1">
       etc
</div>
</div>

The correct number of rows are returned for the appropriate results so the logic is working but no matter what I try it doesn't pick up the wanted elements.

The elements I need are the link e.g.
"/index2.php?page=shop.product_details&amp;product_id=4"
and the link text e.g.
"foot"
The script is as follows

Code:
result_div.addClass('ps_results');
       
        search_res = $$('#search_tmpdiv .browseProductContainer');
        if(search_res.length > 0) search_res.each(function(res) {
            x +=1;
            var res_data='';
            res_data=res.getChildren();
            if(res_data.length > 0){
                res_data.each(function(r) {
                    if(r.getTag() == "div"){
                        if(r.getChildren().length > 2){
                            var suri=r.getFirst().getNext().getProperty('href');
                            if(row == "ps_row_2") row = "ps_row_1";
                            else row = "ps_row_2";
                            var el = new Element('div', {'class': row });
                            var link = new Element('a').setProperty('href',suri).injectInside(el);
                            var name = new Element('h3').setHTML(r.getFirst().getNext().getText()).injectInside(link);
            el.inject(result_div);
                        }
                    }
                });

I assume my mistake s in the line "var suri=r.getFirst().getNext().getProperty('href');" ?

Any help gratefully accepted
Cheers,
Lumo
 
I'm guessing the error is here:

Code:
if(r.getTag() == "div"){

I'd have thought that since this would presumably return the DIVs:

Code:
$$('#search_tmpdiv .browseProductContainer');

then asking for the children of those DIVs:

Code:
res_data=res.getChildren();

would never return the DIVs themselves, so why then only go into your code if you're on a DIV?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top