dimanche 19 avril 2015

Replacing text of a field with javascript Function

I have a form where I dynamically display checkboxes from an oracle database. But I want to change the checkboxes. This is the text of the form:



<form id = "Options">
<?php
$conn = oci_connect('DBadmin', 'dbadmin', 'PETLOVERSDB');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$query= 'select * from pettype order by PET_TYPE_CODE';
$stmt = oci_parse($conn, $query);
oci_execute($stmt);


while($row=oci_fetch_assoc($stmt)) {
echo "<label>{$row['PET_TYPE_NAME']}</label><input type = 'checkbox' name = 'radio' id = '{$row['PET_TYPE_CODE']}' value = '{$row['PET_TYPE_NAME']}'/><br /> " ;
}

?>
</form>


And I also created a function that I call when I press a button:



<script type="text/javascript">
function update(){
var e = document.getElementById("consultFacts");
var str = e.options[e.selectedIndex].text;
alert(str);
var elem = document.getElementById("Options");
elem.value = "My default value";

}
</script>


I have tried the getElementById as I've read but I don't seem to get any changes in the form. And it does enter the function because it does alert(str). Any suggestions?


Aucun commentaire:

Enregistrer un commentaire