// This implementation uses jQuery // My non-conflicting jQuery instance... var externalService; function formatForExternalService() { // Store all values to a map... var myMap = new Object(); // Get user's name and UCO var fullUser = $('#id-uzivatel').text(); var nameSurname = fullUser.match(/^[^(]+/)[0].trim();// divUco.getElementsByTagName("b")[0].textContent; var uco = fullUser.match(/\d+/)[0]; myMap["uco"] = uco; myMap["name"] = nameSurname; //alert("User:" + nameSurname + ", uco:" + uco); // Get studies (may not be defined) //var studies = $('span').text(); myMap["study"] = ''; // studies; //alert("Studies:" + studies); // Walk through all input elements... var inputs = $(":input[name^='tst']"); // input elements starting with 'tst' in their 'name' attribute inputs.each(function() { var t = $(this).attr('type'); var n = $(this).attr('name'); if (t == "radio") { if ($(this).is( ":checked" )) { myMap[n] = $(this).parent().text(); } } else if (t == "checkbox") { if ($(this).is( ":checked" )) { if (n in myMap) { myMap[n] = myMap[n] + "#;#" + $(this).parent().text(); } else { myMap[n] = $(this).parent().text(); } } } else if (t == "text") { myMap[n] = $(this).val().replace(/(\r\n|\n|\r)/gm, " "); } else if ($(this).is('textarea')) { if (n != externalService.attr('name')) { myMap[n] = $(this).val().replace(/(\r\n|\n|\r)/gm, "#^#"); } } else if ($(this).is('select')) { $(this).contents().filter('option:selected').each(function() { if (n in myMap) { myMap[n] = myMap[n] + "#;#" + $(this).text(); } else { myMap[n] = $(this).text(); } }); } //alert('Name:' + n + ', Type:' + t + ", Value:" + $(this).val() + // ", Map update: " + myMap[n]); }); // Format the map to string... and store it to the correct text area var toSend = ""; for (var key in myMap) { toSend = toSend + key + ":" + myMap[key] + "\n"; } //alert("ToSend:" + toSend); externalService.attr("value", toSend); } // Register to the submit button... $(document).ready(function() { //alert("Home assignment No.1"); // Save the e: question element... externalService = $("textarea[name*='_e_a_1']:last"); form = $("form[name='testform']"); form.submit(function(event) { // Format all student answers into the e: question formatForExternalService(); // Do regular form submit.... return; //event.preventDefault(); }); // Hide the e: question... externalService.hide(); });