Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by phdphd

  1. Hi all. I want to print a specific div when a button linked to it is clicked. Here is the code that works, even in Opera : function printContent(el){ var restorepage = document.body.innerHTML; printcontent=document.getElementById(el).innerHTML; document.body.innerHTML = printcontent; window.print(); document.body.innerHTML = restorepage; } However I want to add an image and some text before the content of the div. Here is the code that does not work in Opera : function printContent(el){ var restorepage = document.body.innerHTML; var printcontent = '<center><img alt="logo" src="image.jpg" height="160" width="240" /> BLABLABLA<br></center>'; printcontent+=document.getElementById(el).innerHTML; document.body.innerHTML = printcontent; window.print(); document.body.innerHTML = restorepage; } If I add just text instead of an image, the script runs normally. Thanks for your help.
  2. Sorry, Barand, I was so pleased to learn your "super-fancy one-liner" "showing off" new stuff to me .
  3. Both approaches are OK for me, since they yield more or less the same performances against a 30k-row table.
  4. I got it $input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $tosearch='Tot'; $output_table = array_filter($input_table, function($v) use ($tosearch){return stripos($v, $tosearch)!==false;}); var_dump($output_table); Result : array(4) { [1]=> string(4) "toto" [2]=> string(4) "tota" [4]=> string(4) "TOTO" [5]=> string(4) "toto" }
  5. Thank you. It works great. However, it does not work when using a variable as the string to look for (here "$to_search"): $input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $to_search='Tot'; $output_table = array_filter($input_table, function($v){return stripos($v, $to_search)!==false;}); var_dump($output_table); I get array(0) { }
  6. Hi All, I want to copy into a table values from another table that partially match a given value, case-insensitively. So far I do as follows but I wonder whether there is a quicker way. $input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $input_table_2 = array_map('strtolower', $input_table); $value_to_look_for='Tot'; $value_to_look_for_2=strtolower($value_to_look_for); $output_table=array(); foreach ($input_table_2 as $k=>$v) { if(false !== strpos($v, $value_to_look_for_2)) { $output_table[]=$input_table[$k]; } } One drawback is that $input_table_2 is 'foreached' whereas there might be no occurrences, which would lead to a loss of time/resources for big arrays. Thanks.
  7. Thanks a lot, CroNiX, it is working. Now the beginning of the JS looks like this (the only change is the insertion of "$('#some_other_input_id').val(ui.item.id);": jQuery(document).ready(function(){ $('#input_id').autocomplete({source:'my_jquery_suggest.php', select: function(event, ui) { $(event.target).val(ui.item.value); $('#some_other_input_id').val(ui.item.id); $('#form_id').submit(); return false; }, minLength:2,delay: 1000}).focus(function () { window.pageIndex = 0; $(this).autocomplete("search"); });
  8. Thanks again. As for the plugin I guess you mean jQuery UI 1. 8.18. I am going to investigate your solution right know.
  9. Thank you for answering and for your suggestion. Sorry, I am using jquery-1.7.2.js. Regards.
  10. Hi All, I have a form with a jquery autocomplete input field. Once the user has entered 2 characters, there is a list of values (people names) containing this string that appears. This works good. The values come from a database table with two fields (names and ids). The query that extracts the names also retreives the values in the id field. What would be the syntax to set the "value" attribut of the input tag to the id of a name when the user clicks on that name in the list? The PHP part that builds the json is : $data[] = array( 'label' => $row['name'], 'value' => $row['name'], 'id' => $row['id'] ); echo json_encode($data); The JS begins as follows : jQuery(document).ready(function(){ $('#input_id').autocomplete({source:'my_jquery_suggest.php', select: function(event, ui) { $(event.target).val(ui.item.value); $('#form_id').submit(); return false; }, minLength:2,delay: 1000}).focus(function () { window.pageIndex = 0; $(this).autocomplete("search"); }); ... Thanks for your help.
  11. Hi All, I have a form that enables the user to know events that occur in a specific city. Most of the time they get the results in a few seconds, despite the fact that many rows in various tables might be searched for detailed infos about the events in that city. However, this form partly relies on a table against which a MySQL event regularly does some operations. If the user uses the form while the event is being executed, they have to wait up to 30 seconds before getting the results, and sometimes only part of the html page is generated. Is there a way to avoid this lengthy waiting time ? I am wondering whether or not the best would be putting the site on maintenance while the event is being executed, with a "please come back in a few minutes" message. Thanks in advance for your help.
  12. Hi All, I have a problem with masonry. I initially have a scrollable area that contains DIVs with fixed width. Each DIV contains info about an event, and consists of two DIVs, an upper one, and a lower one. When the user has JS enabled, only the upper one part displays. They can display the lower DIV by clicking a plus sign. Without masonry, this clicking operation will create a blank area. I woud like to get rid of this blank area. I tried to implement masonry, but the result is that when the lower part of a div is displayed, it overlaps the upper part of the div below it. At this stage I defined no options for masonry. I just installed masonry.pkgd.min.js and add class="js-masonry" to the scrollable area. Thank you for your help !
  13. Hi All, I have an html input tag with an associated jquery autocomplete feature. So far, I have been using the following jQuery setting : jquery-1.9.1.js http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js Now, since the list may contain a lot of items and take some time to load if the user types a string that appears in many items, I want to associate an infinite scroll with the autocomplete feature. The infinite scroll would load items 5 at a time when the user scrolls the list down. I found a jsfiddle (http://jsfiddle.net/EVsye/83/) based on a previous jQuery setting (jquery 1.7.2, jquery UI 1.8.18) that illustrates this feature. I tried to update this jsfiddle to my jQuery setting. However there are 2 issues : 1. The user cannot select an item in the list. 2. Items beyond the 5th one seem to have no css applied to them (they are not aligned to the first 5 ones and the mouseover formatting has no effect on them). I would much appreciate your help. My jsfiddle : http://jsfiddle.net/Lp6zP/ Thanks!
  14. Hi All, I have found an interesting source about computing the shortest route given any given number of points, here. However it takes too long above 7 points (around 4 seconds with 7 points, more than 30 sec with 8 points). Does anyone know a quicker solution ? Thanks!
  15. Hi All, I am trying to find a way to hide the Browse button when the user checks a box. I found the solution when the page has just one pair of browser button/checkbox (http://jsfiddle.net/xSvLc/53/). However since the PHP-generated form is likely to contain multiple browser button/checkbox pairs, I do not know how to implement the JS function in this situation. I tried to (http://jsfiddle.net/xSvLc/58/), but it does not work. Thanks for your help ! PhD
  16. Hi All, Is recreating an uploaded image an efficient way to protect it against a potential virus ? I came across this solution at the following address : http://security.stackexchange.com/questions/26690/use-php-to-check-uploaded-image-file-for-malware at the paragraph starting with "Best I can think for PHP is to re-create the image". Thanks
  17. I nearly found the solution by replacing the while loop contents with the following var str1 = suggestions[i]; var str2 = beginning; var str2 = str2.replace(/\*/g, ""); var re = new RegExp(str2,"i"); if (str1.search(re) == -1) { correct = 0; } However there is still an issue with the * character. If the user types "*", all the suggestions are displayed. Without the line "var str2 = str2.replace(/\*/g, "");", If the user types "*" no suggestion is displayed, but if they type any character followed by "*", then all the suggestions are displayed. I also noticed some similar issues with the use of "?". What I want is to avoid the displaying of all the suggestions if wildcards are typed, or to have them processed as normal characters. Thanks for your help.
  18. Thanks for your answer. I managed to solve it, but still have 2 problems after having implemented case-insensitiveness. The getWord function now looks as follows : function getWord(beginning) { var words = new Array(); for (var i=0;i < suggestions.length; ++i) { var j = -1; var correct = 1; while (correct == 1 && ++j < beginning.length) { if (suggestions[i].indexOf(beginning.toLowerCase()) === -1) { if (suggestions[i].indexOf(beginning.toUpperCase()) === -1) correct = 0; } } if (correct == 1) words[words.length] = suggestions[i]; } return words; } Assuming the "suggestions" are ["Hello","World","Hello World","hELLO"], the issues are : 1. Any string representing 2 beginning letters, whatever their case, will match no results. For example, "HE", "He", "hE", "he" do not match "Hello", neither "hELLO", nor "Hello World", whereas "lLo" will match the three of them. 2. " w" and " W" will match "Hello World", but "o W" will not. Any idea of how to solve these issues ? Thanks!
  19. Hi All, I have found an interesting autocomplete js code at http://hscripts.com/scripts/JavaScript/autocomplete-form.php that works without jQuery and grabs data from a php array. I managed to have the data extracted from a database first and I am using the following piece of PHP code inside the JS suggestions variable to feed this variable : $tmp = Array(); foreach($tab as $k=>$v) { $tmp[] = '"'.addslashes($v).'"'; } echo join(',', $tmp); I use addslashes because I noticed that the autocomplete does not work if one of the retreived words contains a double-quote. Is this enough to protect JS coding ? I also would like to make this JS code search for the typed characters at any position in the strings (not just from the beginning). Is this feasible ? Thanks! PS/ I also made the JS case insensitive by applying the following tip : http://www.vonloesch.de/node/18#comment-2832
  20. Hi All, The heredoc syntax enables to put some text in a variable for future reuse. For example : $my_var = <<<EOD The colour is red. EOD; echo $my_var; will result in "The colour is red". So far so good. Now let's assume the following: $colour="red"; $my_var = <<<EOD echo 'The colour is '.$colour; EOD; echo $my_var; Unfortunately the result will be "echo 'The colour is '.red;". In this situation, is there a way to tell php to just put "The colour is red" into the $my_var variable ? Or is there an alternative to heredoc ? Thanks!
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.