Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. Due to security restrictions, browsers do not give Javascript access to the user's filesystem. Any information about the filesystem could be used by hackers to take control of the user's computer.
  2. You should be listening for form events instead of key events or click events. What's important here is that somebody is attempting to submit the form. (function(){ var form = document.getElementById("letter_searchform"); var input = document.getElementById("letter_input"); form.addEventListener("submit", search, false); function search(e) { // Stops form submission regardless of whether it was a click or a key event e.preventDefault(); // If the input is empty, return var search_podcast_input = input.value; if (search_podcast_input == "") { $("#podcast_input_error").show().append('<br />'); $("#podcast_input").focus().focusout(function() { $("#podcast_input_error").hide(); }); return false; } // Send an AJAX request var dataString = 'search_input=' + search_podcast_input; $.ajax(); } })();
  3. If you're saying you have 26 sets of numbered variables, there is no way that using arrays would be more complicated or take up more memory. Arrays are structures specifically designed to simplify tasks of this nature. If you don't fix your data structures now, you're going to run into plenty more barriers of this kind where you're forced to write the same line of code over and over with a different number in each line. Yes, it's going to take some more work to replace your current code with arrays, but if you don't do it now, you'll inevitably have to do it later. The longer you wait the more difficult it will be to change your whole program. You're better off fixing it now before your program gets too much more complicated.
  4. This is what arrays were made for. Instead of naming variables bright1 or bright13, use an array bright[1] and bright[13]. I don't know where the variables are being set, but you'll have to change that block of code as well. Arrays start at index zero, so take that into account. Using arrays, the result would be like this: var canvas; for (i = 0; i < 14; i++) { canvas = document.getElementById('canvas' + (i+1)); canvas.style.filter = "brightness(" + (bright[i] -= 10) + "%) contrast(" + (cont[i] -= 10) + "%)"; } What is the "-=" for? You're modifying the variable itself, which means after you;ve used it it will be 10 less than before. You can use just a "-" to subtract 10 without changing the value of the variable.
  5. I've rewritten the code from your most recent post to clearly distinguish the steps your program is taking. What I find is that the click event you're using is assigning a value to a variable named "data" but is never actually using that variable. Your program would not behave any differently if you deleted all those 12 lines of code. I don't know which text field you want to register the key event one, so I've left "#id_of_element" as a placeholder. Please try to describe in short simple steps what exactly is supposed to happen when the link is clicked. /* Core logic */ $discover = $("div.discover"); // Store a reference to the element for faster access /* Assign all event handlers outside of functions, otherwise things get messy and you will end up with duplicated event handlers on the same element */ $discover.click(beginSlide); $discover.mouseup(returnToNormal); $("#id_of_element").keyup(somethingAboutData); $('.podcast_link').find('a').click(somethingAboutData); // The following events could easily be replaced by pure CSS: $discover.mouseover(highlight); $discover.mouseout(unhighlight); /* Function declarations */ function highlight() { $(this).find("span.discover_text").css({"cursor": "pointer","line-height":"1.6em","font-size":"1.4em"}); } function unhighlight() { $(this).find("span.discover_text").css({"cursor":"auto","line-height":"1.6em","font-size":"1em"}); }; function beginSlide() { $(this).next("div.hidden_info").slideToggle(800); $('body, html').animate({scrollTop: $(this).offset().top}, 800); } function returnToNormal() { $(this).css({"color": "#ccc", "font-weight": "normal"}); } function somethingAboutData(event) { // For the keyboard event, only do something if the key code is 13 if(event.type == "keyup") { if(event.keyCode != 13) { return; } } var $link; if(e.type == "keyup") { // This is the links that you want to click $link = $('.podcast_link').find('a'); } else { $link = $(this); } /* The following logic does not do anything, it assigns a value to the data variable, but that variable is not being used anywhere. */ var attribute = $link.attr('href'); var href_arr = attribute.split('?'); var query_str = href_arr[1]; var pairs = query_str.split('&'); var data = []; $.each(pairs, function(i, v){ var pair = v.split('='); var key = pair[0]; var value = pair[1]; var data_arr = [key, value]; data.push(data_arr); }); /* I assume that by clicking on the link, you mean redirecting the page to the value in its href attribute */ if(event.type == "keyup") { location.href = $link.attr('href'); } }
  6. I don't see a keyup event anywhere in that code.
  7. I can change the width of the input in Chrome, but it seems the submit button remains below. It's not behaving the usual way, but I just found that the parent element has display: flex. That would explain the unusual behaviour and why 100% width is working in Firefox. Since form inputs are very tricky to style, I would recommend not making them direct children of a flex object and instead wrapping each one in their own container. The parent element would have "display: flex" as it is now, but the children are now <div> or <span> elements that contain your inputs, you can set the flex property for each of these.
  8. I'm surprised that it's lining up in Firefox at all. You've set the width to 100%, which means you're telling it to be as wide as its container, leaving no horizontal space for the button to stay next to it. The best solution would be to set the width to something like 80% and give the button a complimentary width, maybe around 18% to leave space between the two. The margins will need to be percentages to to make sure the total does not exceed 100%. You will need to apply box-sizing: border-box to these elements to make sure that their borders don't interfere with the width.
  9. If the database has rows containing "coffee / tea" in the sub_category field and the code is exactly as you presented, then the issue has to be occurring either where the variable was set, or in the code that loops through query results. Start by verifying that $var has the data you expected it to at the moment the query runs.
  10. I can't help you solve the problem if I don't know even what the problem is. Here is what you said: You mentioned a potential cause of the problem, but you didn't tell me what the problem actually is. I need to know at least two things about your problem: The behavior you expect from your code What your code is actually doing A problem only exists if the actual behavior does not match the expected behavior.
  11. I don't find it unreasonable for somebody to join a forum belonging to a website and expect the website's owners to be actively participating. W3schools is actually an anomaly in this regard.
  12. <input type="submit" value="Enviar"> That's all you have to do.
  13. You can use the condition `created_on` < DATE_SUB(NOW(), INTERVAL 3 HOUR). It uses the DATE_SUB() function.
  14. I don't have time to verify that this actually will solve the problem at the moment, but even if it's wrong it might help you get on track to finding the correct solution. SELECT t1.FeeRef, SUM(t2.Amount) AS Summation FROM table AS t1 LEFT JOIN table AS t2 ON t2.ParentFeeRef = t1.FeeRef WHERE t1.CreditType = 0 GROUP BY t2.ParentFeeRef Edit: Well, this will actually only work for one level of nesting. For an unspecified number of levels of nesting it's going to be somewhat more complicated, it might involve subqueries.
  15. The type attribute has to be "submit", because that's what tells the browser how it works. The value attribute contains the text in the button.
  16. The code you presented is trying to create a table with two fields, each of type "VARIABLES," but "VARIABLES" is not a valid data type. My guess is that whoever wrote the query intended to write VARCHAR.
  17. You can remove the shadows from the buttons by setting the border width to zero. You can make all the buttons the same width by setting their width property. You can choose the spacing between lines using the line-height property, if you want to reduce the spacing, remove the margins from your buttons. You should check the CSS reference page to look for properties that might solve your problems whenever you have a question.
  18. A slash should not cause any problem. Have you checked to see what the error message was when you tried a slash?
  19. To build a more complex program out of a lot of simpler parts, you first make a general outline of what the program should do as a collection of simpler steps. The following list is probably similar to the structure of the program you want to make, but you can tweak it if necessary: 1. If the form was submitted: 1.1 Collect the form data 1.2 Validate the form data 1.3a If the form data is valid: 1.3a.1 Save to database 1.3a.2 Redirect to another page 1.3a.3 End 1.3b If the form data is not valid: 1.3b.1 Show error messages 2. Show the form Now, for each step in the list you can write the PHP code for that step. This example uses just one form field for demonstration: <?php // 1. If the form was submitted if(!empty($_POST)) { // 1.1 Collect the form data $first_name = isset($_POST['first_name']) ? $_POST['first_name'] : ''; // 1.2 Validate the form data $is_valid = true; $errors = []; if(strlen($first_name) < 2) { $is_valid = false; $errors[] = 'First name is too short'; } // 1.3a If the form data is valid: if($is_valid) { // 1.3a.1 Save to database $pdo = new PDO("..."); $stmt = $pdo->prepare('INSERT INTO `table` (`first_name`) VALUES(?)'); $stmt->execute([$first_name]); // 1.3a.2 Redirect to another page header("Location: http://example.com/complete.php"); // 1.3a.3 End exit; } else { // 1.3b If the form data is not valid: // 1.3b.1 Show error messages echo 'Form errors:'; echo '<ul>'; foreach($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } } // 2. Show the form ?> <form method="POST"> ... ... </form>
  20. If you want to generate a chart from real data you're going to need a programming language. Browsers have Javascript built in, but you could also generate it using a sever-side language. With HTML, CSS and SVG on their own, all you can do is manually "draw" the shapes using SVG elements or HTML elements styled with CSS.
  21. You must make your HTML valid before you can begin to solve any other problems. You cannot build a website on an unstable foundation. You need to learn how to break down problems into simpler components. Here are some of the properties of the feature you want to create: 1. It's animated. Therefore you have to use the CSS animation property. 2. It does not affect the positioning of any other elements on the page, therefore it's position will have to be absolute or perhaps fixed, depending on how you want it to behave. 3. It's behind everything else, so it will need a negative z-index. Each of these things is something easy to create on their own, building the whole thing is just a matter of building a whole lot of small easy things. I haven't listed all the properties, it's up to you to define your objective in as much detail as possible before starting to write any code.
  22. No, you do not want to call the functions right away, you just want to give a reference to them so that they can be called when the event happens.
  23. Put the video inside the box. Set the video's position to absolute. Set the video's z-index to -1. Set the box's position to relative. Set the box's overflow to hidden.
  24. Ingolme

    please help

    Could you rephrase the question?
  25. Try debugging to determine whether the issue is with the event not firing or whether the click() method isn't working by first verifying that you can get the key event to work on its own. You should be able to capture key events anywhere on the page by putting the event listener on the document object. Why do you want to click a button with a key event? If the button is triggering an event handler, you can call that event handler directly from the key event instead of using the button as a middle-man. If the button is submitting a form, you can call the form's submit() method from the event handler instead.
×
×
  • Create New...