Dear All,
I have a drop down list. Based on the selection I will create more drop down list depending on the selection of the first drop down list. Example if first I select the value as 3 then three drop down list will be created below. Thus now my problem how to validate those drop drop list which I have created dynamically.Thank you.

Recommended Answers

All 8 Replies

Member Avatar for stbuchok

How do you want to validate them? How are you adding the dropdowns? Can we get some code samples? Are you using jQuery?

Dea Stbuchok,
Current below is how I do it? On change of the main drop down I call this function and populate it accordingly. I have a specific table so whatever previous rows I will remove and put new rows for this table document.getElementById('myTable');. I am still working on it using javascript but is very tedious.

function getSlaves(str,entID)
{
var table = document.getElementById('myTable');               
var rowCount = table.rows.length; 
//alert("Slaves Row count : "+rowCount);
  
if(rowCount>4)
{            
	for(var i=4; i<rowCount; i++) 
	{                 
		var row = table.rows[i];                 
		                     
			table.deleteRow(i);                     
			rowCount--;                     
			i--;                 
	}
}
differentiator=Math.floor(Math.random()*50000);

 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      var totalSlave = Number(str)+5;
      var slaveIndex=1;
      for(j=5;j<totalSlave;j++)
      {
	      var x=document.getElementById('myTable').insertRow(j); 
	      var y=x.insertCell(0); 
	      var z=x.insertCell(1); 
	      y.innerHTML="<label class=description for=element_1>Slave <font color='red'>*</font></label> "; 
	      z.innerHTML="<select class='select' id='slaveID"+slaveIndex+"' name='slaveID"+slaveIndex+"' >"+xmlhttp.responseText; 
        //var a=document.getElementById('myTable').insertRow(j); 
	      //var b=a.insertCell(0); 
	      ///var c=a.insertCell(1); 
	      //b.innerHTML=""; 
	      //c.innerHTML="<p class=error id='slaveID"+slaveIndex"+Error'>;  
        slaveIndex++;
      }

    }
  }
xmlhttp.open("GET","getSlavesList.php?e="+entID+"&d="+differentiator,true);
xmlhttp.se

nd();
}

What is the problem ? Doesn't the validation run ?

Dear Zero13,
It runs ok with javascript do you think I should adap jquery or leave it.Now it runs no problem but I got funny problem when I post it over using php I can see the dynamic value only in IE not in firefox and chrome. This is a new problem I am facing now.

Try to alert value after requesting the XMLHttpRequest, and check what is the difference between IE and others.

Dear Zero13,
What values should I alert and where exactly do you want me to alert? Thank you. Do you mean xmlhttp=new XMLHttpRequest(); alert("Something")?

newbie14
It is for debugging. I've no idea where the problem is. It's just only for approaching the problem and debugging. Can you point me the focus if you know where the problem originate ?

Zero13

Dear Zero13,
I am also lost cause is working well for IE and not the rest that is where I am also lost and confuse. I am also looking where could be the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.