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,626
    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,626
    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 05: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,626
    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,626
    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,626
    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 12: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,626
    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,626
    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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.18573 seconds
  • Memory Usage 3,004KB
  • Queries Executed 14 (?)
More Information
Template Usage (37):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates