mariafatima mariafatima - 5 months ago 24
HTML Question

How to break/split the content of xmlhttp.responseText in javascript

enter image description hereenter image description hereThis div tag contains the following content ."Name Individual Branch"

<div hidden name = "divT" id = "divT" >Hi</div> <html>

I want Name in a separate div .
These are dynamic and are coming from the database
the following is my javascript code

<?php>
if ($Select=="Policy"){
$qry = "select DISTINCT l.np1_proposal POLICY , A.aag_agcode AGENT , B.pcl_locatcode CODE , BR.pcl_locatdesc LOCATION ,p.pcl_channel CHANNEL , l.np2_setno
FROM lnp2_policymastr l , laag_agent A , pcl_complocation B , pcl_complocation BR , pcl_complocation p
where l.np1_proposal= '$Policy' and A.aag_agcode=l.aag_agcode AND B.pcl_locatcode =A.pcl_locatcode and B.pcl_locatcode=BR.pcl_locatcode and
p.pcl_locatcode=BR.pcl_locatcode and l.np2_setno = (select max(np2_setno) from lnp2_policymastr where np1_proposal = '$Policy') ";
$stmt = OCIParse($conn,$qry);

OCIDefineByName($stmt,"CHANNEL",$channel);
OCIDefineByName($stmt,"LOCATION",$channe);
OCIExecute($stmt);
OCIFETCH($stmt);
//echo $channe;
//OCIDefineByName($stmt,"LOCATION",$channe);

$q1="select A.NPH_FULLNAME NAME , B.NPH_CODE CODE
FROM lnph_pholder A , LNU1_UNDERWRITI B
where B.NP1_PROPOSAL='$Policy' and A.NPH_CODE=B.NPH_CODE";

$t = OCIParse($conn,$q1);

OCIDefineByName($t,"NAME",$name);
//OCIDefineByName($stmt,"LOCATION",$channe);
OCIExecute($t);
OCIFETCH($t);
echo nl2br("\n$name");
//echo $name;
// echo $_SESSION['$name'];
}
?>



function showName(Policy,Select)
{

//alert("Hi"+Select+Policy);

if (Policy == "") {
document.getElementById("divT").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
//alert("Hi");

} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");


}
xmlhttp.onreadystatechange = function() {
//alert("Hi3" + xmlhttp.readyState + xmlhttp.status );

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//alert(xmlhttp.responseText);
document.getElementById("divT").innerHTML = xmlhttp.responseText;
document.getElementById("divT").style.display ='block';
//document.getElementById("divT1").style.display ='block';
// alert(xmlhttp.responseText);
}
};
xmlhttp.open("GET","query.php?policy="+Policy+'&select='+Select,true);
xmlhttp.send();
}
}





<tr>
<td><h4>Lookup Category: *

<select id= "email" name="email" style="width: 10px !important; min-width: 170px; max-width: 170px;" >


<option value="">Please select:</option>
<option value="Policy">Policy<p></option>
<option value="Agent">Agent</option>
<option value="CNIC">CNIC</option>
<option value="Branch">Branch</option>
</select>
</td>



<td ><div hidden name = "divT" id = "divT" >Hi</div></td>

<div> <span class="error"> <?php ?></div></span>

</tr>



Answer

You can get the innerText adn split the text by word individual

var val = document.getElementById("divName").innerText;
val = val.split("Individual");
var name = val[0];
Comments