SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Issue with a drop down list

    Hi,

    I am using this script in a business card form to populate a list of work titles that the user can choose from.
    The list is in Norwegian and when selected it also selects a hidden value in English for page 2.
    The challenge is that one of the work titles (sjef) in Norwegian has tree different values in English. So it lists the same title tree times.
    (sjef=boss of communication, sjef=boss of transport, sjef=boss of company)

    Is it possible to add a description to the Norwegian list from the English values that will not be visible on the result page?
    Hopefully only for this one work title not for the hole list.
    As it is now the user has to go back and change the value after he/she sees the result.

    Here is the script:
    Code:
    <?php
    require "config.inc.php";  
    echo "
    
    function fillPos(){ 
     // this function is used to fill the position list on load
    
    ";
    
    $q7=mysql_query("select id, name, en_name from met_pos WHERE parentid=0 ORDER BY name");
    echo mysql_error();
    while($nt7=mysql_fetch_array($q7)){
    echo "addOption(document.drop_list.Pos, '$nt7[id]', '$nt7[name]');";
    }// end of while
    ?>
    
    
    }
    ////////////////// 
    
    function removeAllOptions(selectbox)
    {
    	var i;
    	for(i=selectbox.options.length-1;i>=0;i--)
    	{
    		//selectbox.options.remove(i);
    		selectbox.remove(i);
    	}
    }
    
    
    function addOption(selectbox, value, text )
    {
    	var optn = document.createElement("OPTION");
    	optn.text = text;
    	optn.value = value;
    
    	selectbox.options.add(optn);
    }
    Thank you for any help!

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi,

    Would this give you the result you want?
    PHP Code:
    while($nt7=mysql_fetch_array($q7)){
        if (
    $nt7[name] == 'sjef') {
            echo 
    "addOption(document.drop_list.Pos, '$nt7[id]', '$nt7[name] ($nt7[en_name])');";
        } else {
            echo 
    "addOption(document.drop_list.Pos, '$nt7[id]', '$nt7[name]');";
        }

    It should give you list options like this:
    Code:
    sjef (boss of communication) 
    sjef (boss of transport)
    sjef (boss of company)

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Absolutely:-)
    Just what I was hoping for.

    Thank you very much!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •