Javascript: How to store a user generated text in a variable in javascript?
I want to have a text field where user can type in some text and I want to store wha开发者_如何学编程tever they typed in a javascript variable? How do I do this?
var userText = document.getElementById("yourTextInputId").value;
That will store the value of the element with id of "yourTextInputId" in the variable userText. You could put this in a function and call it whenever you need to store the value (for example, when a button is clicked, or when the blur event is fired).
Here's an example binding a blur event to the text input field:
document.getElementById("yourTextInputId").onblur = function() { 
    var userText = this.value;
}
var my_var=document.getElementByID["your_text_box"].value;
this is work with me every time try it
    function getname(name) {
        name = document.getElementById("txtName").value;
        return name;
    }
the getname is the function name and you must pass a parameter witch in may case (name) then use
    name = document.getElementById("txtName").value;
to store the value in the variable then return this variable now you have to do call the getname(name) function whenever you need.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论