...

View Full Version : string split



warzo69
10-09-2008, 03:07 AM
Does anyone see the error in this 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
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

rangana
10-09-2008, 03:13 AM
Please show us the involved markup (HTML).

warzo69
10-09-2008, 03:20 AM
here is the full page
<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>

rangana
10-09-2008, 03:27 AM
I can't test since it's still in PHP raw file, anyway try to capitalize highlighted:


var emparry = new array();


JS is case-sensitive.

If nothing works, show us the generated markup.

warzo69
10-09-2008, 03:38 AM
Brilliant, worked like a charm. I cant say thank you enough.

warzo69
10-09-2008, 03:46 AM
Now I am just beginning to learn js, is there a better way to code this? Not urgent but appreciated all the same.

rangana
10-09-2008, 03:53 AM
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
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum