I have a generated list of Buttons:
<?php
echo "<td> <button id=\"{$cell}\" onclick=\"ausfüllen($cell)\">{$cell}</button></td>"
?>
and I want to call a JavaScript function:
<script>
function ausfüllen(text) {
document.getElementById("nv_durchwahl").value = "dw";
}
</script>
to fill out some other <td>
:
<td>
<input type="text" id="nv_durchwahl" name="nv_durchwahl" value="">
</td>
This is how i tried it.
The buttons are generated without any problem but it doesn't fill out the form.
Any ideas where I went off in this one?
You forgot to close the function bracket
<script>
function ausfüllen(text) {
document.getElementById("nv_durchwahl").value = "dw";
}
</script>
And there is no element with ID "nv_durchwahl".
try to concatenate this way... the function ausfüllen receives a string, check how is being translated into html code...
<?php
echo "<td> <button id='".{$cell}."' onclick='ausfüllen(".'"'.{$cell}.'"'.")'>".{$cell}."</button></td>";
?>
when you say
fill out the form.
means putting on the element with id "nv_durchwahl" (which should be unique) the value "dw" or the content of "text" variable?
<script>
function ausfüllen(text) {
//set the value of the element with the specific id to "dw"
//text is never used!
document.getElementById("nv_durchwahl").value = "dw";
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.