dcsimg
www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: HTML Addition help

  1. #1
    Join Date
    Feb 2016
    Posts
    30

    Unhappy HTML Addition help

    Hi, Im looking for some help with some HTML/Java I have this snippet of code which works for one section but i have another 29 questions to go after. The end result is I need a box to display the totals of each error at the bottom of the page.

    <p>
    <script type="text/javascript">// <![CDATA[
    function getValues(val){

    var numVal1=parseInt(document.getElementById("one").value);
    var numVal2=parseInt(document.getElementById("two").value);
    var numVal3=parseInt(document.getElementById("three").value);

    var totalValue = numVal1 + numVal2 + numVal3;

    document.getElementById("main").value = totalValue;
    }
    // ]]></script>
    </p>
    <p><strong>Question 1</strong></p>
    <p>Drill Error: <input class="numbox" type="text" id="one" value="0" onkeyup="getValues(1)" />* **Critical Error: *<input class="numbox" type="text" id="two" value="0" onkeyup="getValues(2)" />**Safety Errors: <input class="numbox" type="text" id="three" value="0" onkeyup="getValues(3)" /><br /> <br />Total Errors:<br /> <textarea id="main" value=""></textarea></p>


    This is what i have already which works with Question 1 but now i need to finish the other parts. Can anyone help out in explaining how'

    1. I have can Question 1 - Question 29 with Three input boxes and a Final Total/Results For each Error box to be displayed at the bottom.

  2. #2
    Join Date
    Dec 2012
    Posts
    1,549
    Do I understand this correctly? You have 29 questions and three errrors for each question?

    Question 1
    Drill Errors
    Critical Errors
    Safety Errors
    Total errors (for question 1)

    Question 2
    Drill Errors
    Critical Errors
    Safety Errors
    Total errors (for question 2)

    Question 3
    Drill Errors
    Critical Errors
    Safety Errors
    Total errors (for question 3)

    and so on for all 29 questions

  3. #3
    Join Date
    Feb 2016
    Posts
    30
    Hi,

    Yes i have three errors for each question and i need a box at the bottom with three outputs one for Total Drill Errors, one for Total Critical Errors and a box for total Safety Errors. I have tried and tried but just get stuck

  4. #4
    Join Date
    Dec 2012
    Posts
    1,549
    Check if this code meats your requirements:
    Code:
        <div id="qcontainer">
    
        </div>
        <script src="//code.jquery.com/jquery-1.12.4.js"></script>
        <script>
            var questions = [
                "Question 1",
                "Question 2",
                "Question 3",
                "Question 4"
            ];
            var errors = [
                "Drill Errors: ",
                "* **Critical Errors: ",
                "**Safety Errors: "
            ];
            qcont = $("#qcontainer");
            questions.forEach(function (ele, iquestion) {
                var pquestion = $("<p class='question'>" + ele + "</p>");
                qcont.append(pquestion);
                var perror = $("<p></p>");
                qcont.append(perror);
                errors.forEach(function (ele, ierror) {
                    var merror = $("<label>" + ele + "<input class='numbox'  data-id='error-" + ierror + "' type='text' value='0'></label>");
                    perror.append(merror);
                });
            });
            qcont.append("<br /> <br />");
            errors.forEach(function (ele, ierror) {
                var mtotal = $("<label>Total " + ele + "<br /><textarea class='total' data-id='error-" + ierror + "' value=''></textarea>");
                qcont.append(mtotal);
            });
            $(".numbox").on("input", function () {
                for (var ierror = 0; ierror < errors.length; ierror++) {
                    var sum = 0;
                    $("input.numbox[data-id='error-" + ierror + "']").each(function (idx, ele) {
                        sum += parseInt($(this).val());
                    });
                    $("textarea.total[data-id='error-" + ierror + "']").val(sum);
                }
            });
        </script>
    This code is based on two lists or arrays for questions and errors. You need to complete the question list. The DOM elements are created by jQuery, thus copy/paste errors when editing the HTML manually are excluded.
    Last edited by Sempervivum; 07-12-2017 at 06:00 PM.

  5. #5
    Join Date
    Feb 2016
    Posts
    30
    Awesome that works, so if I add question 5 to 29 do I just copy and paste
    var questions = [ "Question 1", "Question 2", "Question 3", "Question 4 and add 5 to 29 and then it will work sorry it's confused me so much.

  6. #6
    Join Date
    Dec 2012
    Posts
    1,549
    Yes, the only thing you need to do is extend the questions array.

  7. #7
    Join Date
    Feb 2016
    Posts
    30
    Thanks it's great. Now I just need to insert all the questions. Also how easy would it be to insert a button to save all info as a document.

  8. #8
    Join Date
    Dec 2012
    Posts
    1,549
    how easy would it be to insert a button to save all info as a document.
    Not shure what you mean. You like to save the information to the local disc? What type of document do you mean? HTML? Plain text? PDF?

  9. #9
    Join Date
    Feb 2016
    Posts
    30
    If all information displayed could be saved as a user clicks Save then the document will download in a pdf format or docx either really. And stored on the local disc

  10. #10
    Join Date
    Dec 2012
    Posts
    1,549
    Yes, this can be done. I recommend using the PDF format. There are two ways for converting the content and saving it to disc:
    1. Using a PDF printer like PDFredirect.
    2. If the page will be used by unexperienced users that cannot install a PDF printer a library like
    https://github.com/eKoopmans/html2pdf
    can be used to convert and print the page.

    Converting to doc/docx can also be done as described here:
    https://stackoverflow.com/questions/...ml-css-to-docx

    Note: Option one features the ability to create a special CSS for printing in order to create a layout that is suitable for printing.
    Last edited by Sempervivum; 07-13-2017 at 01:23 AM.

  11. #11
    Join Date
    Feb 2016
    Posts
    30
    Thanks for the help, is there a way to PM you

  12. #12
    Join Date
    Dec 2012
    Posts
    1,549
    Yes, you can: Click "Private Messages" on top and then "Send New Message" at the left. I would not like to post my email address in a public thread.

  13. #13
    Join Date
    Feb 2016
    Posts
    30
    Quote Originally Posted by Sempervivum View Post
    Yes, you can: Click "Private Messages" on top and then "Send New Message" at the left. I would not like to post my email address in a public thread.
    Hey, I have added you as a Contact as I can not See the Private Message function, Could you send me a PM please. Thanks

  14. #14
    Join Date
    Dec 2012
    Posts
    1,549
    Sending a PM failed. I guess you have to have a minimum number of postings before PMs are enabled.
    If you really cannot post your message here, read my email address from my homepage:
    http://ulrichbangert.de

  15. #15
    Join Date
    Feb 2016
    Posts
    30
    Quote Originally Posted by Sempervivum View Post
    Sending a PM failed. I guess you have to have a minimum number of postings before PMs are enabled.
    If you really cannot post your message here, read my email address from my homepage:
    http://ulrichbangert.de
    Thanks, Emailing heading your way haha

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center