[Solved] Creating a JavaScript global array with static elements?

The problem isn’t that removeFunction doesn’t have access to bigArray. The problem is in your onclick attribute, and the id you’re putting on the link: $(‘#div’).append(“<a href=”#” id=’bigArray[i]’ onclick=’removeFunction(bigArray[i])’>Element bigArray[i]</a><br />”); In the onclick, you’re referring to i, but A) I’m guessing i isn’t a global, and B) Even if it is, it will not … Read more

[Solved] Display alert if checkbox isn’t checked on button click [closed]

You need to capture the click event of your button and then check whether the checkbox is clicked or not. If not, you can send the alert and return false (be sure to do this otherwise the form will be submitted anyway). $(‘#reset’).click(function () { if (!$(‘#confirm’).is(‘:checked’)) { alert(‘not checked’); return false; } }); jsFiddle … Read more

[Solved] Passing an array from Java (JSP) to jQuery

Use a JSON library for Java. Then serialize your ArrayList to JSON: ArrayList wordslist = new ArrayList(); wordslist.add(“Hello”); wordslist.add(“again”); String json = (new JSONArray(wordslist)).toString(); Echo the JSON text at the appropriate place in your JavaScript code. E.g. $(document).ready(function(){ var arr = <%= json %>; $.each( arr, function(i, l){ alert( “Index #” + i + “: … Read more

[Solved] jQuery – Passing only certain values into a running total

I presume your full code looks something like: $(‘#table1 .set2′).each(function (idx) { total += parseInt($(this).html(),10); }); What you’ll need to do is use the mod operator like so: $(‘#table1 .set2’).each(function (idx) { if ((idx + 1) % 5 === 0 && idx !== 19)) { total += parseInt($(this).html(),10); } }); Every 5th value apart from … Read more

[Solved] jQuery return all Array [closed]

You’re overwriting templateArray in each iteration. Try .map() instead of each(): var templateArray = $.map(Basepath.Templates, function(tpl, i){ return { title: tpl.Template.name, src: ‘view/’+tpl.Template.id, description: tpl.Template.name }; }); console.log(templateArray); // now is only one array, containing template objects; 3 solved jQuery return all Array [closed]

[Solved] how to refresh a particular div content when page is loading through ajax load() function

I suggest you to use .data() method of jQuery to provide required extra info: <ul id=”nav” class=”nav” style=”font-size:12px;”> <li><a href=”#” data-url=”https://stackoverflow.com/questions/24553150/tab1.php”>Tab1</a></li> <li><a href=”#” data-url=”tab2.php”>Tab2</a></li> <li><a href=”#” data-url=”tab3.php”>Tab3</a></li> </ul> As you are using jQuery then better to use unobtrusive way of writing scripts like this: $(‘#nav a’).on(‘click’, function(e){ e.preventDefault(); $(‘.active’).removeClass(‘active’); // removes the active class from … Read more

[Solved] How do I find empty cells or cells with &nbsp in td in table and make it editable using js and jquery

Try like this .trim() will ignore the &nbsp; $(‘td’).each(function() { if (!$(this).text().trim()) { $(this).attr(‘contenteditable’, true) } }) table, tr, td { border: 1px solid #333; } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <table> <tr><td>one</td><td>&nbsp; &nbsp; &nbsp; </td><tr> <tr><td>one</td><td>&nbsp; &nbsp; &nbsp; </td><tr> <tr><td>one</td><td>&nbsp; &nbsp; &nbsp; </td><tr> <tr><td>one</td><td>&nbsp; &nbsp; &nbsp; </td><tr> <tr><td>one</td><td> </td><tr> <tr><td>one</td><td>&nbsp; &nbsp; &nbsp; </td><tr> <tr><td>one</td><td>&nbsp; &nbsp; &nbsp; </td><tr> … Read more

[Solved] Convert AJAX script to jQuery syntax [closed]

If you want all the code to be jQuery-style: $.ajax({ method: ‘POST’, url: ‘getTemplate?templateID=’ + str, dataType: ‘json’ }).done(function(data) { $(data).each(function() { $(“#messageBody”).html(this.templateBody); $(“#emailSubject”).val(this.templateSubject); }); }); solved Convert AJAX script to jQuery syntax [closed]