Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
he,
greetings of a day !

here i need to know how i get a cloned textbox value by using jquery in Asp.Net.MVC

What I have tried:

@model Clone.Models.Myclone

@{
	ViewBag.Title = "Index";
}

<h2>Index</h2>
<html>
<head>

</head>
<body>
	<div>
		<input type="text" id="1" />
		<p><input type="button" id="bt" value="Clone it" class="btn btn-success" /></p>
		<p><input type="button" id="bt2" value="Clone Msg" class="btn btn-danger" /></p>
	</div>
	<div id="mycln" class="cln1">
		<table class="table table-responsive table-hover table-bordered" id="orderdetailsItems"><tbody></tbody></table>

	</div>


</body>
</html>
<link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
@section scripts{
	<script src="~/Scripts/jquery-3.3.1.min.js"></script>
	<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

	<script>


		var iCnt = 1;
		$(document).ready(function () {
			$('#bt').on('click', function () {
					iCnt += 1;
					$('#1')
						.clone(true, true)
						.attr('id', iCnt)
						.appendTo("body");
			});

			$('input').on('change', function () {
				alert(this.value);
			});
		});
		$(document).ready(function () {
			$('#bt2').on('click', function () {
				var xid = ($('#iCnt').val());
			
				alert(this.value);
			// how i get here textbox value in a new veriabel 
				// when i am trying to get msg then alert only Show  a massage  "clone msg"
				 
			})
		});
	</script>
}
Posted
Updated 20-Feb-19 3:25am
Comments
Bryian Tan 20-Feb-19 11:22am    
What your code trying to do? on button click, the code need to know which textbox value it need to get. let assumed, the code clone the textbox once, to access the textbox, try something like alert($('#1').val());.

$('#iCnt')

The above means an element with a literal id of "iCnt", eg;

<input type=text id=iCnt/>


What you really want is the value of the iCnt variable, not "iCnt" as literal text

$('#' + iCnt)


That will construct a param like '#2' or '#3' depending on what is in iCnt.
 
Share this answer
 
Comments
sayli1995 20-Feb-19 22:52pm    
thanking you sir ,
really you shows me a simply solution,
i accept your solution
thanking you ,
alert($('#' + iCnt).val())
 
Share this answer
 
Comments
sayli1995 20-Feb-19 22:47pm    
nice and simply solution ,five star ***** for your answer sir
i accepted your answer
thanking you ,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900