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.

Categories Selection

Discussion in 'PHP' started by superlinksworld, Jul 13, 2012.

  1. #1
    Hi all PHP coders,

    I have a list of categories in mysql database . I want users to select the categories they want to pick at signup page . Can you guys give me your ideas how can i achieve this goal ? .

    Regards,

    D Najmi
     
    superlinksworld, Jul 13, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Do you want the way the signup page works, or the way to store the selections they make? Or both? Or what?
     
    Rukbat, Jul 13, 2012 IP
  3. superlinksworld

    superlinksworld Member

    Messages:
    127
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    43
    #3
    Hi Rukbat,

    I want to display all available categories ,which i can pull into any of this like drop down, select box and simple page etc . i can use multiple select option two but i don't like that . i need some thing where user can pick categories , and then the also have ability to remove them if they mistakenly choose wrong , i also limit them to just choose 2 categories , Then finally i want that categories selection will save by id in there profile database(which i can do ) .

    I have couple of ideas .

    first idea is to put one select box on right side and fetch all categories from database then in center add two button "ADD" and "REMOVE" and then after them add another empty textarea box where its display user categories he add by clicking on "ADD" button. i hope u understand my idea .

    can u help ?

    Regards,
     
    superlinksworld, Jul 14, 2012 IP
  4. superlinksworld

    superlinksworld Member

    Messages:
    127
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    43
    #4
    I have a JavaScript code which i can modify to add mysql database and work with php but the only thing i want in this code is to limit categories selection to three . So if you guys only help me here would be fine .



    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    
    <title>Transferring value from one select box to another with help of Javascript</title>
    
    <script type="text/javascript">
    
      function addOption(theSel,theText,theValue){
    
       var newOpt=new Option(theText,theValue);
    
       var selLength=theSel.length;
    
       theSel.options[selLength]=newOpt;
    
      }
    
      function deleteOption(theSel,theIndex){
    
       var selLength=theSel.length;
    
       if(selLength>0){
    
        theSel.options[theIndex]=null;
    
       }
    
      }
    
      function selAll() {
    
        elem=document.getElementById('receiver');
    
        varr=new Array();
    
        for (d=0;d<elem.length;d++){
    
          varr[d]=elem.options[d].value;
    
        }
    
        vars=varr.join(",");
    
        tmps=document.getElementById('tmps');
    
        tmps.value=vars;
    
      }
    
      function moveOptions(SFrom,STo){
    
       var theSelFrom = document.getElementById(SFrom);
    
       var theSelTo = document.getElementById(STo);
    
       var selLength=theSelFrom.length;
    
       var selectedText=new Array();
    
       var selectedValues=new Array();
    
       var selectedCount=0;
    
       var i;
    
       for(i=selLength-1;i>=0;i--){
    
        if(theSelFrom.options[i].selected){
    
         selectedText[selectedCount]=theSelFrom.options[i].text;
    
         selectedValues[selectedCount]=theSelFrom.options[i].value;
    
         deleteOption(theSelFrom,i);
    
         selectedCount++;
    
        }
    
       }
    
       for(i=selectedCount-1;i>=0;i--){
    
        addOption(theSelTo,selectedText[i],selectedValues[i]);
    
       }
    
       selAll();
    
      }
    
      function swapOpt(shift) {
    
        elem=document.getElementById('receiver');
    
        ind=elem.selectedIndex;
    
        if(ind!=-1) {
    
          if(ind==0 && shift==-1){return false;}
    
          if(ind==elem.length-1 && shift==1){return false;}
    
          nind=ind+shift;
    
            tval=elem.options[nind].value;
    
            ttxt=elem.options[nind].text;
    
            elem.options[nind].value=elem.options[ind].value;
    
            elem.options[nind].text=elem.options[ind].text;
    
            elem.options[ind].value=tval;
    
            elem.options[ind].text=ttxt;
    
            elem.selectedIndex=nind;
    
          selAll();
    
        }
    
      }
    
      function frmCheck() {
    
        if(document.form1.tmps.value=="") {
    
          alert("Please select input field(s)!");
    
          return false;
    
        }
    
      }
    
     </script>
    
    </head>
    
    <body>
    
      <form name="form1" method="post" onsubmit="return frmCheck();">
    
        <table class="form" cellpadding="3" cellspacing="1">
    
          <tr>
    
            <td><select size="10" style="width:80px;" name="sender" id="sender" ondblclick="moveOptions('sender','receiver')">
    
                <option value="1">Name 1</option>
    
                <option value="2">Name 2</option>
    
                <option value="3">Name 3</option>
    
                <option value="4">Name 4</option>
    
                <option value="5">Name 5</option>
    
              </select>
    
            </td>
    
            <td><input value="&#9658;" type="button" onclick="moveOptions('sender','receiver')" />
    
              <br />
    
              <input  value="&#9668;" type="button" onclick="moveOptions('receiver','sender')" />
    
            </td>
    
            <td><select size="10" style="width:80px;" id="receiver" name="receiver" ondblclick="moveOptions('receiver','sender')">
    
              </select>
    
              <input type="hidden" name="tmps" id="tmps" value="" />
    
            </td>
    
            <td valign="top"><input value="&#9650;" type="button" onclick="swapOpt(-1)" />
    
              <br />
    
              <input value="&#9660;" type="button" onclick="swapOpt(1)" />
    
            </td>
    
          </tr>
    
          <tr>
    
            <td colspan="4" align="center"><input class="inputBut" type="submit" value="Submit" /></td>
    
          </tr>
    
        </table>
    
      </form>
    
    </body>
    
    </html>
    
    
    Code (markup):
    Regards,

    D Najmi
     
    superlinksworld, Jul 14, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    
    var countOptions = 0;
    //then keep count of the options you add and subtract.
    //If the user tries to add an option, and the count is already 3, pop up an alert and don't add the option.
    
      function moveOptions(SFrom,STo){
    
       var theSelFrom = document.getElementById(SFrom);
    
       var theSelTo = document.getElementById(STo);
    
       var selLength=theSelFrom.length;
    
       var selectedText=new Array();
    
       var selectedValues=new Array();
    
       var selectedCount=0;
    
       var i;
    
       for(i=selLength-1;i>=0;i--){
    
        if(theSelFrom.options[i].selected){
    
         selectedText[selectedCount]=theSelFrom.options[i].text;
    
         selectedValues[selectedCount]=theSelFrom.options[i].value;
    
         deleteOption(theSelFrom,i);
    
         selectedCount++;
    
        }
    
       }
    
       for(i=selectedCount-1;i>=0;i--){
    
        addOption(theSelTo,selectedText[i],selectedValues[i]);
    
       }
    
       selAll();
    
      }
    
    
    Code (markup):
     
    Rukbat, Jul 14, 2012 IP