admin管理员组文章数量:1357716
I have these inputs:
<input type='radio' id='1' name='s' onclick='pieces(this.value);' value='6'>6
<input type='radio' id='2' name='s' onclick='pieces(this.value);' value='12'>12
<input type='radio' id='3' name='s' onclick='pieces(this.value);' value='24'>24
<input type='radio' id='11' name='v' onclick='pieces(this.value);' value='yes'>Yes
<input type='radio' id='12' name='v' onclick='pieces(this.value);' value='no'>No
I want to pass the value from "name='s'" to var1, and value from "name='v'" to var2 to the function pieces(var1, var2)
when the radio button is clicked.
I have these inputs:
<input type='radio' id='1' name='s' onclick='pieces(this.value);' value='6'>6
<input type='radio' id='2' name='s' onclick='pieces(this.value);' value='12'>12
<input type='radio' id='3' name='s' onclick='pieces(this.value);' value='24'>24
<input type='radio' id='11' name='v' onclick='pieces(this.value);' value='yes'>Yes
<input type='radio' id='12' name='v' onclick='pieces(this.value);' value='no'>No
I want to pass the value from "name='s'" to var1, and value from "name='v'" to var2 to the function pieces(var1, var2)
when the radio button is clicked.
- @arttronics, already editted. thanks – Ivo San Commented Jun 30, 2012 at 8:35
3 Answers
Reset to default 1You can pass the arguments in the following different ways:
function antguider(name, url){
alert("Name = "+name+" URL = "+url);
}
HTML Part
<input type="button" onclick=antguider('AntGuider','http://antguider.blogspot.') value="Click Without Quotation" />
<input type="button" onclick="antguider('AntGuider','http://antguider.blogspot.')" value="Click With Quotation" />
<input type="button" onclick="antguider(12345,'http://antguider.blogspot.')" value="No Quotation Needed For Button" />
You can get values of both radio inputs in Javascript method itself using document.getElementsByName()
method or this should also work,
Try using func(document.getElementsByName('s'),document.getElementsByName('v'))
Below code should help,
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="js1/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
alert('Ok');
$('#btn').click(function(){
var r1=$('input:radio[name=s]').val();
var r2=$('input:radio[name=v]').val();
show(r1,r2);
});
});
function show(r1,r2){
alert(r1);
alert(r2);
}
</script>
</head>
<body>
<input type='radio' id='1' name='s' onclick='pieces(this.value);' value='6'>6
<input type='radio' id='2' name='s' onclick='pieces(this.value);' value='12'>12
<input type='radio' id='3' name='s' onclick='pieces(this.value);' value='24'>24
<input type='radio' id='11' name='v' onclick='pieces(this.value);' value='yes'>Yes
<input type='radio' id='12' name='v' onclick='pieces(this.value);' value='no'>No
<button id="btn">Submit</button>
</body>
</html>
For 2 inputs, this can easily be done with JQuery.
va1=$("input[name=s]").val();
va2=$("input[name=v]").val();
Then call the desired function, passing in your values as parameters.
func(va1,va2);
本文标签: How to pass 2 or more arguments from HTML inputs to a Javascript functionStack Overflow
版权声明:本文标题:How to pass 2 or more arguments from HTML inputs to a Javascript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744058533a2583695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论