Search code examples
phpjavascriptcodeigniter

get the input box 'name' using javascript


I am making form in PHP and submitting using javascript. I want to get the name of input box, As normal coding gives the value of the input box, but i need to get name of input box. Without onclick functionality on it. Can it possible that retrieving the name of input box in other javascript function on click a button. for example

<input type="radio" name="text_name" value="4" id="d">

Now onclick a other button I am calling test(), In test() how can I get the name of the input box.


Solution

  • var txtbox = document.getElementById("d");
    var txtboxname = txtbox.name;