Jump to content

davej

Moderator
  • Posts

    3,988
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by davej

  1. So you have elements that you click on which have content that you want to replace. That is a fairly vague description. Where does this new content come from? Is it unique for each clicked item or all the same? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <title>title</title> <style> #wrapper{ text-align:center; width: 300px; } #wrapper,h3 { border:1px solid red; border-radius:10px; } .highlight{ background-color: #ff0; } h3{ cursor:pointer; } </style> <script> window.onerror = function(a,b,c){ alert('Javascript Error: '+a+'\nURL: '+b+'\nLine Number: '+c); return true; } </script> <script> 'use strict'; window.onload = init; function init() { document.getElementById('wrapper').addEventListener("click", replaceContent); // or document.getElementById('wrapper').onclick = replaceContent; } function replaceContent(evt){ var ele = evt.target; var cla = ele.className; if (cla.indexOf('clkchg') != -1 && cla.indexOf('highlight') == -1){ var d = ele.getAttribute('data-new'); ele.innerHTML = d; ele.className += ' highlight'; } } </script> </head> <body> <div id="wrapper"> <h3 class="clkchg" data-new="This is the new content for A.">This is original content A.</h3> <h3 class="clkchg" data-new="This is the new content for B.">This is original content B.</h3> <h3 class="clkchg" data-new="This is the new content for C.">This is original content C.</h3> <h3 class="clkchg" data-new="This is the new content for D.">This is original content D.</h3> </div> </body> </html>
  2. davej

    HTML5

    As Dsonesuk says, in the traditional webpage operation you would submit a form to the server and then load another page with the results obtained from the server. A newer approach is to not use a form, but instead to use Javascript to communicate with the server in a background operation generally known as AJAX. Then there are the people who say that both methods should be used, with the form being the fallback method if Javascript has been turned off by the user.
  3. davej

    HTML5

    A form is something that you use to enclose and identify a set of inputs that are going to be submitted to the server. A div is merely an enclosing block element that can be used for structure and/or to identify a certain part of a page.
  4. <?php // make connection to database // (not shown) $sql = "SELECT id_nr, name FROM mytable;"; if ($stmt = $conn->prepare($sql)) { //$stmt->bind_param('i', $id_nr); // nothing to bind $stmt->execute(); $stmt->store_result(); $num_of_rows = $stmt->num_rows; $stmt->bind_result($id_nr, $name); echo '<table style="border:1px solid #555">'; echo '<tr><th>id</th><th>name</th></tr>'; while ($stmt->fetch()) { echo '<tr><td>'. $id_nr . '</td><td>' . $name . '</td></tr>'; } $stmt->free_result(); echo '</table>'; $stmt->close(); mysqli_close($conn); } ?> ...if you needed to bind a variable... $sql = "SELECT id_nr, name FROM mytable WHERE id_nr > ? ;"; $id_nr = 250; if ($stmt = $conn->prepare($sql)) { $stmt->bind_param('i', $id_nr); // 'i' = int $stmt->execute(); ...
  5. You can easily create the appearance of crooked containers, but you can't (afaik) create actual crooked (non-rectangular) containers.
  6. What type of code? How are you going to test the code? There are a number of websites that do this sort of thing... http://www.codewars.com/ https://www.hackerrank.com/ https://projecteuler.net/
  7. Code without tables. Provide a diagram of what you want to create and we will show you how to code without tables. I don't know what you mean by "scrollboxes."
  8. Yeah, those would be better. I'm not sure what addcslashes() was supposed to accomplish?
  9. Is addcslashes() adequate to prevent bad stuff from getting inserted?
  10. The code seems to work, although I found one line that had errors in the Php code... <?php if( isset( $_POST['task'] ) && $_POST['task'] == 'comment_insert'){ $userId = (int)$_POST['userId']; $comment = addslashes( str_replace( "\n" , "<br>" , $_POST['comment'] )); $std = new stdClass(); $std->comment_id = 24; $std->userId = $userId; $std->comment = $comment; $std->userName = "Joe Smith"; $std->profile_img = "/images/photo.jpg"; echo json_encode( $std ); }else{ header('location: /'); } ?>
  11. As a "complete beginner" how much of this code do you understand? Do you also have the Php portion of the code? Have you created the required database?
  12. Usually when port 80 is conflicted then port 8080 is used next, but it doesn't really matter.
  13. Go to line 184 of fire_menu.js and add something like this... //alert(buttons[i].text + ' was pushed'); switch (i){ case 0: location.assign('page1.html'); break; case 1: location.assign('page2.html'); break; case 2: location.assign('page3.html'); break; case 3: location.assign('page4.html'); break; default: alert('[' + buttons[i].text + ' unknown]'); break; } --updated 8/23--
  14. If the website displays the message and also a date/time stamp for each message -- then you could write Javascript to use that date/time stamp. If such a date/time stamp is not provided then the server-side code (probably Php) would need to be modified.
  15. Oh, I'm not intending to be harsh or negative, but there are already so many frameworks out there that most people don't even look at them all. Rather than writing an entirely new framework wouldn't it be better to try adding a few desirable features to a framework that already exists?
  16. Why do we need another framework? How is this any better than existing frameworks? https://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks
  17. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body> <h4>Algemene Informatie</h4> <table BORDER="1"> <tr> <th ALIGN="left">Ritnummer:</th> <th WIDTH="200"> </th> <th ALIGN="left">Datum Dienst</th> <th WIDTH="200"> </th> </tr> <tr> <th ALIGN="left">Vertrek van:</th> <th> </th> <th ALIGN="left">Ambulance:</th> <th> </th> </tr> <tr> <th> </th> <th> </th> <th ALIGN="left">Ambulance assistent:</th> <th> </th> </tr> <tr> <th>Afhaaladres:</th> <th> </th> <th ALIGN="left">Ambulanceverpleegkundige:</th> <th> </th> </tr> <tr> <th ALIGN="left">Bestemming:</th> <th> </th> <th ALIGN="left">Overige:</th> <th> </th> </tr> <tr> <th> </th> <th> </th> <th> </th> <th> </th> </tr> </table> </body> </html>
  18. This doesn't make any sense to me. Is E-terra a Firefox plug-in?
  19. I thought PayPal would auto-generate the required code... https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/get_started/
  20. You have a program? What program?
  21. The code I provided above is just a Javascript counter. It won't keep time if the page is closed or refreshed. When you post to a webpage that is a server-side operation -- not client-side. The client-side is the browser running Javascript. The Javascript counter above only runs in an open browser. When something like a message is stored to a webpage it is most commonly stored in a database using server-side code such as Php. You might want to look at a Php tutorial. There are many of them online. http://www.w3schools.com/php/ As Ingolme says above, if you really want live timers running on the page then Php would need to pass each message post time to the Javascript (perhaps in a hidden field) so that the Javascript could produce that changing elapsed-time display. The Php code runs only when the page is being rendered and loaded but a continuously changing timer value would require that Javascript continuously update the displayed value.
  22. Normally a post is going to be entered into a table in the database. That entry would include a timestamp. So it isn't clear to me what you are trying to do. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>time</title> </head> <body> <p id="p1">Last update: <span id="hours">00</span>:<span id="minutes">00</span>:<span id="seconds">00</span> </p> <script> // This code is rather strange as it accumulates seconds and minutes and hours // as independent semi-equivalent totals var hoursLabel = document.getElementById("hours"); var minutesLabel = document.getElementById("minutes"); var secondsLabel = document.getElementById("seconds"); var totalSeconds = 0, totalMinutes = 0, totalHours = 0; setInterval(setTime, 1000); function setTime() { 'use strict'; ++totalSeconds; secondsLabel.innerHTML = pad(totalSeconds%60); if (totalSeconds%60 == 0){ ++totalMinutes; minutesLabel.innerHTML = pad(totalMinutes%60); if (totalMinutes%60 == 0){ ++totalHours; hoursLabel.innerHTML = pad(totalHours); } } } function pad(val) { var valString = val + ""; if(valString.length < 2) { return "0" + valString; } else { return valString; } } </script> </body> </html>
  23. davej

    AJAX

    So headers won't cause the browser or the server to treat the data any differently? I don't even really understand why there is a xhr.responseXML -- since xml is just text, right? Apparently there is a move toward using a declared xhr.responseType... and one of the types is 'json' https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-responseType-attribute
  24. davej

    AJAX

    Oh, the content isn't my primary confusion -- it is the necessary headers and encoding steps and details to do this correctly.
×
×
  • Create New...