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')">
1

5 Answers 5

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>

Sign up to request clarification or add additional context in comments.

Comments

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 )
});

Comments

0

yes use the following

onclick="viewphone(71241,'divid71241',this.value)"

Comments

0

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

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

Comments

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.