Insert id in data-formid="" from jquery

Asked

Viewed 33 times

2

I need to include on the data-formid="" the id of each event clicked, so that it is different and give u Ubmit with ajax in each form.

I’ve managed to pass the id that way:

Html

<div id="eventID_faturar"></div>

Jquery

This line is where I get the id - $('#eventID_invoice'). text(Event.id);

eventClick:  function(event, jsEvent, view) {
                endtime = $.fullCalendar.moment(event.end).format('h:mm');
                starttime = $.fullCalendar.moment(event.start).format('dddd, D MMMM YYYY, h:mm');
                var mywhen = starttime + ' - ' + endtime;
                var mywhen2 = event.id;
                $('#modalTitle_excluir').html(event.title);
                $('#modalWhen_excluir').text(mywhen);
                $('#eventID_faturar').text(event.id);
                $('#calendarModal_excluir').modal();
            }

Upshot

<div id="eventID_faturar">969</div>

But I would need to include this id in the data-formid="", how would I do that

<form class="faturar_ajax" data-formid="id_aqui" method="post" enctype="multipart/form-data">   
<input type="hidden" id="eventID_faturar" name="eventID_faturar"/>
</form>

1 answer

3


$('#eventID_faturar').data('formid', event.id);

More details here

EDIT: AP wants to put the value inside the tag form. Do as follows:

$('form:eq(0)').data('formid', <valor a passar>);

Where form:eq(0) designates the first. form on the page and <valor a passar>, the value of the attribute data-formid.

EDIT 2: AP was checking if the attribute appeared in the DOM and for that we changed jQuery.data('formid', <valor>) for jQuery.attr('data-formid', <valor>).

  • And in the form I do how to put the id in data-formid=""?

  • If your jQuery has version above or equal to 1.6.4, the jQuery.data(<parametro>) puts and reads from the HTML attribute data-<parametro>

  • What do you mean? I didn’t understand, I put my form so but I didn’t see the id in data-formid="" <form class="faturar_ajax" data-formid="" id="eventID_invoice" method="post" enctype="Multipart/form-data">

  • I am using jQuery v3.3.1

  • I edited the answer. Please check if it meets your need and if it meets, accept my answer and score.

  • yes I understood, but as I said before, it still didn’t work, my form is like this <form class="invoice"invoice" data-formid="" id="eventID_invoice" method="post" enctype="Multipart/form-data"> and my jquery so $('#eventID_invoice'). data('formid', Event.id);

  • Dude, look at EDIT, doing me a favor.

  • Yes I left my jquery like $('form:eq(0)'). data('formid', Event.id); but the id has not yet come=""

  • Do $('form:eq(0)').data('formid', 12345); and see if anything pops up. If it does, the problem is in event.id.

  • I did as you falour and did not appear the id yet Event.id is working because as I said in the question, so it works $('#eventID_invoice'). text(Event.id); but it’s inside a div and I want the id to be in data-formid=""

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.