Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: string split

  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    2
    Thanked 4 Times in 4 Posts

    string split

    Does anyone see the error in this code:
    Code:
    function empsel() {
    document.getElementById('txtfullname').value = document.getElementById('select1').value;
    
    var empinfo = document.getElementById('txtempinfo').value;
    var emparry = new array();
    emparry = empinfo.split("|");
    
    document.getElementById('txtssn').value = emparry[0]; 
    document.getElementById('txtdob').value = emparry[1]; 
    document.getElementById('txtadd1').value = emparry[2]; 
    document.getElementById('txtadd1').value = emparry[3]; 
    document.getElementById('txtphone').value = emparry[4]; 
    document.getElementById('txtempid').value = emparry[5];
    document.getElementById('txtposition').value = emparry[6]; 
    document.getElementById('txthiredate').value = emparry[7]; 
    document.getElementById('txttermdate').value = emparry[8]; 
    document.getElementById('txtstatus').value = emparry[9]; 
    document.getElementById('txtsalary').value = emparry[10]; 
    document.getElementById('txtdriverslicense').value = emparry[11];  
    }
    this is what is displayed in 'txtempinfo' 528-45-9273|1984-07-24|285 Php ln|Buffalo, NY 14201|716-505-1331|1002|Roofer|2008-09-03|0000-00-00|active|41|765-987-567
    The first part is working fine in mozilla but not in IE
    Code:
    document.getElementById('txtfullname').value = document.getElementById('select1').value;
    The remainder is not working at all. i am more concerned with the error in the split function.

    Thanks in advance,

    Matthew Wawrzyniec

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Please show us the involved markup (HTML).
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    2
    Thanked 4 Times in 4 Posts
    here is the full page
    Code:
      <head>
    
    <script src="empedit.js" type="text/javascript" language="javascript"></script>
    
      </head>
    
            <form name="form1">
    
    <div align="left">
      <table width="825" border="0" bgcolor="#FAFAFA">
        <tr>
          <td width="155" rowspan="6" valign="top">
            <div align="center">
                <select name="select1" id="select1" onChange='empsel()'/> 
      <?php
      $result = mysql_query("SELECT fullname FROM employee");
      while ($row = mysql_fetch_array($result)) {
          echo "<option>".$row['fullname']."</option><br>";
      };
      ?>
                  <option>New Employee</option>
                </select>
                <br/>
                <br/>
                <br/>
                <br/>
       
                <textarea name="txtempinfo" rows="5" cols="15" id="txtempinfo"/>
      <?php
      $tmpVar = $_POST['select1'];
      $result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = 'John Smith' ");
      while ($row = mysql_fetch_array($result)) {
          echo "".$row['ssn']."|"."".$row['dob']."|"."".$row['add1']."|"."".$row['add2']."|".
               "".$row['phone']."|"."".$row['empid']."|"."".$row['position']."|"."".$row['hiredate']."|".
               "".$row['termdate']."|"."".$row['status']."|"."".$row['salary']."|"."".$row['driverslicense']."";
      };
       
      ?>
                </textarea>
    
    
          </td>
    	<td width="299" height="10">Full Name or DBA
          </td>			
    	<td width="151" height="10">SSN / Tax ID
          </td>			
    	<td width="151" height="10">Position
          </td>
        </tr>
        <tr>
          <td width="299" height="10">
            <div align="left">
              <input type="text" name="txtfullname" id='txtfullname' value="Full Name or DBA"/>
            </div>
          </td>
          <td width="151" height="10">
            <div align="center">
              <input type="text" name="txtssn" id='txtssn'/>
            </div>
          </td>
          <td width="151" height="10">
            <div align="center">
              <input type="text" name="txtposition" id="txtposition"/>
            </div>
          </td>
        </tr>
        <tr>
          <td width="299" height="10">Address
          </td>			
    	<td width="151" height="10">Drivers License #
          </td>			
    	<td width="151" height="10">Start Date
          </td>
        </tr>
        <tr>
          <td width="299" height="10"> 
            <div align="center">
              <input name="txtadd1" id="txtadd1" type="text" value="Street Address"/>
              <input name="txtadd2" id="txtadd2" type="text" value="City State Zip"/>
            </div>
          </td>
          <td height="10">      
            <div align="center">
              <input type="text" name="txtdriverslicense" id="txtdriverslicense"/>
            </div>
          </td>
          <td height="10">
            <div align="center">
              <input type="text" name="txthiredate" id="txthiredate"/>
            </div>
          </td>
        </tr>
        <tr>
          <td width="299" height="10">Phone Number
          </td>			
    	<td width="151" height="10">Employee ID Number
          </td>			
    	<td width="151" height="10">Term Date
          </td>
        </tr>
        <tr height="20">
          <td width="299" height="10"> 
            <div align="left">
              <input name="txtphone" id="txtphone" type="text" value="XXX-XXX-XXXX"/>
            </div>
          </td>
          <td height="10">   
            <div align="center">
              <input type="text" name="txtempid" id="txtempid"/>
            </div>
          </td>
          <td height="10">
            <div align="center">
              <input type="text" name="txttermdate" id="txttermdate"/>
            </div>
          </td>
        </tr>
        <tr>
          <td height="20" rowspan="2">
            <div align="center">
              
            </div>
          </td>
          <td width="299" height="10">Date Of Birth
          </td>			
    	<td width="151" height="10">Status 
          </td>			
    	<td width="151" height="10">Salary 
          </td>
        </tr>
          <td width="299" height="10">
            <div align="left">
              <input type="text" name="txtdob" id="txtdob"/>
            </div>
          </td>
          <td height="10">
            <div align="left">
              <select name="txtstatus" id="txtstatus"/>
                <option>Active</option>
                <option>Inactive</option>
              </select>
            </div>
          </td>
          <td height="10">
            <div align="center">
              <input type="text" name="txtsalary" id="txtsalary"/>
            </div>
          </td>
        </tr>
      </table>
            </form>  
      </div>

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    I can't test since it's still in PHP raw file, anyway try to capitalize highlighted:
    Code:
    var emparry = new array();
    JS is case-sensitive.

    If nothing works, show us the generated markup.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    warzo69 (10-09-2008)

  • #5
    New Coder
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Brilliant, worked like a charm. I cant say thank you enough.

  • #6
    New Coder
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Now I am just beginning to learn js, is there a better way to code this? Not urgent but appreciated all the same.

  • #7
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    function empsel() {
    document.getElementById('txtfullname').value = document.getElementById('select1').value;
    var empinfo = document.getElementById('txtempinfo').value;
    var emparry = empinfo.split("|"), // Split the value of textarea into emparry Array
    valEq=['txtssn','txtdob','txtadd1','txtadd1',
    'txtphone','txtempid','txtposition',
    'txthiredate','txttermdate','txtstatus',
    'txtsalary','txtdriverslicense' // The last one should'nt have a comma
    ]; // Place the ID in this array. The first element will accept the first split string from emparry.
    
    for(var i=0;i<emparry.length;i++)
    	document.getElementById(valEq[i]).value=emparry[i]; // Make the split string as the value
    }
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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