0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="managesurveys.aspx.cs" Inherits="managesurveys" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript">
	function newAttribute() {
		var d = document;

		// get field labels
		var lbl_attribute_new = document.getElementById('js_lbl_attribute_new').value;
		var lbl_attribute_del = document.getElementById('js_lbl_attribute_delete').value;
		var lbl_property_new = document.getElementById('js_lbl_property_new').value;
		var lbl_property = document.getElementById('js_lbl_property').value;
		var lbl_title = document.getElementById('js_lbl_title').value;


		var container = document.getElementById('attribute_container');
		var next_inc = container.getElementsByTagName('table').length + 1;
		var toolbar = "<a href='javascript:newAttribute();'><img src='http://localhost:49366/Surveys/add_button.png' alt='Question' width='20' height='20' border='0' hspace='5' align='absmiddle'/></a> <a href='javascript:deleteAttribute(" + next_inc + ")'><img src='http://localhost:49366/Surveys/delete_button.png' alt='Question' width='20' height='20' border='0' hspace='5' align='absmiddle' /></a>";
		var toolbar2 = "<a href='javascript:newProperty(" + next_inc + ")'><img src='http://localhost:49366/Surveys/add_button.png' alt='Answer' width='20' height='20' border='0' hspace='5' align='absmiddle' /></a>Answer ";

		if (next_inc % 2 == 0) {
			var dynamicClass = 'dynamicTableEven';
		} else {
			var dynamicClass = 'dynamicTableOdd';
		}

		var table = d.createElement('table');
		table.id = 'attributeX_table_' + next_inc;
		table.className = dynamicClass;

		var tbody = d.createElement("tbody");
		var tr = d.createElement('tr');
		var tr2 = d.createElement('tr');
		tr2.id = "attributeX_tr_" + next_inc + "_0";


		var td_01 = d.createElement('td');
		td_01.style.width = '15%';
		td_01.innerHTML = toolbar + lbl_title;

		var td_02 = d.createElement('td');
		td_02.colSpan = '2';
		td_02.align = 'left';
		td_02.innerHTML = '<input type="text" name="attributeX[' + next_inc + '][name]" value="" size="60"/>';

		var td_03 = d.createElement('td');
		td_03.colSpan = '2';
		td_03.align = 'left';
		td_03.innerHTML = toolbar2;

		var td_04 = d.createElement('td');
		td_04.style.width = '15%';
		td_04.innerHTML = '&nbsp;';

		var td_05 = d.createElement('td');
		td_05.style.width = '9%';
		td_05.align = 'left';
		td_05.innerHTML = lbl_property;

		var td_06 = d.createElement('td');
		td_06.style.width = '57%';
		td_06.align = 'left';
		td_06.innerHTML = "<input type='text' name='attributeX[" + next_inc + "][value][]' value='' size='40' /><a href='javascript:deleteProperty(" + next_inc + ",\"" + next_inc + "_0\");'><img src='http://localhost:49366/Surveys/delete_button.png' alt='answer' width='20' height='20' border='0' hspace='5' align='absmiddle' /></a>";

		table.appendChild(tbody);
		tbody.appendChild(tr);
		tr.appendChild(td_01);
		tr.appendChild(td_02);
		tr.appendChild(td_03);
		tbody.appendChild(tr2);
		tr2.appendChild(td_04);
		tr2.appendChild(td_05);
		tr2.appendChild(td_06);

		container.appendChild(table);
	}


	function deleteAttribute(attribute_id) {
		var container = document.getElementById('attribute_container');

		var table = document.getElementById("attributeX_table_" + attribute_id);

		container.removeChild(table);
	}


	function newProperty(attribute_id) {
		var d = document;

		// get field labels
		var lbl_property = document.getElementById("js_lbl_property").value;
		var table = document.getElementById("attributeX_table_" + attribute_id);
		var tbody = table.getElementsByTagName('tbody')[0];
		var tr_id = table.getElementsByTagName('tr').length + 1;

		// create new HTML elements
		var tr = d.createElement('tr');
		tr.id = "attributeX_tr_" + attribute_id + "_" + tr_id;

		var td_01 = d.createElement('td');
		td_01.style.width = '15%';
		td_01.innerHTML = '&nbsp;';

		var td_02 = d.createElement('td');
		td_02.style.width = '9%';
		td_02.align = 'left';
		td_02.innerHTML = lbl_property;

		var td_03 = d.createElement('td');
		td_03.style.width = '57%';
		td_03.align = 'left';
		td_03.innerHTML = "<input type='text' name='attributeX[" + attribute_id + "][value][]' value='' size='40'/><a href='javascript:deleteProperty(" + attribute_id + ",\"" + attribute_id + "_" + tr_id + "\");'><img src='http://localhost:49366/Surveys/delete_button.png' alt='answer' width='20' height='20' border='0' hspace='5' align='absmiddle' /></a>";


		// append new elements    
		tbody.appendChild(tr);
		tr.appendChild(td_01);
		tr.appendChild(td_02);
		tr.appendChild(td_03);


	}


	function deleteProperty(attribute_id, property_id) {
		var d = document;
		var table = document.getElementById("attributeX_table_" + attribute_id);
		var tbody = table.getElementsByTagName('tbody')[0];
		var tr = d.getElementById("attributeX_tr_" + property_id);

		tbody.removeChild(tr);
	}

	function SaveValues() {
		var e;
		var allvalues = new Array();
		for (i = 0; i < form1.elements.length; i++) {

			e = form1.elements[i];

			if (e.type == 'text') {
				alert('in');
				allvalues[i] = e.value;
			}
		}
		}

//			    alert('in');
//			    for (var i in form1.elements) {
//			        if (i.tagName=='INPUT')
//			            alert(form1.id);
//			    }
//	}
</script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table width="97%" cellpadding="0" cellspacing="0">
          <tr>
		  <td colspan="2"> &nbsp;Survey Name:<input type="text" name="Survey Name:" id="survey name" value="" size="60" style="width: 400px; margin-left: 58px" /></td>
		  </tr>
		  <tr>
            <td width="79%" align="left" id="attribute_container"><input type="hidden" name="js_lbl_title" id="js_lbl_title" value="Question:" />
              <input type="hidden" name="js_lbl_property" id="js_lbl_property" value="Answer:" />
              <input type="hidden" name="js_lbl_property_new" id="js_lbl_property_new" value="New Property" />
              <input type="hidden" name="js_lbl_attribute_new" id="js_lbl_attribute_new" value="New Attribute" />
              <input type="hidden" name="js_lbl_attribute_delete" id="js_lbl_attribute_delete" value="Delete Attribute" />
              <%--<input type="hidden" name="js_lbl_price" id="js_lbl_price" value="Default Value" />--%>
               <table width="96%" class="dynamicTableOdd" id="attributeX_table_0">
                <tbody>
                  <tr>
                    <td width="15%"><a href="javascript: newAttribute(1)"><img src="http://localhost:49366/Surveys/add_button.png" alt="add question" width="20" height="20" border="0" hspace="5" align="absmiddle" /></a> Question:</td>
                    <td align="left" colspan="2"><input type="text"	name="attributeX[0][name]" value="" size="60" style="margin-right: 0px" /></td>
                    <td colspan="2" align="left"><a href="javascript: newProperty(0)"><img src="http://localhost:49366/Surveys/add_button.png" alt="add answer" width="20" height="20" border="0" hspace="5" align="absmiddle" /></a> Answer</td>
                  </tr>
                  <tr id="attributeX_tr_0_0">
                    <td width="15%" align="left">&nbsp;</td>
                    <td width="9%" align="left">Answer:</td>
                    <td align="left" width="57%"><input type="text"	name="attributeX[0][value][]" value="" size="40" /> </td>
                    
                  </tr>
                </tbody>
              </table>
			  
		    </td>
          </tr>
      </table>
	  <asp:Button ID="btnsave" runat="server" Text="Save" OnClientClick="SaveValues()" onclick="btnsave_Click" />
	  </div>
	  <input type="hidden" runat="server" id="hdn" />
    </form>
</body>

</html>
<script type="text/javascript">
	function SaveValues() {

		var e;
		var allvalues = new Array();
		var arrposition = 0;
		for (i = 0; i < form1.elements.length; i++) {

			e = form1.elements[i];

			if (e.type == 'text') {


				allvalues[arrposition] = e.value;
				arrposition = arrposition + 1;
			}

		}
		document.getElementById("<%=hdn.ClientID%>").value = allvalues;

	}
</script>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by prvnkmr194
0

Search on google you gets of post regarding saving the data in database, then if you get any problem feel free to ask your problem

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.