0

I'm trying to create a modal which should show position variable mention in my code here is my ejs code (i'm using ejs and node js and java script for modal)

<div class="container-fluid">

  <%for(i=0;i<Vac.length;i++){%>
 <div class="alert alert-dark" role="alert">

     <h4 class="alert-heading">Postion:- <%=Vac[i].position%></h4>

  <hr>
  <h5>Type:- <%=Vac[i].type%></h5>

  <h6>Skills:- <%=Vac[i].Skills%></h6>
  <p class="lead"><%=Vac[i].Description%> </p>
   <button type="button" class="btn btn-primary" data-toggle="modal" onclick="showApply()">Apply</button>  


     <br> 
  </div>
  <%}%>
</div>

here is my javascript code for the modal

<script>
     function showApply()
     {
     $('#applyModal').modal('show');
      $('#applyModal').('#applyModaltitle').text($('#alert-heading'));
     } 
    </script>

but i'm getting the error as below:

SyntaxError: missing name after . operator[Learn More] careers:216:23 [Show/hide message details.] ReferenceError: showApply is not defined

can anybody tell me whats wrong and how i can correct it ?

Vignesh Raja
  • 7,927
  • 1
  • 33
  • 42
Atul kumar
  • 69
  • 8

2 Answers2

0

Refer to: Multiple selector chaining in jQuery?

 function showApply()
 {
  $('#applyModal').modal('show');
  $('#applyModal').('#applyModaltitle').text($('#alert-heading'));
 } 

The error you get tells you that showApply doesn't exist. That is so, because there is a . (dot) operator that is wrong in this function.

You can try that:

 function showApply()
 {
  $('#applyModal').find('#applyModaltitle').innerHTML=$('#alert-heading').text;
  $('#applyModal').modal('show');
 } 
dscham
  • 547
  • 2
  • 10
0

After Searching for the answer for many answer i had found this out from one of the answer on stackoverflow .Since I'm accessing data from database generated , i have to access data through the elements from the data set displayed like from my example :-

i have displayed my data in an alert box and from alert box i have to take the required data and displayed it in the modal,in order to display the data on the modal we have to do the following :-

$(document).ready(function(){
 $('#modalname').on('show.bs.modal',function(e){
  var _button =$(e.relatedTarget);
  var info =_button.parents(".alert");
  var position=info.find(".classofelementneeded").text(); //text as i was using h5 tag for displaying data
  $(this).find("#element where you want to display data").val(position); //val because  i want to display data in text box
});
});

you can use this for displaying data from web page to modal via javascript

Atul kumar
  • 69
  • 8