Seach doesn't work!



  • Please fix the search function!



  • SeachFunctionNotFoundException



  • www.google.com

    Works fine for me.



  • @ICDeadPpl said:

    Please fix the search function!

    don't hit enter, physically click the "site" button and the search works. i think "enter" defaults to some other button/form on these pages.



  • Erm ... okay, let's try to resist the tempting "OMFG the whole page is a big form !". I guess it's why hiting enter yields strange results.

    But it doesn't work when using the button neither ( on FF and Safari ).  The problem is the following :

    (line 132) document.getElementById('wtf_sitesearch_q').value

     but on line 144 the element we look for was created this way :

    document.writeln('<input type="text" name="wtf_sitesearch_q" maxlength="255" size="15" />');

    I guess getElementById on IE fallbacks on name, but not Firefox.
     

    So we have two options :

     either document.writeln('<input type="text" name="wtf_sitesearch_q"  id="wtf_sitesearch_q" maxlength="255" size="15" />'); 

    or :

     document.getElementByName('wtf_sitesearch_q')[0].value

     but well, I won't go into whiny criticism, but this is only a mere workaround. This shouldn't be done like that and I hope the developer behind this code understands there are other ways, more compatible and even simpler. So, that's in his own interest to re-think that weird implementation.
     



  • I guess getElementById on IE fallbacks on name, but not Firefox.

    Correct.

    In fact, write a bunch of elements with the same id, and IE will give you a barebones* array with the id's name containing these elements!

    IE: Flaws To Features since '95

     

    *) an array that's not instanceof Array and only contains the length property. Just like the one returned by getElementsByTagName().


  • ♿ (Parody)

    @aikii said:

    So we have two options :

     either document.writeln('<input type="text" name="wtf_sitesearch_q"  id="wtf_sitesearch_q" maxlength="255" size="15" />'); 

    or :

     document.getElementByName('wtf_sitesearch_q')[0].value

     but well, I won't go into whiny criticism, but this is only a mere workaround. This shouldn't be done like that and I hope the developer behind this code understands there are other ways, more compatible and even simpler. So, that's in his own interest to re-think that weird implementation.
     

    This was my mistake -- thanks for pointing this out, I'll get it fixed (it worked in IE, obviously, and I must have forgotten to test searching in firefox).

    What is a better/simpler way to do this, keeping in mind that the entire header template (which is all that I want to edit) is already nested within a FORM?

    To my credit, you'll notice that on the WTF site (not forums), the FORM tag is used sparingly.



  • Well, I don't know which parts of the source I see comes from the header. But I think I understand your problem : the first and only child of <body> is a <form> which contains the rest of the page and you can't do anything about it. That's asking for problems indeed, because if you nest forms, any "submit" action goes to the top-level form unless you use javascript to catch the event and redispatch it in some other way. So, I understand the workaround used here : a new form is written outside the top-level form, which is done using document.write that appends a new form after the first form, and then submitting it.

     So, we witness a path that leads to quite many WTFes ;-) For sure, that's not the easiest way to do it in HTML ( who needs javascript for a search form ? ), but that's the easiest way to get it done by editing the fewest files in this forum software.

     Accordingly to get it working with only minor modifications, I guess the proposed changes in my previous post is all you need for the moment. You could even capture the "enter" keypress on the search input so it works as expected but that's almost a browser emulation for a simple thing that should not require any workaround. The true problem is that top-level form, and one day you should roll up your sleeves and get rid of it, that's your real enemy ;-)


Log in to reply