0

Is it possible to get on click value by input name in jQuery? I don't have neither class nor id and I want to get the on click value on name only. As I am doing all this in a software to get data.

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')">
halfer
  • 19,824
  • 17
  • 99
  • 186
Hitesh Chauhan
  • 87
  • 2
  • 4
  • 13
  • 2
    Possible duplicate of [How can I select an element by name with jQuery?](http://stackoverflow.com/questions/1107220/how-can-i-select-an-element-by-name-with-jquery) – Tibrogargan Aug 13 '16 at 07:16

5 Answers5

2

try this , it is easy to get onclick value

<html>
<head></head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>


<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;">

</body>

<script type="text/javascript">
    
   $(document).ready(function(){
    $('[name=view]').click(function(){
     var valueis = $(this).attr('onclick');
     alert(valueis);
    });
   });


</script>

</html>
caldera.sac
  • 4,918
  • 7
  • 37
  • 69
1

You could use the attribute selector

For example for your element

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;">

If you just have one element with a unique name:

$("input[name='view']").click(function() {
// function data goes here 
console.log( this.value )
});

If you have multiple elements with the same name you can use the each() method

$("input[name='view']").each(function() {
// function data goes here 
console.log( this.value )
});

Output

Click To View Phone, Mobile & Fax Numbers
// other input values here

If you have multiple elements with the same name but only want the first ones value you can use the .first() method:

$("input[name='view']").first(function() {
// function data goes here 
console.log( this.value )
});
AnonDCX
  • 2,501
  • 2
  • 17
  • 25
0

yes use the following

onclick="viewphone(71241,'divid71241',this.value)"
Akshay
  • 815
  • 7
  • 16
0

Try this one. I believe you can use attr name to trigger an event.

$('input[name=view]').click(function(){
    // functions here
});
0

Yes , you can do that by using [attribute] selector .

input[name="view"] 

will select that particular Element.

$('input[name="view"]').click(function(){

});

Here is a reference link : https://api.jquery.com/attribute-equals-selector/

Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26