开发者

define, radio button change to auto drop down with loop

i looking for help... and hope of you kindly

I want to change my site language model from radio button to auto dropdown button using loop

This the languages

if ($lang=="en") {
//Pages
define ("Pages", "Pages") ;

}

if ($lang=="de") {
define ("Pages", "Seiten") ;
}

This the existing Radio button

                <td width="60%">Languange<b><BR />
                <?php 
                    if ($lang == 'en') {
                        prin开发者_运维技巧t '<input type="radio" value="de" checked name="lang_" /> German&nbsp;&nbsp
                                <input type="radio" value="en" name="lang_" />English&nbsp';
                    }
                    else {
                        print '<input type="radio" value="de" name="lang_" />German&nbsp;&nbsp
                                <input type="radio" value="en" checked name="lang_" />English&nbsp';
                    }
                ?>
                </b></td>

and the Radio button above i want to change drop down button, i looking your help please


I am struggling to understand your question, but are you looking to do something like this? (I haven't tested this code yet)

<td width="60%">Languange<br />
    <select name="lang_">
    <?php
        $languages = array(
            'en'    =>  'English',
            'de'    =>  'German',
            'fr'    =>  'French',
        );

        foreach ($languages as $abrv => $language) {
            printf(
                '<option %s value="%s">%s</option>',
                $lang == $language ? 'selected' : '',
                htmlentities($abrv),
                htmlentities($language)
            );
        }
    ?>
    </select>
</td>


you can't do this in PHP without refreshing the page. otherwise, you can use JavaScript to detect when the radio buttons are clicked, and then change the drop down appropriately.


I ever seen like this code, that i want to

function optionbox($boxname, $cssclass, $elementsarray, $cat_activ=1) {
    echo "<select name='$boxname' class='$cssclass'>";
    while (list($key,$value) = each($elementsarray)) {
        if ($key == $cat_activ) {               // Kategory ist actif 
            $SELECTED = "SELECTED";
        } else {
            $SELECTED = "";
        } //endif
        echo "<option $SELECTED value='$key'>$value</option>";
    } //endwhile
    echo "</select>";
} 

but i am new to php..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜