Jump to content

Jonathanks

Members
  • Posts

    69
  • Joined

  • Last visited

Posts posted by Jonathanks

  1.  

    This is my approach to the problem:

    // Parameters
    var hours = 0
    var minutes = 50
    var seconds = 7
    var duration = 24 * 60 * 60;
    
    // Algorithm
    var start = hours * 3600 + minutes * 60 + seconds;
    var end = start + duration;
    var h, m, s;
    for(var time = start; time < end; time++) {
      h = Math.floor(time / 3600);
      m = Math.floor(time / 60) % 60;
      s = time % 60;
      core.output("hours " + h + " minutes " + m +" seconds " + s );
      core.wait(.4);
    }
    
    Wow. That's very elegant! I like your approach.
  2. You can wrap the output in <pre></pre> tags. But this too is HTML (you're sending data to a web browser so you may not always escape it) and it may cause the output to display in monospace fonts.Also, the nl2br() function can be used; you can also use heredoc to format your text so you won't need n.

  3. Single page

    <?php$con=mysqli_connect("localhost","root","","");// Check connectionif (mysqli_connect_errno()) {    echo "Failed to connect to MySQL: " . mysqli_connect_error();}?><!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <meta name="viewport" id="viewport" content="target-densitydpi=high-dpi,initial-scale=1.0,user-scalable=no" />        <title>http://w3schools.invisionzone.com/index.php?showtopic=53472</title>         <script type="text/javascript">            function myFunction() {                var x = document.getElementById('myform');                if (confirm("Da li želite da sačuvate promjene?") == true) {                    x.action = "http://localhost/web_testing/php_test/submittoself.php?success=true"   /*enter url to this form with query string at end*/                    return true;                } else {                    window.location = "http://localhost/web_testing/php_test/submittoself.php?success=false"  /*enter url to this form with query string at end*/
    Won't this code perform the database insert even if success=false?It seems testing for success before the connection to database satisfies his request.Maybe by adding && $_GET['success'] == 'true'to the if condition in the first segment of php will be good.
  4. Grrrr... I am not good with the AJAX.. I am the beginner :) yes I have two buttons... One for submmit and one for the cancelation written directly in my js confirmation box... Here is the code: Java Script confirmation box code: <script>function myFunction() { var x; if (confirm("Da li želite da sačuvate promjene?") == true) { x = "You pressed OK!"; } else { x = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = x;}</script> I know that this is a simple js function.. Do I need make some changes here (write an AJAX into this js code)???

    You want to reverse an accidental submission to a database, correct? That's what my suggestion is intended to address.The code above does not interact with the server. Most likely, it will be helpful in confirming form submission. If the user clicks 'ok', the request proceeds, else it fails. And the buttons aren't what I meant: they're JavaScript dialog buttons, not HTML.You can do it without AJAX.Did you understand my suggestion?
  5. Try this:

    <script>function myFunction() {    var x;    if (confirm("Da li želite da sačuvate promjene?") == true) {        x = "You pressed OK!";    } else {        return;    }    document.getElementById("demo").innerHTML = x;}</script>
    Or this:
    <script>function myFunction() {    var x;    if (confirm("Da li želite da sačuvate promjene?") == true) {        x = "You pressed OK!";    } else {        break;    }    document.getElementById("demo").innerHTML = x;}</script>
    I think he wants to provide a remedy for mistakes in form submission. He can do it by form or by AJAX. I'm not good at this but I may provide pseudocode instead.
  6. It seems you're using two buttons in the markup: one for 'submit' and the other for 'cancel. You can add an onclick function to the cancel button that sends an AJAX query to the post destination to check the database and reverse the last update.Your PHP code can set a variable, say $prev_data, to the previous state of the data in the MySQL database before updating it with new data. If the user, after submitting the update completely, decides it was a mistake, the 'cancel' button sends an AJAX request; the PHP code tests the request for a condition then updates the database with the data in $prev_data.I hope this makes sense a little.

    • Like 1
  7. That will work: on all files in the home directory, I think.Maybe you should consider naming your files semantically. For example, you may suffix files intended to have read-write permission with '_rw' before the file extension and use wildcard matching to set the permission on all of them at a time.(example:example_rw.txt, example1_rw.html...exampleN_rw.php$ chmod a+r /home/*_rw.*)I don't know if such would work but I hope you get the point. Just try it for yourself.I haven't used UNIX or LINUX before: I'm just a beginner with windows. I've seen so many recommendations for linux systems to programmers. Maybe one day I'll try a linux OS.

    • Like 1
  8. The first problem has the loop body reassign the variable 'a' to a number. Given it's initial value of a.length as 2, and the initial value of 'i' as 0, 'a' will always be greater since the value of i is continuously added to it. So the loop never ends.

    • Like 1
  9. Yea. Ingolme has explained it.In your first loop, the assignment was done outside the loop so each time the loop is run, the value of the variable 'hunter' is updated outside and is stored.In the second loop, the value is updated inside of the loop, stored and output with the document.write() function. But each time the loop is run, the variable 'hunter' is reassigned to 0. Hence you have 3 instead of 6.

  10. It's a mode in which the browser is not law-abiding. It accepts any malformed mark-up in this mode and is not strict with syntax, tags and elements as prescribed in the DTD.But one thing is many websites depend on it very much: turn on strict mode and try visiting as many sites as you can. You'll find that many of them will not render correctly in the browser.

  11. The first code uses the && operator. The && operator evaluates all conditions from left to right and returns 'true' if all the conditions are satisfied. If one is satisfied, it continues on to the next until all conditions are tested. All must be satisfied for the instruction to be executed. The || operator tests if one of the conditions is true. If the first is false, the second is evaluated. But if the first is true, the other conditions bound by the || will be ignored and the instruction executed.So, considering your code, the first loop tests the variable 'sexo" for all predefined values. It must satisfy all conditions, returning 'true' for the code to run. If sexo === 'h', for example, it returns false and the loop ends without executing the code. The second code tests for options. If sexo === 'h', being an OR operator, it executes the instruction if any of the conditions is true. That means one of the conditions must definitely be true in this case. And so, the loop won't end.

×
×
  • Create New...