1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

sending data from swap listbox to index.php

Discussion in 'JavaScript' started by zodehala, Feb 4, 2012.

  1. #1
    this is my code
    
    <script type="text/javascript">
    function moveToRightOrLeft(side){
    var listLeft=document.getElementById('selectLeft');
    var listRight=document.getElementById('selectRight');
    
    if(side==1){
    if(listLeft.options.length==0){
    alert('You have already moved all countries to Right');
    return false;
    }else{
    var selectedCountry=listLeft.options.selectedIndex;
    
    move(listRight,listLeft.options[selectedCountry].value,listLeft.options[selectedCountry].text);
    listLeft.remove(selectedCountry);
    
    if(listLeft.options.length>0){
    listLeft.options[0].selected=true;
    }
    }
    }else if(side==2){
    if(listRight.options.length==0){
    alert('You have already moved all countries to Left');
    return false;
    }else{
    var selectedCountry=listRight.options.selectedIndex;
    
    move(listLeft,listRight.options[selectedCountry].value,listRight.options[selectedCountry].text);
    listRight.remove(selectedCountry);
    
    if(listRight.options.length>0){
    listRight.options[0].selected=true;
    }
    }
    }
    }
    
    function move(listBoxTo,optionValue,optionDisplayText){
    var newOption = document.createElement("option");
    newOption.value = optionValue;
    newOption.text = optionDisplayText;
    listBoxTo.add(newOption, null);
    return true;
    }
    </script>
    </head>
    
    <body>
    <form action="index.php" method="post">
    <table border="0">
    <tr>
    <td colspan="4"></td>
    </tr>
    <tr>
    <td colspan="2">Available Countries </td>
    <td colspan="2">Your Selection </td>
    </tr>
    <tr>
    <td rowspan="3" align="right"><label>
    <select name="selectLeft" size="10" id="selectLeft">
    <option value="AS" selected="selected">American Samoa</option>
    <option value="AD">Andorra</option>
    <option value="AO">Angola</option>
    <option value="AI">Anguilla</option>
    <option value="AQ">Antarctica</option>
    <option value="AG">Antigua And Barbuda</option>
    <option value="AR">Argentina</option>
    <option value="AM">Armenia</option>
    <option value="AW">Aruba</option>
    <option value="AU">Australia</option>
    <option value="AT">Austria</option>
    </select>
    </label></td>
    <td align="left">&nbsp;</td>
    <td align="left">&nbsp;</td>
    <td rowspan="3" align="left"><select name="selectRight" size="10" id="selectRight">
    <option value="AF" selected="selected"> value</option>
    
    </select></td>
    </tr>
    <tr>
    <td align="left">&nbsp;</td>
    <td align="left"><label>
    <input name="btnRight" type="button" id="btnRight" value="&gt;&gt;" onClick="javascript:moveToRightOrLeft(1);">
    </label></td>
    </tr>
    <tr>
    <td align="left">&nbsp;</td>
    <td align="left"><label>
    <input name="btnLeft" type="button" id="btnLeft" value="&lt;&lt;" onClick="javascript:moveToRightOrLeft(2);">
    </label></td>
    </tr>
    <tr>
    <td colspan="4" align="right">
    <input name="gonder" type="submit" value="gonder">
    </td>
    </tr>
    </table>
    </form>
    
    PHP:
    but when i push to submit button to get data from right listbox to index.php

    foreach($_POST  as $a => $b){
      echo $a." - ".$b;
    }
    PHP:
    output is

    
    selectLeft - AIselectRight - AFgonder - gonder
    
    Code (markup):
    there are no any data is in right selectbox
     
    zodehala, Feb 4, 2012 IP