[Solved] how toggleClass work?

You could do something like: $(“.form-elements input[type=”image”]”).on(“click”, function() { var currSrc = $(this).attr(“src”); // check if the source ends with “_pasif.png” if (/_pasif.png$/.test(currSrc)) { // if it does, just replace it with “.png” $(this).attr(“src”, currSrc.replace(/_pasif.png$/, “.png”)); } else { // if it does not, replace “.png” with “_pasif.png” $(this).attr(“src”, currSrc.replace(/.png$/, “_pasif.png”)); } }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> … Read more

[Solved] JavaScript function not called from onclick attribute correctly

Your code doesn’t work because you have a big scope problem. onclick attributes can only target functions that are in the global scope. In your case, your function is not in the global scope. <script> $().ready(function(){ function submitDB() { alert(‘From function!’); } }); </script> should be <script> function submitDB() { alert(‘From function!’); } </script> Demo: … Read more

[Solved] how to change php functions send result to jquery ajax [closed]

right code for this <? // http://huddak.net/bbs/board.php?bo_table=cm_free&wr_id=3629 function remove_nr($str) { $reg_e = array(‘/\n/’, ‘/\r/’, ‘/\”https://stackoverflow.com/”, “/<\/script>/i”); $reg_p = array(‘ ‘, ‘ ‘, ‘\\”‘, “<\/SCRIPT>”); return preg_replace($reg_e, $reg_p, $str); } ?> <script type=”text/javascript”> $(“#test1″).html( ” <? echo remove_nr( trim( db_cache(“main_top_naver_cache”, 300, “naver_popular(‘naver_popular’, 4)”)))?> ” ); </script> you can do time consuming php code to jquery loading. … Read more

[Solved] on click, reduce countdown with 1 and so something, when countdown reaches 0 open window

This code is maybe the solution you wanted: function countdown() { var i = document.getElementById(‘counter’); if (parseInt(i.innerHTML)<=0) { $(“#counter”).fadeout(); i.innerHTML =10; i.style.width=”100%”; $(“#counter”).fadein(10); } else { i.innerHTML = parseInt(i.innerHTML)-1; setTimeout(function(){ var i = document.getElementById(‘counter’); i.style.width=”10%”; i.innerHTML=”1″; },5000) } var msg = window.open(“”, “Window name”, “width=200, height=100”); msg.document.write(“Some HTML”); } You have to add jquery in … Read more

[Solved] How to select all cell starting, containing or ending with some word with JQuery/CSS?

you can use regular expressions. These two regexp checks if text contain “John” (anywhere) and ends with “1”: $(‘#myTable’).find(‘td’).each(function() { var str = $(this).text(); if (str.match(“John”) && str.match(“1$”) ) { $(this).css(‘background’, ‘red’); // …or do something else with it. } }); 3 solved How to select all cell starting, containing or ending with some word … Read more

[Solved] Is it possible to update a textarea-element with data from an AJAX call? [closed]

You want a textarea to display the contents of logs.php, and update every 2 seconds. I think this should do it: <script> $(document).ready(function(e) { $.ajaxSetup({cache:false}); setInterval(function() { $.get(‘logs.php’, function(data) { $(‘#chatlogs’).text(data); }); }, 2000); }); </script> <textarea name=”” id=”chatlogs” style=”width:100px; height:100px”></textarea> Note you also need to add id=”chatlogs” to your textarea for this to work. … Read more

[Solved] Show calculation of textboxes with decimal using javascript [closed]

Try this: $(‘#Text4’).val(parseInt($(‘#Text1’).val()) * 100 + parseInt($(‘#Text2’).val()) + parseInt($(‘#Text3’).val()) / 10); function doCalculation() { $(‘#Text4’).val(parseInt($(‘#Text1’).val()) * 100 + parseInt($(‘#Text2’).val()) + parseInt($(‘#Text3’).val()) / 10); } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <input name=”txtArea1″ type=”text” id=”Text1″ style=”width: 20%;” /> – <input name=”txtArea2″ type=”text” id=”Text2″ style=”width: 20%;” /> – <input name=”txtArea3″ type=”text” id=”Text3″ style=”width: 20%;” /> <input name=”txtGuntha” type=”text” id=”Text4″ style=”width: 80%;” … Read more

[Solved] How to popup an alert when every cell in a table has been clicked?

If you’re wanting to set each cell to have a red background individually on click it would be done like this and will alert after all 5 have been clicked. $(‘#one, #two, #three, #four, #five’).click( function() { $(this).toggleClass(“redbg”); if($(‘.redbg’).length == 5) alert(‘Bingo!’); }); .redbg { background: red; } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <table> <tr> <td id=”one”>1</td> <td … Read more

[Solved] How to subtract two inputs with each another

<input id=”total” type=”text”> <input id=”v1″ type=”text”> <input id=”v2″ type=”text”> <button type=”button” onclick=”update()”>Update</button> <script> function update() { var total = parseInt(document.getElementById(“total”).value, 10); var value1 = parseInt(document.getElementById(“v1”).value, 10); var value2 = parseInt(document.getElementById(“v2”).value, 10); document.getElementById(“total”).value = total – (value1 + value2); } </script> Working example: https://jsfiddle.net/md9ebo00/5/ I would not suggest using onchange=”update” as an attribute for the two … Read more

(Solved) Why does jQuery or a DOM method such as getElementById not find the element?

The element you were trying to find wasn’t in the DOM when your script ran. The position of your DOM-reliant script can have a profound effect on its behavior. Browsers parse HTML documents from top to bottom. Elements are added to the DOM and scripts are (generally) executed as they’re encountered. This means that order … Read more