www.webdeveloper.com
Results 1 to 4 of 4

Thread: select box fill text box

  1. #1
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544

    select box fill text box

    Hi

    How can i fill a text box after select one item from a select box ? if i select below 4610R-04490101 the text box must have the 490 team value

    <input type="hidden" name="team[][code]" />
    <select name="team[][teamcodicred]">
    <option value="" default>Select one...</option>
    <option value="4610R-04490101">4610R - 04 - Lab. Progr. - Team 490 </option>
    <option value="4610R-04480101">4610R - 04 - Lab. Progr - Team 480</option>
    <option value="4610U-04360101">4610U - 04 - Prog. Eng. - Team 360 </option>
    </select>
    Team: <input type="text" name="team[][teamnumber]" value="" size=3 maxlength=3></input>

    <input type="hidden" name="team[][code]" />
    <select name="team[][teamcodicred]">
    <option value="" default>Select one...</option>
    <option value="4610R-04490101">4610R - 04 - Lab. Progr. - Team 490 </option>
    <option value="4610R-04480101">4610R - 04 - Lab. Progr - Team 480</option>
    <option value="4610U-04360101">4610U - 04 - Prog. Eng. - Team 360 </option>
    </select>
    Team: <input type="text" name="team[][teamnumber]" value="" size=3 maxlength=3></input>

    <input type="hidden" name="team[][code]" />
    <select name="team[][teamcodicred]">
    <option value="" default>Select one...</option>
    <option value="4610R-04490101">4610R - 04 - Lab. Progr. - Team 490 </option>
    <option value="4610R-04480101">4610R - 04 - Lab. Progr - Team 480</option>
    <option value="4610U-04360101">4610U - 04 - Prog. Eng. - Team 360 </option>
    </select>
    Team: <input type="text" name="team[][teamnumber]" value="" size=3 maxlength=3></input>

    Thank's in advance

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
    <!--
    div#main{text-align:center;padding-top:100px;}
    -->
    </style>
    <script type="text/javascript">
    <!--
    function toBox(obj,val){
    var trimval = '';
    if(val != 'Select one...'){
    var raw_val = val.substring(val.indexOf('Team')+5, val.length);
    trimval = raw_val.replace(/\s/g, '');
    }
    var fields = obj.parentNode.elements;
    for(var i = 0; i < fields.length; i++){
    if(fields[i] !== obj){continue;}
    else{
    var box_index = i + 1;
    fields[box_index].value = trimval;
    break;
    }
    }
    }
    //-->
    </script>
    </head>
    <body>
    <div id="main">
    <form action="" name="form1">
    <input type="hidden" name="team[][code]" /> 
    <select name="team[][teamcodicred]" onchange="toBox(this,this.options[this.selectedIndex].text)">
    <option value="" selected="selected">Select one...</option>
    <option value="4610R-04490101">4610R - 04 - Lab. Progr. - Team 490 </option>
    <option value="4610R-04480101">4610R - 04 - Lab. Progr - Team 480</option>
    <option value="4610U-04360101">4610U - 04 - Prog. Eng. - Team 360 </option>
    </select>
    Team: <input type="text" name="team[][teamnumber]" value="" size="3" maxlength="3" />
    
    <input type="hidden" name="team[][code]" />
    <select name="team[][teamcodicred]" onchange="toBox(this,this.options[this.selectedIndex].text)">
    <option value="" selected="selected">Select one...</option>
    <option value="4610R-04490101">4610R - 04 - Lab. Progr. - Team 490 </option>
    <option value="4610R-04480101">4610R - 04 - Lab. Progr - Team 480</option>
    <option value="4610U-04360101">4610U - 04 - Prog. Eng. - Team 360 </option>
    </select>
    Team: <input type="text" name="team[][teamnumber]" value="" size="3" maxlength="3" />
    
    <input type="hidden" name="team[][code]" />
    <select name="team[][teamcodicred]" onchange="toBox(this,this.options[this.selectedIndex].text)">
    <option value="" selected="selected">Select one...</option>
    <option value="4610R-04490101">4610R - 04 - Lab. Progr. - Team 490 </option>
    <option value="4610R-04480101">4610R - 04 - Lab. Progr - Team 480</option>
    <option value="4610U-04360101">4610U - 04 - Prog. Eng. - Team 360 </option>
    </select>
    Team: <input type="text" name="team[][teamnumber]" value="" size="3" maxlength="3" />
    </form>
    </div>
    </body>
    </html>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    Thank's a lot !

    One line i do not understand why is :
    trimval = raw_val.replace(/\s/g, '');

    Wich job this line does ?

    Cheers

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    Quote Originally Posted by amrigo View Post
    ...
    trimval = raw_val.replace(/\s/g, '');

    Wich job this line does ?
    in your options sometimes text ends with a space and sometimes not.

    var raw_val = val.substring(val.indexOf('Team')+5, val.length);

    first we get a substring which starts after "Team " - val.indexOf('Team')+5 and ends on val.length. this substring contains the number we need but it may contain a space after the number (take a look at your markup). to cut off this space we do replacement trimval = raw_val.replace(/\s/g, ''); which cuts it off if space found
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles