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);