I tried with old question, there they passing the value in js to js.But I would like to pass string from html to javascript. but it gives
Uncaught reference error
my html
is
<a href="#" onclick="test(TEST123)">
and my javascript
is,
function test(p){
alert(p)
}
how can I pass the string>
If you write test(TEST123)
then it looks for the variable with TEST123
name.
so you have to pass it as a string not as a variable
function test(p){ alert(p) }
<a href="#" onclick="test('TEST123')"> and
<a href="#" onclick="test('TEST123')">
只是在您的js函数中写一个字符串参数
If you are using select tag, and want to pass the value on selecting the option item, then you can use
<select class="form-control" onchange="checkifclick('hello')" name="product_name">
and in javascript,
<script>
function checkifclick(test) {
alert(test);
}
Basically, i had faced this problem once, i wanted to call the function and wanted to pass the variables into that javascript function.
class="form-control"
is using to beautify the element, form-control
is a build-in class of bootstrap.
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.