Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 494
Parth Sarthi Gour Avatar asked Oct 11 '12 05:10

Parth Sarthi Gour


3 Answers

var txtbox = document.getElementById("d");
var txtboxname = txtbox.name;
like image 77
Priyank Patel Avatar answered Sep 25 '22 05:09

Priyank Patel


u can do that by using attr function...

in yout test function add this...

$('#d').attr('name');  // this will return text_name in your case (if you are using jquery)

OR

var inputname=document.getElementById("d").name  //javascript
like image 44
bipen Avatar answered Sep 23 '22 05:09

bipen


put this on your javascript function

var name=document.getElementById("d").name;
like image 41
polin Avatar answered Sep 26 '22 05:09

polin