SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: need help passing a variable into a textbox

  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help passing a variable into a textbox

    hi guys! am trying to insert the email address of the user when their names are cut and pasted into listbox (list2), my code does insert the email address, but not perfect, it insert more than one for one user, for example, if i passed the name of "user08", his/her email address would appear in the textbox like this:
    PHP Code:
    user08@ourdomain.com;user08@ourdomain.com;user08@ourdomain.com 
    instead of this:
    PHP Code:
    user08@ourdomain.com 
    and if i insert multiple users, it will look like this:
    PHP Code:
    user08@ourdomain.com;user08@ourdomain.com;user08@ourdomain.com;;;;;;;;;;;;;;;;;;user09@ourdomain.com;user09@ourdomain.com;;;;;;;;;;;;;;;;;;;user10@ourdomain.com 
    instead of this:
    PHP Code:
    user08@ourdomain.com;user09@ourdomain.com;user10@ourdomain.com 
    below is my code, any help would be appreciated:
    PHP Code:
    <HTML>
     <
    HEAD>
     
      <
    script language="javascript">

         function 
    move(fboxtbox) {
         var 
    arrFbox = new Array();
         var 
    arrTbox = new Array();
         var 
    arrLookup = new Array();
         var 
    i;
         
         for(
    i=0i<tbox.options.lengthi++) {
              
    arrLookup[tbox.options[i].text] = tbox.options[i].value;
              
    arrTbox[i] = tbox.options[i].text;
         }
         
           var 
    users = [
                    
                    [
    "01""user01""user01@ourdomain.com"], 
                    [
    "02""user02""user02@ourdomain.com"], 
                    [
    "03""user03""user03@ourdomain.com"], 
                    [
    "04""user04""user04@ourdomain.com"], 
                    [
    "05""user05""user05@ourdomain.com"],
                    [
    "06""user06""user06@ourdomain.com"], 
                    [
    "07""user07""user07@ourdomain.com"], 
                    [
    "08""user08""user08@ourdomain.com"], 
                    [
    "09""user09""user09@ourdomain.com"], 
                    [
    "10""user10""user10@ourdomain.com"]
                ];

        var 
    emps = []; 
        var 
    ops document.theFORM.list1.options;   
        for( var 
    i=0ops.lengthi++ ) {   
            if( 
    ops[i].selected ) {    

            for( var 
    j=0users.lengthj++ ) {   
                if( 
    ops[i].value == users[j][0] ) {   
                    
    emps[emps.length] = users[j][2];   
                } 
          } 

        
        var 
    old_users document.theFORM.email.value;   
           if(
    old_users != "") {   
          
    old_users += ";";   
           }   
                
    document.theFORM.email.value old_users concat_arr(emps); 

         
         var 
    fLength 0;
         var 
    tLength arrTbox.length
         
    for(i=0i<fbox.options.lengthi++) {
              
    arrLookup[fbox.options[i].text] = fbox.options[i].value;
              if(
    fbox.options[i].selected && fbox.options[i].value != "") {
                   
    arrTbox[tLength] = fbox.options[i].text;
                   
    tLength++;
              } else {
                   
    arrFbox[fLength] = fbox.options[i].text;
                   
    fLength++;
              }
         }
         
    arrFbox.sort();
         
    arrTbox.sort();
         
    fbox.length 0;
         
    tbox.length 0;
         var 
    c;
         for(
    c=0c<arrFbox.lengthc++) {
              var 
    no = new Option();
              
    no.value arrLookup[arrFbox[c]];
              
    no.text arrFbox[c];
              
    fbox[c] = no;
         }
         for(
    c=0c<arrTbox.lengthc++) {
             var 
    no = new Option();
             
    no.value arrLookup[arrTbox[c]];
             
    no.text arrTbox[c];
             
    tbox[c] = no;
         }
    }

    function 
    selectAll(box) {
         for(var 
    i=0i<box.lengthi++) {
         
    box[i].selected true;
         }
    }

    function 
    concat_arr(arr) { 
       var 
    ret_str ""
       var 
    i
       for(
    i=0i<arr.lengthi++) { 
          if(
    0) { 
             
    ret_str += ";"
          } 
          
    ret_str += arr[i]; 
       } 
       return 
    ret_str
    }  
                
    </SCRIPT>
          
     </HEAD>
     <BODY>
       <CENTER>
        <TABLE CELLPADDING="7" CELLSPACING="0" BORDER = "1" WIDTH="560" bgcolor="#F0F8FF">
       <FORM NAME="theFORM">
           <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0">
            <TR><TD width="28%">&nbsp;<p>
                 &nbsp;</TD>
             <TD width="43%"><p align="center"><b>Recipient's E-Mail</b></p><p align="center"><input type="text" name="email" size="30"></TD>
             <TD>&nbsp;</TD></TR></TABLE>

           <TABLE WIDTH="30%" CELLPADDING="0" CELLSPACING="0" BORDER="0">
            <TR><TD><TABLE WIDTH="92%" CELLPADDING="0" CELLSPACING="0" BORDER="0">
               <TR><TD WIDTH="9%" height="18" align="center"></TD>
                <TD WIDTH="15%" height="18" align="center"></TD></TR>
                
               <TR><TD WIDTH="29%" height="18" align="center" bgColor=#eaefff>
                  <p align="center" bgColor=#eaefff><b>Selected Recipient(s)</b></TD>
                <TD WIDTH="15%" height="18" align="center" bgColor=#eaefff></TD>
                <TD WIDTH="38%" height="18" align="center" bgColor=#eaefff>
                  <b>Recipient List</b></FONT></TD></TR>
               <TR>
                 
                 <TD width="29%" valign="top"><p align="center"><SELECT NAME="list2" SIZE="9" MULTIPLE style="width: 187; height: 150"></SELECT></TD>
                 
                <TD width="15%"><TABLE CELLPADDING="0" CELLSPACING="0" ALIGN="center" BORDER="0" id="table1" width="58">
                  <TR><TD ALIGN="center" height="26"><INPUT TYPE="button" VALUE="&lt;&lt;" NAME="AddRecipient" onClick="move(this.form.list1,this.form.list2)"></TD></TR>
                  <TR><TD><p align="center"><INPUT TYPE="button" VALUE="&gt;&gt;" NAME="RemoveRecipient" onClick="move(this.form.list2,this.form.list1)" ></TD></TR></TABLE>
                          
                <TD width="38%"><p align="right"><SELECT NAME="list1" SIZE="9" MULTIPLE style="width: 187; height: 153">
                <option value="01">user01</option>
                <option value="02">user02</option>
                <option value="03">user03</option>
                <option value="04">user04</option>
                <option value="05">user05</option>
                <option value="06">user06</option>
                <option value="07">user07</option>
                <option value="08">user08</option>
                <option value="09">user09</option>
                <option value="10">user10</option>
                </SELECT></TABLE></TD></TR></CENTER></FORM>
     </BODY>
    </HTML> 

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may be of interest

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    var users = [
     ["01", "user01", "user01@ourdomain.com"],
     ["02", "user02", "user02@ourdomain.com"],
     ["03", "user03", "user03@ourdomain.com"],
     ["04", "user04", "user04@ourdomain.com"],
     ["05", "user05", "user05@ourdomain.com"],
     ["06", "user06", "user06@ourdomain.com"],
     ["07", "user07", "user07@ourdomain.com"],
     ["08", "user08", "user08@ourdomain.com"],
     ["09", "user09", "user09@ourdomain.com"],
     ["10", "user10", "user10@ourdomain.com"]
     ];
    
    
    function FillSelect(objid,tarid,ary){
     obj=document.getElementById(objid);
     for (i0=0;i0<ary.length;i0++){
      obj.options[i0+1]=new Option(ary[i0][1],ary[i0][2],true,true)
     }
     obj.options[obj.options.length]=new Option('Clear','Clear',true,true)
     obj.selectedIndex=0;
     obj.onclick=null;
     obj.target=document.getElementById(tarid);
     obj.ary=new Array();
    }
    
    function ShowEMail(obj){
     if (obj.options[obj.selectedIndex].value=='Clear'){obj.target.value=''; obj.ary=new Array(); return; }
     if (obj.selectedIndex<1){ return; }
     for (i0=0;i0<obj.options.length;i0++){
      if (obj.options[i0].selected){
       if (!obj.target.value.match(obj.options[i0].value)){
        obj.ary[obj.ary.length]=obj.options[i0].value+';';
       }
      }
     }
     obj.target.value='';
     for (i1=0;i1<obj.ary.length;i1++){
      obj.target.value+=obj.ary[i1];
     }
    }
    
    //-->
    </script>
    
    
    
    </head>
    
    <body onload="FillSelect('EMail','EMailTB',users);">
    <select id="Email" size=4  multiple="multiple" onchange="ShowEMail(this);" style="width:120px;" >
    <option >Select Email</option>
    </select>
    <input id="EMailTB" type=text size=100 >
    
    </body>
    
    </html>
    or even
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    var users = [
     ["user01", "user01@ourdomain.com"],
     ["user02", "user02@ourdomain.com"],
     ["user03", "user03@ourdomain.com"],
     ["user04", "user04@ourdomain.com"],
     ["user05", "user05@ourdomain.com"],
     ["user06", "user06@ourdomain.com"],
     ["user07", "user07@ourdomain.com"],
     ["user08", "user08@ourdomain.com"],
     ["user09", "user09@ourdomain.com"],
     ["user10", "user10@ourdomain.com"]
     ];
    
    
    function FillSelect(objid,tarid,ary){
     obj=document.getElementById(objid);
     for (i0=0;i0<ary.length;i0++){
      obj.options[i0+1]=new Option(ary[i0][0],ary[i0][1],true,true)
     }
     obj.options[obj.options.length]=new Option('Clear','Clear',true,true)
     obj.selectedIndex=0;
     obj.target=document.getElementById(tarid);
    }
    
    function ShowEMail(obj){
     if (obj.options[obj.selectedIndex].value=='Clear'){obj.target.value=''; return; }
     if (obj.selectedIndex<1){ return; }
     for (i0=0;i0<obj.options.length;i0++){
      if (obj.options[i0].selected){
       if (!obj.target.value.match(obj.options[i0].value)){
        obj.target.value+=obj.options[i0].value;
       }
      }
     }
    }
    
    //-->
    </script>
    
    
    
    </head>
    
    <body onload="FillSelect('EMail','EMailTB',users);">
    <select id="Email" size=4  multiple="multiple" onchange="ShowEMail(this);" style="width:120px;" >
    <option >Select Email</option>
    </select>
    <input id="EMailTB" type=text size=100 >
    
    </body>
    
    </html>

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
  •