Leaderboard


Popular Content

Showing most liked content since 09/07/2011 in all areas

  1. 2 likes
    Like astralaaron said using closest class and the index class in jquery you can get the index of the tr, have a look at the fiddle. https://jsfiddle.net/8hL46ftj/ hope this helps $('img').click(function(){ alert($(this).closest('tr').index()) })
  2. 1 like
    Well it would help if you place the style properties within the style attribute.
  3. 1 like
    No! the PHP file in its present state should not be included in to the form page, it is AJAX specific because of the if condition, which should be access by JavaScript AJAX code that uses url to that php file to retrieve required data using server script language PHP. I don't know what jquery.js is? is it the users own custom code or jquery framework code? either way it is perfectly all right if not the norm to place js code at bottom of page, as it will help in loading of page quicker as html and css needs to loaded primarily first, and JavaScript secondary as most of the time JavaScript is triggered by events by the user after the page is fully loaded. The main problem with include ("jquery.js"); is that is needs to be within <script>...</script> tags if custom js code, OR if jQuery framework file, it should link to it, using for example <script type="text/javascript" src="jquery.js"></script>
  4. 1 like
    OK. The advantage of using AJAX is to prevent having to reload the page each time the form is submitted, and the advantage of using PHP is to insure that the submitted data is sanitized and validated. Are implying with this that it is not possible to use Javascript for the purpose of sanitization and validation? If I have understood correctly, AJAX serves only as an intermediary between the form page and the PHP page. In other words, the PHP page should be written, as if the AJAX did not exist, and the AJAX should always refer to the PHP page via the following piece of code $.ajax({ url: 'ajax_comment.php', What is more, the PHP code should only be included in the page, if the following condition is satisfied. !isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) Thus, it was wrong for Loois to have included the following code at the bottom of his form page include ("jquery.js"); Under the assumption that all of the above is correct, why is the following code not entered at the top of the form page? include ("jquery.js"); My very best, Roddy
  5. 1 like
    You should always provide a pure php script, to sanitize and validate, BECAUSE JavaScript CAN be disabled, You can use AJAX to update content, make database requests/update/insert etc without the need to reload the page constantly, which is required for pure php code to do the same thing. Usually you would not include the php script in the form page, only the AJAX JavaScript code would access it externally, to process the form data and return results to a specific location, it makes more sense this way checking with $_SERVER['HTTP_X_REQUESTED_WITH'] that it is a AJAX request. Without this it could be included in the form page, it would retrieve default information or content on loading of page, a AJAX request could be made using form using the same php script externally, the new AJAX returned results can be use to update/overwrite the default content without reloading the page.
  6. 1 like
    So, why use AJAX at all? Since AJAX depends on Javascript being turned on or off, and since this decision is made by the user-client, why not use PHP whose functioning is determined solely by the host-server?
  7. 1 like
    There is no action attribute in the following line of code <form id="form" method="post"> You must enter an URL for ajax_comment.php as the value of your action attribute in the above <form> element. <form id="form" method="post" action='pathto/ajax_comment.php'> Replace the word "pathto" with whatever is necessary to connect the document that contains your form with the document that processes your $_POST variable -- namely, ajax_comment.php.
  8. 1 like
    <form method="post" name="form_name" id="form_name" action="https://www.w3schools.com/comment.php"> <fieldset> <legend>Title</legend> <p>A brief explanation about what you would like to see entered.</p> <textarea name="comment" form="form_name" maxlength='400' rows="8" placeholder='Character Limit: 400'></textarea> </fieldset> <input type="submit" value="Submit comment"> </form> In addition you must decide what you want to do with the comments and how to process them one they are received via the post ($_POST) method at comment.php. Roddy
  9. 1 like
    The superglobal is like any other variable in the PHP process, it only exists during the time the script is running. If you want to store its value permanently somewhere you can use a database or write it to a file. If you want to store something for one user during a browsing session you can use PHP sessions.
  10. 1 like
    The PHP GD library can't open TIFF files, but it looks like ImageMagick can. If you don't have access to ImageMagick then you'll have to go through the tedious work of building a TIFF reader that parses binary TIFF files and extracts information from them.
  11. 1 like
    OR var mil = function() { var min = $('#min').val(); var sec = $('#sec').val(); var millisec = ((min * 60) + sec) * 1000; return millisec; }; $('#item_encllength').mousedown(function() { $(this).val(mil()); });
  12. 1 like
    The save() and restore() methods are useful for that. save() remembers the current state, restore brings back the state of the last save() call. ctx.save(); // Remember the current state ctx.translate(100,100); ctx.fillRect(0,0,100,100); ctx.restore(); // Return to the previous state ctx.fillRect(100,100,50,50);
  13. 1 like
    https://www.w3schools.com/php/php_file_upload.asp
  14. 1 like
    Yep. The alternative is to not list the columns in the table and only give the values: INSERT INTO table VALUES ('val1', 'val2', 'val3') But, like I said, if you ever change the structure of that table then that query is going to break if you've changed the number of columns. It's best to just list everything out explicitly. You don't have to pay per character in your source code, make the code as obvious as possible so that it's easy to maintain. Ease of maintenance should always be a higher priority than something like how long the code is.
  15. 1 like
    If you're using mysqli in PHP then you still need to write the SQL code. mysqli is just an extension for using MySQL, it's not an abstraction layer like you would get with Zend Db or something where you're building PHP method calls instead of writing SQL queries.
  16. 1 like
    I understand that an RSS feed is XML, but the links that go in that XML, the software used to create the XML, and the server security aren't related to XML. That's why I was asking why a question about directory security was in the XML forum. IIS is Internet Information Services, the Microsoft web server that runs on Windows. You didn't say what your environment was so I pointed out that URL rewriting can be done using htaccess in Apache, or another way in IIS. I assume nginx and other web servers also have a way to set up URL rewriting. Linux isn't a web server, it's an operating system, like Windows. Apache, nginx, IIS, etc are web servers. Your Linux server is probably running Apache. Yes. Like I mentioned, browsers often send partial requests for audio or video content. If you don't support that then the client will wait until the entire file finishes downloading before starting to play it. I'm not aware of a class that will do everything, when I implemented directory security and authorization through PHP I wrote that myself. Things might have changed since then. There might be something for your web server, like an Apache module, which is built to take a request and run a PHP script to handle authentication and authorization, or maybe a module that would check your database directly without going through PHP. I looked into some of those things but at the time I didn't find anything that perfectly matched what I was trying to do.
  17. 1 like
    Program files is a protected directory, did you open command prompt by right clicking it and selecting 'run as administrator'.
  18. 1 like
    No! the alt attribute is not useless, it may be useless for those with normal sight, but for those without sight who use a 'screen reader', or hard of hearing it is a necessity.
  19. 1 like
    Why use success and error ajax functions when you can use .done and .fail? .done and then you do all the checks in the php script even the return so that way you don't need to do that much of a javascript code in order to display an message. For example my way i use to display messages with jquery is very simple. For example index.php <div id="return_php" style="display: none;"></div> <form id="test"> <input type="text" name="something" placeholder="Insert something ..."> <input type="submit"> </form> <script> $('#test').submit(function(e){ e.preventDefault(); $.ajax({ url: 'path/to/something.php', data: $(this).serialize(), dataType: 'html', type: 'POST' }) .done(function(data){ $('#return_php').fadeIn(400).html(data).delay(5000).fadeOut(400); }) .fail(function(){ $('#return_php').fadeIn(400).html('Something went wrong with the ajax script !').delay(5000).fadeOut(400); }) }); </script> This way you just call the php page in which you do the checks and whatever stuff and then you echo an alert which will then be displayed into the return_php div. The .delay(5000) acts as a delay for the fadeOut function, after 5 seconds the message will fade away. something.php $something = $_POST['something']; if(empty($something)) { echo "Something needs to be filled in !"; //This message will be then returned into the div return_php on the index.php page } else { //Example of database try { $sql = "SELECT something FROM something WHERE something = :something"; $stmt = $db->prepare($sql); //$db is from a config file you have to include $stmt->bindParam(":something", $something); $stmt->execute(); $rowCount = $stmt->rowCount(); //This works for every case, at least i use it this way and for me works just fine. if($rowCount > 0) //let us presume that the something has more rows { echo "Ok, there is something in that something !"; } else { echo "There is nothing in something with the something you typed !"; } } catch (PDOException $e) { echo "Error: " . $e->getMesage(); //This will be showed into the return div aswell as the echo is still a part of this page, and this page is called by ajax. } } Now, this is my way to do it time to time when i need live php script calling on my page without needing my page to refresh. Hope it helped at least for your issue with displaying messages. EDIT I've read again through your post and i think i figured out what is all about. When i try to use that ereg_replace() php function is always throwing me an Uncaught error as the function doesn't exist. This may be influencing how you are selecting the data by that variable. Instead of ereg_replace use preg_replace, It does the same thing. $email = $_POST['email']; $email = preg_replace('/\s+/, '', $email); NOTE! Some of the code i wrote may or may not fit your code if you copy paste it as it doesn't contain the same variables or functions that you wrote. You may need to adapt it to your use.
  20. 1 like
    When you're printing each field you can check if the field ID exists in $non_matches, and style the element appropriately. I'm just suggesting that it is more efficient to print everything correct in the first place, versus printing everything then trying to run client-side code to show errors or whatever else.
  21. 1 like
    You can use scandir() to list files in a directory and generate the HTML for the images. The line breaks exist, but HTML doesn't render line breaks unless you specifically put a <br> element. You can use nl2br() to show line breaks in the text provided by users. You can't choose the size of a file, but you can give a size limit in the file uploader. There are plenty of PHP file upload tutorials, you should look at some of them. The W3Schools tutorial has sections explaining how to limit the file size and file type. You can use str_replace() to change substrings into something else, such as in the following example: <?php $string = str_replace(':)', '<img src="smiley.gif">', $string); ?>
  22. 1 like
    Store the completed state of the form in the session, then check whether the session value is set before showing the panel. You can do this in Javascript with localStorage, sessionStorage or cookies. You can do it in PHP using sessions or cookies.
  23. 1 like
    Are you running the first cron job with the colons? /usr/local/cpanel/bin/jailshell: -c: /home/my_username/public_html/folder/file.php" Try removing the colons and also the double quote at the ends of the cron jobs.
  24. 1 like
    If they are child element of parent div, you need to add space before child elements. $( id + 'textarea') will look for an element with id '#letter_abstracttextarea' $( id + ' textarea') = '#letter_abstract textarea' will look for child textarea element whose parent element has this specific id.
  25. 1 like
    Depending IF the poster is already using jquery as all i see is plain vanilla JavaScript code, that would overkill just for one small line of code.
  26. 1 like
    IF you stringify the array you will simply get [ "AAAAAA" ] for single array value [ "AAAAAA","BBBBBB" ] for two array values, JSON.stringify(lsData) converts to ' [ "AAAAAA","BBBBBB" ] '. While when you use lsData = JSON.parse(localStorage.getItem("desSet"));it converts it back to a readable array of values with lsData[0] equallying "AAAAAA" and lsData[1] equallying "BBBBBB", that is what the loop does starting from 0 to less than total number of values (2) meaning 1.
  27. 1 like
    You will need an array to store the values, on page load you will check localstorage to see if values already exist, if yes, update the array with these values, then as more values are submitted, add to array and localstorage.
  28. 1 like
    If you're sending string values in the URL then you'll also want to use the encodeURIComponent function to make sure the values don't break the URL. Otherwise, if you're sending a lot of data you'll probably want to just switch to a post request instead of a get request.
  29. 1 like
    Misplaced ',' instead of ' ' in margin styling, and ending semi-colon ';' for 'src = val' document.getElementById('btn').onclick = function() { var container = document.createElement("div"); container.style.maxWidth = "270px"; /* just for testing purposes dsonesuk*/ container.style.backgroundColor = "red"; /* just for testing purposes dsonesuk*/ container.style.display = "inline-block"; /* just for testing purposes dsonesuk*/ container.style.verticalAlign = "top"; /* just for testing purposes dsonesuk*/ //image var val = document.getElementById('idImage').value; var img = document.createElement('img'); src = val; /* replaced ',' with ';' dsonesuk */ img.src = src; //document.body.appendChild(img); img.style.width = "150px"; img.style.height = "150px"; img.style.padding = "10px"; //img.style.float = "left"; img.style.margin = "0px 50px"; /* removed ',' dsonesuk*/ //description var valDes = document.getElementById('idDes').value; var des = document.createElement('p'); var tex = document.createTextNode(valDes); des.style.display = 'block'; des.style.backgroundColor = "green"; /* just for testing purposes dsonesuk*/ /* des.style.top = '0px'; des.style.left = '0px'; removed because obsolete without position used dsonesuk*/ des.style.height = "160px"; des.style.padding = "10px"; des.appendChild(tex); //also tried tex.appendChild(des); container.appendChild(img); container.appendChild(des); //container.appendChild(tex); also tried this document.body.appendChild(container); }; With css and class Name <style type="text/css"> .img_descrip_wrap { display: inline-block; max-width: 270px; vertical-align: top; } .img_descrip_wrap img {width:150px; height: 150px; padding:10px; margin: 0 50px; display: block;} </style> document.getElementById('btn').onclick = function() { //image var container = document.createElement("div"); container.className = "img_descrip_wrap"; var val = document.getElementById('idImage').value; var img = document.createElement('img'); src = val; img.src = src; //description var valDes = document.getElementById('idDes').value; var des = document.createElement('p'); var tex = document.createTextNode(valDes); des.appendChild(tex); container.appendChild(img); container.appendChild(des); document.body.appendChild(container); };
  30. 1 like
    Here's how you created nested elements: /* Create a container */ var container = document.createElement("div"); /* Create children */ var image = document.createElement("img"); //... Set attributes var paragraph = document.createElement("p"); // ... Set attributes and content /* Add children to the container */ container.appendChild(image); container.appendChild(paragraph); /* Add the container to the body */ document.body.appendChild(container);
  31. 1 like
    You should get in the habit of structuring your code like Ingolme mentions. Put your PHP code first that will decide what the page is even going to do, and output HTML and whatever later on. If you're just going to redirect there's no reason to output a bunch of HTML anyway, right? So figure out first if you're going to redirect or show HTML or whatever else, and then do that.
  32. 1 like
    You can store the query results in a multidimensional array check this https://www.w3schools.com/php/func_array.asp "example 4" you can then return the array .
  33. 1 like
    Use block elements, or turn them into block elements using display: block; or display: inline-block;
  34. 1 like
    Any inline element, or block element using display: inline; turning it into a inline element will not respond to width, height applied, its width will be determined by content within it.
  35. 1 like
    header > h1, header > p{ color:red; } /*OR*/ header > h1, header > h1 + p{ color:red; } /*Give header class name */ .colour_version01 {color:red;} <header class="colour_version01"> <h1>Some text</h1> <p>Some more text</p> </header>
  36. 1 like
    That would be fine if you were coding for a website, but HTML emails need to be simple. if you want it random, you'll have to create several different images with the pictures in different orders.
  37. 1 like
    If you check the network tab of your browser's developer tools, each time you click a color you'll see a request go out for an image. Here's one of them. http://hanes.scene7.com/is/image/Hanesbrands/HNS_HO5944_ChiliPepperHeather?defaultImage=Hanesbrands/HNS_HO5944_AwesomeBlueHeather&id=Cd9S33&wid=490&hei=622&fmt=jpg
  38. 1 like
    Instead of individual ref for each, use the actual innerhtml text as the complete src ref $(this).next('img').attr('src', "http://placehold.it/400x150?text=" + $(this).html()); Equals repeating duplicate of text in src of image Equals the value that defines the complete src reference <span class="fruit">apple</span> <img src=""> <span class="fruit">orange</span> <img src=""> <script type="text/javascript"> $(function() { $('.fruit').each(function(i) { $(this).next('img').attr('src', "http://placehold.it/400x150?text=" + $(this).html()); /* if (document.getElementById("fruit").textContent == "orange") { document.getElementById("img").src = "http://placehold.it/400x150?text=orange"; } else if (document.getElementById("fruit").textContent == "apple") { document.getElementById("img").src = "http://placehold.it/400x150?text=apple"; } else if (document.getElementById("fruit").textContent == "pear") { document.getElementById("img").src = "http://placehold.it/400x150?text=pear"; }*/ }); }); </script>
  39. 1 like
    An id reference must be unique within a page, only class names can be used multiple times, so you would have to loop through classnames and make changes to next sibling img src attribute.
  40. 1 like
    First of all you can't have multiple id references, or spaces within id value, and as id must be unique within a page, you have to clone a element with unique id and temporarily apply it to variable, then remove original, then prepend temporarily cloned to a surrounding container which would make it easy to control placement and order. But first you will need an array that will store id references, that do not currently exist, in order they were selected, then looping this array you can temp clone, remove original, prepend clone.
  41. 1 like
    Buttons are inline elements, so they need to be centered by setting text-align on the parent element.
  42. 1 like
    .form-actions {width:200px; margin-left:auto; margin-right:auto; text-align:center;}
  43. 1 like
    Because they show as the order they are laid out from the beginning. There are several ways to do this, but will involve cloning the current hidden divs, in the order they were selected, removing the original hidden selected and then appending cloned divs in correct selected order.
  44. 1 like
    Events like these are applied to elements on loading of the page, if you place them in a function you apply the exactly the same event with same outcome again everytime the function is called, very inefficient, generally if these are placed in function you are doing it wrong. You don't even require the function, you just need to target the parent and then the newly created class references. function addFlowLine() { var table = document.getElementById("query_content_unexe"); var row = table.insertRow(0); row.insertCell(0).innerHTML = '<button class="up">up</button>'; row.insertCell(1).innerHTML = '<button class="down">down</button>'; row.insertCell(2).innerHTML = 'add'; } $("#unexe_table").on("click", ".up, .down", function() { var row = $(this).parents("tr:first"); if ($(this).is(".up")) { row.insertBefore(row.prev()); } else { row.insertAfter(row.next()); } });
  45. 1 like
    Hi Joymis, as Ingolme said the event is being added every time the new row is added. Here is the fix - https://jsfiddle.net/rockey91/8zzq635c/
  46. 1 like
    Every time you create a new row you're adding another event handler to all the rows. The newest row will have just one event handler, but the older rows will have as many event handlers as times you've clicked the "new" button.
  47. 1 like
    It's common to put basic configuration in an include file. You'll need an include file anyway for database connection details, so you can either add your other config options to the file or you can save them in the database and then have a GUI in your program to change them. If you want people to be able to log in and change various settings, those settings should go in a database. If they can't be changed by people using the program then they go in an include file.
  48. 1 like
    I don't think that it would be a bad thing personally, as a lot of popular frameworks like Angular 2 and React are using ES6 and TypeScript in their tutorials and so are a lot of the blogs and guides. That said, there will still be the requirement of needing a transpiler for the time being but, I certainly think there are lots of tutorials and guides around that too, however, at the risk of linking people off site to other tutorials (for Babel, TypeScript, Webpack, Gulp, etc) I could see W3Schools being hesitant in that regard as well. Either way, I firmly encourage any intermediate JS developer to start learning ES6 features now and consider taking the extra time to learn how to transpile that source code down to ES5 compatible JS. New features, like imports have fundamentally helped changes the language (for the better IMO) and I think the resulting source code is better for it too.
  49. 1 like
    <?php $book = array( "Language" => array("English", "Franch", "Arabic"), "Programming" => array("PHP", "JAVA", "C++"), "Science" => array("Physics", "Geography", "Math"), ); $classRef = ""; $keysvalues = array_keys($book); echo '<ul>'; for ($i = 0; $i < sizeof($book); $i++) { $classRef = str_replace(" ", "_", strtolower($keysvalues [$i])); echo '<li class="' . $classRef . '">' . $keysvalues [$i]; echo '<ul>'; foreach ($book[$keysvalues [$i]] as $value) { echo '<li>' . $value . "</li>"; } echo '</ul>'; echo "</li>"; } echo '</ul>'; ?>
  50. 1 like
    Please PM me or the other moderators for suggestions about this topic. The topic will be locked to avoid clutter.This topic will provide some links to common tutorials, references, articles and downloads related to web servers.Check the posts below for further information.