I have a XML call that populates a div of 3 input boxes. The data isnt the problem but the JS that formats the input box into 2 decimal places onblur.
I dont have any problem with this before when the input box and the JS are inline. But now that the input boxes are generated by php thru XML, the script doesnt seem to work.
class clear on inputbox3 (name="price_edit") doesnt work. The function clear should activate onblur of inputbox and formats the input as 2 decimal places.
what am I missing?
<div id="info_div" style="float: left;">
</div>
<script>
function showDescript(str) {
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("info_div").innerHTML = this.responseText;
}
};
xhttp.open("GET", "dropdown.php?q="+str, true);
xhttp.send();
}
</script>
<script>
$(".clear").blur(function() {
var num = parseFloat($(this).val());
var cleanNum = num.toFixed(2);
$(this).val(cleanNum);
});
</script>
<?php
session_start();
include '../dbh.php';
$q = $_REQUEST["q"];
$sql = "SELECT * FROM sc_item_master WHERE name='$q'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
echo "<input type='text' value='".$row['descript']."' style='width: 409px;' name='descript_edit'>";
echo "<input type='text' value='".$row['currency']."' style='margin-left: 3px; width: 83px; padding-left: 3px;' name='currency_edit'>";
echo "<input type='number' name='price_edit' placeholder='price' step='.01' class='clear' style='margin: 0 3px; width: 142px;'>";
?>