Pages

26 Aug 2013

getElementById OR get textbox Elements id on forms with using javascript

Method 1: Using an ID
Code:
function add(text){
    var TheTextBox = document.getElementById("Mytextbox");
    TheTextBox.value = TheTextBox.value + text;
}



Method 2: using the form:
Code:
function add(text){
    var TheTextBox = document.forms[0].elements['field_name']; //I think that's right, haven't done it in a while
    TheTextBox.value = TheTextBox.value + text;
}

No comments:

Post a Comment