Tony77
Tony77

Reputation: 311

How can I create a "go to a page" dropdown list in PHP?

I am trying to extend a component for Joomla called Jquarks. This component allows you to create paginated quizzes, and answer the questions or correct your answers by going back and forth through the questions. I think this handled by some Javascript code.

This is the piece of code I believe makes this functionality work, but I don't know how to start to modifying it. I want to have a dropdown list containing all the page numbers, to allow the user go to a navigate to a specific page.

// adding the back next link if multi-pages 
        if ($nbrPage > 1) 
        {
            if( $pNum == (int)($qNum / $nbrQuestionPage) || $qNum == $totalNbrQuestions ) 
            {

                if ($pNum == 1) 
                {
                    echo '<span class="jquarks_qprog"><a id="jquarksPage_' . $pNum . 'next" href="#">' . JText::_('NEXT') . '</a>'
                         . '<p>' . JText::_("PAGE") . ' ' . $pNum . ' / ' . $nbrPage .'</p>' .'</span></div>' ; 
                } 
                elseif ( $pNum == $nbrPage ) 
                {
                    echo '<span class="jquarks_qprog"><a id="jquarksPage_' . $pNum . 'back" href="#">' . JText::_('BACK') . '</a>'
                         . '<p>' . JText::_("PAGE") . ' ' . $pNum . ' / ' . $nbrPage .'</p>' .'</span></div>' ; 
                } 
                else 
                {
                    echo '<span class="jquarks_qprog"><a id="jquarksPage_' . $pNum . 'back" href="#">' . JText::_('BACK') . '</a>
                         |
                         <a id="jquarksPage_' . $pNum . 'next" href="#">' . JText::_('NEXT') . '</a>' 
                        . '<p>' . JText::_("PAGE") . ' ' . $pNum . ' / ' . $nbrPage .'</p>'   
                        . '</span></div>' ;
                }
                $pNum ++ ;
            } 
        } 
         $qNum++ ;
       } 
       if ($nbrPage == 1 ) :
            echo "</div>" ;
       endif ;
       ?>

</div>
<div style="clear: both;"></div>
<div>
    <p>
    <?php if ($nbrPage > 1) : ?>
        <input type="submit" value="<?php echo JText::_('SUBMIT_ANSWERS_CHECK_PAGES') ; ?>" id="send" name="send" />
    <?php else : ?>
    <input type="submit" value="<?php echo JText::_('SUBMIT_ANSWERS') ; ?>" id="send" name="send" />
    <?php endif ; ?>
    </p>    
    <p>
        <a href="http://www.jquarks.org" target="_blank">Powered by JQuarks</a>
    </p>
</div>

<?php 
    $attribs = array('type' => 'text/css');
    $document->addHeadLink(JRoute::_("components/com_jquarks/assets/stylesheets/SyntaxHighlighter.css"), "stylesheet", "rel", $attribs) ; 
?>

Upvotes: 1

Views: 557

Answers (1)

Chris L.
Chris L.

Reputation: 275

Here's an example of javascript on an html drop down:

<select onchange="window.location = this.value">
    <option value="#">Select a page</option>
    <option value="/foo.html">Foo Bar</option>
    <option value="/foo2.html">Foo Bar2</option>
    <option value="/foo3.html">Foo Bar3</option>
    <option value="/foo4.html">Foo Bar4</option>
</select>

I haven't tested this in all browsers but it works in chrome. Usually I use jQuery so the would be:

<select onchange="window.location = $(this).val()">

I'll leave the converting this to PHP as your homework assignment ;) Cheers

Upvotes: 1

Related Questions