简体   繁体   中英

How can i add permanent word to the text box?

I am trying to add permanent word to the textbox.in this text box it will take users firstname automatically when user enters the his name in the firstname textbox using onkeyup="copyText()" function.what i want to do is i want s to add permanent word to sitename textbox after getting automatically typed firstname.

Here is my code

<td><input type="text" id="fname" name="fname"   value=""  placeholder="Your First Name" onkeyup="copyText()"  required /></td>

<td><input type="text" id="sitename" name="sitename" value=""  placeholder="Your Site name" readonly/></td>

Here is my javascript code this is working

<script type="text/javascript">
    function copyText() {
        src = document.getElementById("fname");
        dest = document.getElementById("sitename");
        dest.value = src.value;
    }
</script>

This is pretty doable with jQuery:

$('#fname').keyup(function(event) {

    event.stopPropagation();

    $('#sitename').val($('#fname').val());
});

You will have to remove your copyText() function for this to work.

Hope this helps.

I assume you want something like this

if a user enters a name for eg 'StackOverflow'

in the second input box you want to have 'StackOverflow.co.in' where '.co.in' is your permanent text to the text box

However for this you can use simple javascript

<input id = "firstName" onkeyup="copyText()" />

<Input id = "siteName" value =".co.in" />

<script type="text/javascript">
function copyText(){
    var firstName = document.getElementById('firstName').value ;
    document.getElementById('siteName').value = firstName + '.co.in' ;
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM