data attribute from anchor not sending value ti hidden input [closed]

343
November 22, 2016, at 5:01 PM

I have this anchor tag

<a class="productin" onclick="openbox()" data-pid="23">Report</a>

This opens up an modal box which sends an email, I have a hidden input tag inside that email form in which i want to add that data-pid

<input type="hidden" name="productid" id="productid">
Answer 1

Since you tagged this question with jQuery, I'll give you the jQuery answer. This should work:

$(function(){
    $('a.productin').click(function(){
        $('input:hidden[name="productid"]').val($(this).data('pid'));
    });
});

FYI - It is normal procedure in Stack Overflow to post the code you have tried on your own. We are here to help you fix issues with your code, not to write your code for you. In the future do a search for an answer before you ask the question and give it a shot on your own. Then, you can ask why your code didn't work posting the relevant code for us to see. That's is why your question was voted down.

It is also normal procedure for the downvoter to explain why he voted it down.

Rent Charter Buses Company
READ ALSO
ng-disabled / ng-readonly no working

ng-disabled / ng-readonly no working

I'm working on an AngularJS app and I'm stuck. [nnn]I have a simple tabbled interface section with the same layout for every tab section.

527
Using one if else statement to color progress bars in different contexts

Using one if else statement to color progress bars in different contexts

I’ve got some simple rolling progress bars, fed by a percentage number on the page (later this will come from a database), which change color and width dependent upon this number. Got them working nicely in one context, but on another page they need to use different...

234
Remove a table row in MYSQL using PHP [closed]

Remove a table row in MYSQL using PHP [closed]

I've looked through the existing questions and i don't believe they are answering my question. [nnn]I have created a table that gets populated using PHP and MySQL.

394
How to copy a div&#39;s content with clipboard.js or zeroclipboard? [closed]

How to copy a div's content with clipboard.js or zeroclipboard? [closed]

I have some divs in my HTML and I want to copy the contents of a div when I click on that div. .

378