How can I get value of editorfor and assign this value to another editorfor?
11,820
Solution 1
Try :-
$(document).ready(function () {
$("#projectName").on('input',function(){
$('#identifier').val($(this).val());
});
});
Solution 2
You can use keyup
event and copy value to the other control, so that when user write something in the projectName
textbox the value will be copied to the identifier
textbox as well:
$(document).ready(function () {
$("#projectName").keyup(function(){
$("#identifier").val($(this).val());
alert($("#identifier").val())
});
});
or you can write event the when your textbox loses focues copy value that time:
$(document).ready(function () {
$("#projectName").blur(function(){
$("#identifier").val($(this).val());
alert($("#identifier").val())
});
});
Solution 3
In my solution I used Button "Copy"
$(document).ready(function () {
$('#buttonCopy').click(function() {
$("#identifier").val($("#projectName").val());
});
});
![melomg](https://i.stack.imgur.com/b12Vp.jpg?s=256&g=1)
Author by
melomg
Updated on June 04, 2022Comments
-
melomg about 2 years
I want to get value of my projectName but Alert result always is :
Value: function(value){ return access(this, function(value){ return value === undefined ? Jquery.text(this): this.empty().each(function(){….
like that. I tried .val and .html methods. But they don't work. I also changed the EditorFor as a TextBoxFor but again doesn't work. What should I do? Thanks in advance.
here my view:
<script> $(document).ready(function () { $("#projectName").change(function(){ alert("Value: " + $("#identifier").text); }); }); </script> <div class="form-group"> @Html.LabelFor(model => model.projectName, new { @class = "col-lg-2 control-label" }) <div class="col-lg-10"> <p>@Html.EditorFor(model => model.projectName, new { htmlAttributes = new { @class = "form-control", id = "projectName" } })</p> @Html.ValidationMessageFor(model => model.projectName) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.identifier, htmlAttributes: new { @class = "col-lg-2 control-label" }) <div class="col-lg-10"> <p>@Html.EditorFor(model => model.identifier, new { htmlAttributes = new { @class = "form-control", id = "identifier" } })</p> @Html.ValidationMessageFor(model => model.identifier) </div> </div>
-
Jogi about 8 yearsThis is when the document is ready. What if after the document is ready and user enters an input in an editorfor and i want to read that input and assign it to another editorFor after user has finished inputting it?