Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi all I have two textbox like that

HTML
 @Html.TextBox("Title",null, new { @class = "name_input", @id = "Title" })

@Html.TextBox("LongUrlText", "http://www.darwish.ps/"+ pageID + "/Details/" + Model.ID + (I need here to add the value which come from the textbox Title)"/" + Model.Title.ToSeoUrl(), new { @class = "name_input", @id = "LongUrlText", @readonly = 
"readonly" })


I want to add the value whih come from textbox Title to the data which already existed in textbox LongUrlText help me please to ahcieve that .

What I have tried:

I tried to use use this script but it clear all data from the textbox longurltext and I don't want to clear data I just want to complete the the data which come from Title textbox into it .

JavaScript
@*<script>

     document.getElementById("Title").onkeyup = function () {
     document.getElementById("LongUrlText2").value = this.value;
     };
 </script>*@
Posted
Updated 8-May-16 7:32am
v2
Comments
Sergey Alexandrovich Kryukov 8-May-16 9:50am    
The script is correct but ugly: you calculate document.getElementById again and again. Store the results in variables, that's it. The problem is ASP.NET markup, not JavaScript. You did not properly set id values.

id = "LongUrlText" would work, without @...

—SA
Sarah Mohammed77 8-May-16 10:12am    
can you give me the correct syntax for my code please .

1 solution

Try this

JavaScript
<script>
           var initialValue = document.getElementById("LongUrlText2").value;
           document.getElementById("Title").onkeyup = function () {
               document.getElementById("LongUrlText2").value = initialValue + this.value;
           };

   </script>
 
Share this answer
 
Comments
Sarah Mohammed77 8-May-16 16:57pm    
it just work like charm thanks alot man .
Karthik_Mahalingam 8-May-16 22:41pm    
Welcome Sara
lanthanh1985 10-Nov-20 0:19am    
can auto copy data when the textbox has already loaded data ?

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