Показать сообщение отдельно
  #3 (permalink)  
Старый 02.12.2010, 19:50
Интересующийся
Отправить личное сообщение для shleify Посмотреть профиль Найти все сообщения от shleify
 
Регистрация: 02.12.2010
Сообщений: 10

Все всем спасибо сообразили и выкрутились! Если кому надо выложу код! Оч интересная штука получилась!
<script type="text/javascript">

//==============================================================================================================================
function createQuestionLabel(id)
{
	var questionInp = document.createElement( "questionLabel" );
	questionInp.innerHTML = "<a>Вопрос №"+id+"</a><br>";
	return questionInp;
}
function createQuestionInp(id,value)
{
	var questionInp = document.createElement( "input" );
	questionInp.type = "text";
	questionInp.name = "q" + id;
	questionInp.id = "q" + id;
	questionInp.value = value ;
	return questionInp;
}
function createDeleteQuestionButton(id)
{
	var buttonDelete = document.createElement( "input" );
	buttonDelete.type = "button";
	buttonDelete.value = "У";
	buttonDelete.id = "delQButton" + id;
	buttonDelete.onclick = function() { deleteQuestion(id);  };
	return buttonDelete;
}
function createQuestionDiv(id)
{
	var questionDiv = document.createElement( "div" );
	questionDiv.id = "qDiv" + id;
	return questionDiv;
}
function createAddAnswerButton(id)
{
	var addAnswerButton = document.createElement( "input" );
	addAnswerButton.type = "button";
	addAnswerButton.value = "Добавить ответ";
	addAnswerButton.name = "qd_sanswer_b";
	addAnswerButton.id = "addAButton" + id;
	addAnswerButton.onclick = function() { addAnswer(id,'');  };
	return addAnswerButton;
}
function createAnswerDiv(id)
{
	var answerDiv = document.createElement( "div" );
	answerDiv.id = "aDiv" + id;
	return answerDiv;
}
function createAnswerCount(id)
{
	var answerCount = document.createElement( "input" );
	answerCount.type = 'hidden';
	answerCount.id = "countA" + id;
	answerCount.value = '0';
	return answerCount;
}
function createAnswerInp(questionId,answerId,value)
{
	var answerInp = document.createElement( "input" );
	answerInp.type = "text";
	answerInp.name = "q"+questionId+"a" + answerId;
	answerInp.id = "q"+questionId+"a" + answerId;
	answerInp.value = value;
	return answerInp;
}
function createDeleteAnswerButton(questionId,answerId)
{
	var buttonDelete = document.createElement( "input" );
	buttonDelete.type = "button";
	buttonDelete.value = "У";
	buttonDelete.id = "delAButton" + answerId;
	buttonDelete.onclick = function() { deleteAnswer(questionId,answerId);  };
	return buttonDelete;
}
function addQuestion(text){
	countQ = document.getElementById("countQ").value;
	var parentNode = document.getElementById("placeToAdd");
	var questionDiv = createQuestionDiv(++countQ);
	parentNode.appendChild(questionDiv);
	var questionLabel = createQuestionLabel(countQ);
	questionDiv.appendChild(questionLabel);
	var questionInp = createQuestionInp(countQ,text);
	questionDiv.appendChild(questionInp);
	var buttonDelete = createDeleteQuestionButton(countQ);
	questionDiv.appendChild(buttonDelete);
	var addAnswerButton = createAddAnswerButton(countQ);
	questionDiv.appendChild(addAnswerButton);
	var answerDiv = createAnswerDiv(countQ);
	questionDiv.appendChild(answerDiv);
	var answerCount = createAnswerCount(countQ);
	questionDiv.appendChild(answerCount);
	document.getElementById("countQ").value=countQ;
}
function addAnswer(questionId,text){
	countA = document.getElementById("countA"+questionId).value;
	var parentNode = document.getElementById("aDiv"+questionId);
	var answerInp = createAnswerInp(questionId,++countA,text);
	parentNode.appendChild(answerInp);
	var buttonDelete = createDeleteAnswerButton(questionId,countA);
	parentNode.appendChild(buttonDelete);
	document.getElementById("countA"+questionId).value = countA;
}
function deleteQuestion(id){
	var parentNode = document.getElementById( "placeToAdd");
	var countQ=document.getElementById("countQ").value;
	var questions = new Array();
	var answers = new Array();
	for (var i=1; i<=countQ; i++)  {
		questions[i]= document.getElementById("q"+i).value;
		countA=document.getElementById("countA"+i).value;
		answers[i]=new Array();
		for (var a=1; a<=countA; a++)  {
			answers[i][a]= document.getElementById("q"+i+"a"+a).value;
		}	
	}
	questions.splice(id,1);
	answers.splice(id,1);
	while (parentNode.firstChild) {
		parentNode.removeChild(parentNode.firstChild);
	}
	countQ = 0;
	document.getElementById("countQ").value=0;
	var parentAnswerNode;
	for(i=1; i<questions.length; i++){
		var question = questions[i];
		addQuestion(question);
		countA=0;
		parentAnswerNode = document.getElementById("aDiv"+i);
		//alert(questions[i].length);
		for(a=1; a<answers[i].length; a++){
			addAnswer(i,answers[i][a]);		
		}
	}
}
function deleteAnswer(questionId,answerId){
	var parentNode = document.getElementById( "aDiv"+questionId);
	var countA=document.getElementById("countA"+questionId).value;
	var answers = new Array();
	for (var i=1; i<=countA; i++)  {
		answers[i]= document.getElementById("q"+questionId+"a"+i).value;
	}
	answers.splice(answerId,1);
	while (parentNode.firstChild) {
		parentNode.removeChild(parentNode.firstChild);
	}
	countA = 0;
	document.getElementById("countA"+questionId).value=0;
	for(i=1; i<answers.length; i++){
		addAnswer(questionId,answers[i]);
	}
}
</script>


<form id="f" method="post" enctype="multipart/form-data" onsubmit="return false">
		<table cellpadding='2' cellspacing='0'>
			
	   			<tr valign='top'>

							<button type='button' onclick="addQuestion('')" style='width: 140px; height: 21px'>Добавить вопрос</button>
							<div id="placeToAdd"></div></td>


	   			</tr>
	    			<tr>
	   					
	   				<input name='countQ' type="hidden"  id="countQ" value="0"></td>
	   				<td align='right'>
				</td>
				  <tr>
	    			<td align='right'></td>
	    			<td></td>
	    		</tr>
			</tr></table></form>
Ответить с цитированием