Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:14:07+00:00 2026-06-04T07:14:07+00:00

To solve a tricky wiki search problem we’ve implemented a Javascript solution in a

  • 0

To solve a tricky wiki search problem we’ve implemented a Javascript solution in a PHP file.

Unfortunately, I have two problems. One is that the function is not being called and secondly I see a syntax error in the Error Console that I cannot solve. First, here is the code within the PHP file:

    $htmlOut .=  <<<ENDOFBLOCK
    <script language="javascript">
    function appendAndSubmit(){
    var platform1 = document.getElementById( 'p1').checked;
    var platform2 = document.getElementById( 'p2').checked;
    var text = document.getElementById('search').value;
    if (platform1) text = 'Applies to=Platform 1.0 ' + text;
    if (platform2) text = 'Applies to=Platform 2.0 ' + text;
    alert( text);
    document.getElementById('search').value = text;
    document.forms['searchform'].submit();}
    </script>
    ENDOFBLOCK
    ;

So, the first problem is that I see appendAndSubmit is not defined in the Error Console.

The second problem is the syntax error. The generated HTML source is:

<p><script language="javascript">
function appendAndSubmit(){
var platform1 = document.getElementById( 'p1').checked;
var platform2 = document.getElementById( 'p2').checked;
var text = document.getElementById('search').value;
if (platform1) text = 'Applies to=Platform 1.0 ' + text;
if (platform2) text = 'Applies to=Platform 2.0 ' + text;
alert( text);
document.getElementById('search').value = text;
document.forms['searchform'].submit();}
</p>
</script><div align="center" style="background-color:transparent"><form name="searchbox" id="searchbox" class="searchbox" action="/wiki/index.php?title=Special:Search"><input class="searchboxInput" name="search" type="text" value="" size="50" /><br /><input type="checkbox" name="1" value="&quot;Applies to=Platform 1.0&quot;" id="p1" />&nbsp;<label for="">Platform 1.0</label><input type="checkbox" name="2" value="&quot;Applies to=Platform 2.0&quot;" id="p2" />&nbsp;<label for="">Platform 2.0</label><br /><input type="submit" name="fulltext" class="searchboxSearchButton" value="Go!" onClick="appendAndSubmit();" /></div></form>

Note the </p> occurs before </script>, whereas <p> occurs before <script>.

Can anyone tell me please what I’m doing wrong?

The call to the appendAndSubmit function is here:

    $htmlOut .= Xml::element( 'input',
        array(
            'type' => 'submit',
            'name' => 'fulltext',
            'class' => 'searchboxSearchButton',
            'value' => 'Go!',
            'onClick' => 'appendAndSubmit();'
        )
    );

Complete method:

    public function getSearchPlatform() {

    // Use button label fallbacks
    global $wgContLang;

    // Use button label fallbacks
    if ( !$this->mButtonLabel ) {
        $this->mButtonLabel = wfMsgHtml( 'tryexact' );
    }
    if ( !$this->mSearchButtonLabel ) {
        $this->mSearchButtonLabel = wfMsgHtml( 'searchfulltext' );
    }

    $htmlOut .=  <<<ENDOFBLOCK
<script type="text/javascript">
function appendAndSubmit(){
var platform1 = document.getElementById( 'p1').checked;
var platform2 = document.getElementById( 'p2').checked;
var text = document.getElementById('search').value;
if (platform1) text = 'Applies to=Platform 3.0 ' + text;
if (platform2) text = 'Applies to=Platform 4.0 ' + text;
alert( text);
document.getElementById('search').value = text;
document.forms['searchform'].submit();}
</script>
ENDOFBLOCK
;

    // Build HTML
    $htmlOut .= Xml::openElement( 'div',
        array(
            'align' => 'center',
            'style' => 'background-color:' . $this->mBGColor
        )
    );
    $htmlOut .= Xml::openElement( 'form',
        array(
            'name' => 'searchbox',
            'id' => 'searchbox',
            'class' => 'searchbox',
            'action' => SpecialPage::getTitleFor( 'Search' )->escapeLocalUrl(),
        )
    );
    $htmlOut .= Xml::element( 'input',
        array(
            'class' => 'searchboxInput',
            'name' => 'search',
            'type' => 'text',
            'value' => $this->mDefaultText,
            'size' => $this->mWidth,
        )
    );

    $htmlOut .= $this->mBR;

    // Checkbox
    $htmlOut .= Xml::element( 'input',
        array(
            'type' => 'checkbox',
            'name' => '1',
            'value' => '"Applies to=Platform 1.0"',
            'id' => 'p1'
        )
    );
    // Label
    $htmlOut .= '&nbsp;' . Xml::label( 'Platform 2.0' );

    // Checkbox
    $htmlOut .= Xml::element( 'input',
        array(
            'type' => 'checkbox',
            'name' => '2',
            'value' => '"Applies to=Platform 2.0"',
            'id' => 'p2'
        )
    );
    // Label
    $htmlOut .= '&nbsp;' . Xml::label( 'Platform 2.0' );

    // Line break
    $htmlOut .= $this->mBR;

    $htmlOut .= Xml::element( 'input',
        array(
            'type' => 'submit',
            'name' => 'fulltext',
            'class' => 'searchboxSearchButton',
            'value' => 'Go!',
            'onClick' => 'appendAndSubmit();'
        )
    );

    // Hidden fulltext param for IE (bug 17161)
    if( $type == 'fulltext' ) {
        $htmlOut .= Xml::hidden( 'fulltext', 'Search' );
    }

    $htmlOut .= Xml::closeElement( 'div' );
    $htmlOut .= Xml::closeElement( 'form' );

    // Return HTML
    return $htmlOut;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:14:08+00:00Added an answer on June 4, 2026 at 7:14 am

    I managed to get rid of the </p> problem by putting everything between <script> and </script> on one line. This makes me wonder if it is a problem with the editor (Notepad++ on Windows) when I put the file on the Linux server. But I thought Notepad++ could handle that (it is no problem for PHP).

    The fact that the script was not being called was actually due to a syntax error, which I found out via a clue in another question: 'search' should have been 'searchbox'.

    Once that was resolved the function was called without errors.

    In case anyone else wants it, here is the complete working code:

        public function getSearchPlatform() {
    
            // Use button label fallbacks
            global $wgContLang;
    
            // Use button label fallbacks
            if ( !$this->mButtonLabel ) {
                $this->mButtonLabel = wfMsgHtml( 'tryexact' );
            }
            if ( !$this->mSearchButtonLabel ) {
                $this->mSearchButtonLabel = wfMsgHtml( 'searchfulltext' );
            }
    
            $htmlOut .=  <<<ENDOFBLOCK
            <script type="text/javascript">function appendAndSubmit(){var platform1 = document.getElementById('p1').checked;var platform2 = document.getElementById('p2').checked;var text = document.getElementById('searchboxInput').value;if (platform1 * platform2 >0) text = text + ' "Applies to=Platform 1.0" "Applies to=Platform 2.0"';else if (platform1) text = text + ' "Applies to=Platform 1.0"';else if (platform2) text = text + ' "Applies to=Platform 2.0"';document.getElementById('searchboxInput').value = text;document.forms['searchform'].submit();}</script>
    ENDOFBLOCK;
    
            // Build HTML
            $htmlOut .= Xml::openElement( 'div',
                array(
                    'align' => 'center',
                    'style' => 'background-color:' . $this->mBGColor
                )
            );
            $htmlOut .= Xml::openElement( 'form',
                array(
                    'name' => 'searchbox',
                    'id' => 'searchbox',
                    'class' => 'searchbox',
                    'action' => SpecialPage::getTitleFor( 'Search' )->escapeLocalUrl(),
                )
            );
            $htmlOut .= Xml::element( 'input',
                array(
                    'class' => 'searchboxInput',
                    'name' => 'search',
                    'id' => 'searchboxInput',
                    'type' => 'text',
                    'value' => $this->mDefaultText,
                    'size' => $this->mWidth,
                )
            );
    
            $htmlOut .= $this->mBR;
    
            // Checkbox
            $htmlOut .= Xml::element( 'input',
                array(
                    'type' => 'checkbox',
                    'name' => '1',
                    'id' => 'p1'
                )
            );
            // Label
            $htmlOut .= '&nbsp;' . Xml::label( 'Platform 1.0' );
    
            // Checkbox
            $htmlOut .= Xml::element( 'input',
                array(
                    'type' => 'checkbox',
                    'name' => '2',
                    'id' => 'p2'
                )
            );
            // Label
            $htmlOut .= '&nbsp;' . Xml::label( 'Platform 2.0' );
    
            // Line break
            $htmlOut .= $this->mBR;
    
            $htmlOut .= Xml::element( 'input',
                array(
                    'type' => 'submit',
                    'name' => 'fulltext',
                    'class' => 'searchboxSearchButton',
                    'value' => 'search',
                    'onClick' => "appendAndSubmit();"
                )
            );
    
            // Hidden fulltext param for IE (bug 17161)
            if( $type == 'fulltext' ) {
                $htmlOut .= Xml::hidden( 'fulltext', 'Search' );
            }
    
            $htmlOut .= Xml::closeElement( 'div' );
            $htmlOut .= Xml::closeElement( 'form' );
    
            // Return HTML
            return $htmlOut;
        }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sort of a tricky problem I'm attempting to solve. First of all,
I'm trying to solve a tricky problem in Google Maps (api V3) Works nicely:
I've got a slightly tricky problem to solve; imagine this: One of my applications
I've got a rather tricky problem that I've been trying to solve for the
I am trying to solve a tricky math problem, in a cocos2d for iphone
I've stuck with one quite tricky problem. I have list of products from different
I am having quite a tricky problem, which i just cannot seem to solve.
I am trying to solve a tricky problem. I am creating a project, which
Our company site has a JavaScript problem that I'm desperately trying to solve, but
To solve some problem I need to compute a variant of the pascal's triangle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.