Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting value of hidden element in php

Tags:

html

php

I have a hidden field in form. On form submit I call a database function to add the inputs to database and return result of query. I wish to set the value returned to hidden field. But when I am not able to assign a value to it

<form name="frmAddBook" id="frmAddBook" method="post">
<input type="hidden" name="actionResult" id="actionResult">

PHP

echo '
<script type="text/javascript">
alert("hello"); 
document.getElementById("actionResult").value=1;
alert("2222222");
alert(document.frmAddBook.getElementById("actionResult").value);
</script>';
like image 898
user1247412 Avatar asked Dec 04 '25 11:12

user1247412


1 Answers

you need to specify the value of that hidden input field, so if you wanted to do this in PHP it'd look like this:

<input type="hidden" name="actionResult" id="actionResult" value="<?php echo $result; ?>"/>
like image 188
Ben Ashton Avatar answered Dec 06 '25 23:12

Ben Ashton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!