I cant use PHP variables to use as parameters for my function.
The function is:
<script type="text/javascript">
function myFunction(id,name) {
alert(id);
alert(name);
}
</script>
And this is PHP part:
echo "<button onclick='myFunction($intvar,$strvar)' type='button'>ClickMe</button>";
the call works when I use numbers like this: myFunction(0,1) but I need to use variables to call myFunction.
Please Help, thanks.
Your onclick event handler can optionally accept a MouseEventArgs parameter which Blazor will automatically include when it invokes the handler.
In order to pass a value as a parameter through the onClick handler we pass in an arrow function which returns a call to the sayHello function. In our example, that argument is a string: 'James': ... return ( <button onClick={() => sayHello('James')}>Greet</button> ); ...
A JavaScript function can have any number of parameters. The 3 functions above were called with the same number of arguments as the number of parameters. But you can call a function with fewer arguments than the number of parameters. JavaScript does not generate any errors in such a case.
example: <button onclick="updateById(`id`, `name`)">update</button> function updateById(id, name) { alert(id + name ); ... } Save this answer.
You try this
function myFunction(ide,name) {
change insted of id => ide
echo "<button onclick='myFunction(".'"'.$intvar.'","'.$strvar.'"'.")' type='button'>ClickMe</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