0

Hi Im trying to call a javascript function from within a div function

Bascially I have a filter box which adds a bootstrap alert to a textbox and this works perfectly, the issue is when I click the close button on the alert it is not running the specified function and i dont know why

This is the routine which adds the alert to the text box, in it I specify the javascript function to run and 3 variables. the function clear does not seem to get called

//Add Filter on " Add Filters" button click
$("#filter2-add").click(function(){
           table.addFilter($("#filter2-field").val(), $("#filter2-type").val(), $("#filter2-value").val());

         var div = document.getElementById('appliedfilters');
           div.innerHTML += '<div id="'+$("#filter2-field").val()+$("#filter2-value").val()+'" style="width:500px; height:20px;text-align: left;display:inline-block;vertical-align: middle;line-height: normal;" class="alert alert-success alert-dismissible"><a href="javascript:clear(\''+$("#filter2-field").val()+'\',\''+$("#filter2-type").val().charCodeAt(0)+'\',\''+$("#filter2-value").val()+'\')"; class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Filter  </strong>'+$("#filter2-field").val()+' '+$("#filter2-type").val()+' '+$("#filter2-value").val()+'</div>';
            });
1
  • Essential information is missing from your question, while there's tons of irrelevant stuff. Briefly, javascript:functionName() will call the function named functionName that is defined in the global scope - can confirm that it works. In your code, where is the definition of clear? Please edit your question by removing everything that does not influence the behaviour that you are seeing, format the code and include enough code so that the definition of function clear is visible, otherwise it's not possible to help you. Commented Oct 6, 2019 at 13:54

1 Answer 1

1

I think your code has a syntax error. Try replacing

div.innerHTML += '<div id="'+$("#filter2-field").val()+$("#filter2-value").val()+'" style="width:500px; height:20px;text-align: left;display:inline-block;vertical-align: middle;line-height: normal;" class="alert alert-success alert-dismissible"><a href="javascript:clear(\''+$("#filter2-field").val()+'\',\''+$("#filter2-type").val().charCodeAt(0)+'\',\''+$("#filter2-value").val()+'\')"; class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Filter  </strong>'+$("#filter2-field").val()+' '+$("#filter2-type").val()+' '+$("#filter2-value").val()+'</div>';

with

div.innerHTML += '<div id="'+$("#filter2-field").val()+$("#filter2-value").val()+'" style="width:500px; height:20px;text-align: left;display:inline-block;vertical-align: middle;line-height: normal;" class="alert alert-success alert-dismissible"><a href="javascript:clear(\''+$("#filter2-field").val()+'\',\''+$("#filter2-type").val().charCodeAt(0)+'\',\''+$("#filter2-value").val()+'\');" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Filter  </strong>'+$("#filter2-field").val()+' '+$("#filter2-type").val()+' '+$("#filter2-value").val()+'</div>';
Sign up to request clarification or add additional context in comments.

1 Comment

Tom thank you so much, ive spent hours on that and you have fixed it in 8 mins

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.