I have the following function:
<script>
function assign()
{
String val="";
String val = document.form1.text1.value;
System.out.println(val);
}
</script>
i am trying to call the function in the button click as shown below:
<button type="button" onclick="assign()">Display</button>
When i click on the button nothing happens. I want the string value in the text box to be printed on the console.Please help
First of all, if you are trying to call JavaScript on button click, then your syntax is wrong. See, you are mixing Java with JavaScript (code) in script tag, that is invalid.
Use like this:
<script>
function assign() {
var val = "";
val = document.form1.text1.value;
alert(val); or console.log(val);
}
</script>
and
<button type="button" onclick="javascript:assign();">Display</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With