validation of the 2 dropdowns.

validation on the two dropdown that user can't select the same value in two dropdowns.
designersxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Graceful_PenguinCommented:
Check that the two values are not the same.

Please explain the situation or post some code because you question doesn't tell us anything.
0
designersxAuthor Commented:
code
<select name="test1" id="test1">
	<option>1</option>
	<option>2</option>
</select>
 
<select name="test2" id="test2">
	<option>1</option>
	<option>2</option>
</select>
 
<input type="submit" />
 
<script language="javascript" type="text/javascript">
	//here i want to check before submitting the values there should be a check of both dropdowns whether there is a same value selected 
</script>

Open in new window

0
designersxAuthor Commented:
if i would take simple 4  textboxes and a submit button and  i want to check all the textboxes values whether there is any duplicate value in the textbox , how would we do that
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Graceful_PenguinCommented:
How about this. All you needed was the value on each option.
<script language="javascript" type="text/javascript">
function TestInput()
{
  if (test1.value != test2.value)
    form.submit;
}
 
</script>
<select name="test1" id="test1">
  <option value="1">1</option>
  <option value="2">2</option>
</select>
 
<select name="test2" id="test2">
  <option value="1">1</option>
  <option value="2">2</option>
</select>
 
<input type="submit" onClick="TestInput();"/>

Open in new window

0
designersxAuthor Commented:
how can we do if we 7 dropdowns means if i have dynamic.
0
Graceful_PenguinCommented:
OK I changed the script to test all the values. All the script needs to know is how many selects there are and it assumes that all the selects are called test+num. If you don't like that just write a function that collects all the selects int the array. It could even be outputed from the php.

BTW this the way you ask the questions is not nice if I knew that the question is the complecated I would not have started to answer for only 125 pts. So in future please state the whole question, not just a piece.
<script language="javascript" type="text/javascript">
function TestInput(NumSelects)
{
  for (k = 0; k < NumSelects; k++)
    selects[] = GetElementByID("test"+k);
 
  for (i = 0; i < NumSelects; i++)
  {
    for (j = 1; j > NumSelects; j++)
    {
      if (selects[i] != selects[j])
        form.submit;
     }
  }
}
</script>

Open in new window

0
designersxAuthor Commented:
sir i tried ur static code and it does not work here so i included
<form action="" method="post" name="form"> and even then code does not work. 'sir i have written this code and it works can u help me out for making it dynamic.

i am just recently going to give u my dynamic code which i am making.


but thanks for ur great help. i feel sorry if u feel bad for anything on my part. ok leave it. focussing the question. see my static code, it works but tell me if there is any mistake i have done.
<form action="selectcheck.php" method="post" name="form">
<select name="test1" id="test1">
	<option>1</option>
	<option>2</option>
	<option>3</option>
</select>
 
<select name="test2" id="test2">
	<option>1</option>
	<option>2</option>
	<option>3</option>
</select>
 
<select name="test3" id="test3">
	<option>1</option>
	<option>2</option>
	<option>3</option>
</select>
 
<input type="submit" name="submit" />
</form>
 
<?php
if(isset($_REQUEST['submit'])){
	$test1=$_REQUEST['test1'];
	$test2=$_REQUEST['test2'];
	$test3=$_REQUEST['test3'];
?>
	<script language="javascript" type="text/javascript">
		<?php if($test1==$test2 || $test1==$test3 || $test2==$test3){ ?>
			alert('Please select the different values');
		<?php } ?>
	</script>
<?php 
}	
?>

Open in new window

0
designersxAuthor Commented:
i am really sorry now ur code is working, let me check ur dynamic code. there was a problem og double quotes.
0
designersxAuthor Commented:
how the value will be passed from php variable to the javascript variable, this is the main problem i am facing. please see my 3rd line and second last line.
<script language="javascript" type="text/javascript">
function TestInput(NumSelects)
{
	alert(NumSelects)//not working 
  for (k = 0; k < NumSelects; k++)
    selects[] = GetElementByID("test"+k);
 
  for (i = 0; i < NumSelects; i++)
  {
    for (j = 1; j > NumSelects; j++)
    {
      if (selects[i] != selects[j])
        form.submit;
     }
  }
}
</script>
	
<form action="dynamiccheck.php?countryid=1" name="form" method="post">
	<input type="submit" value="submit" onclick="TestInput(<?php $primax1 ?>)" />
</form>

Open in new window

0
designersxAuthor Commented:
oh......... on the click of a button i am using               if(isset($_request['submit'])){ // here i have written the code which is saving the values in the database. so on the click of that button i can't call any function and use javascript. so can u tell me with isset instead of calling a function.
0
Graceful_PenguinCommented:
About the first post.
Try the attached code. If it does not work please tell me what it does eg. is the string blank?

About the second post
What do you mean you are using if(isset($_request['submit'])){  on the onClick that is a php method which can't be called in an onclick. You can only test that after the form post, after my onClick code.
<script language="javascript" type="text/javascript">
function TestInput()
{
  NumSelects = <?php $primax1 ?>;
 	alert(NumSelects)//not working 
  for (k = 0; k < NumSelects; k++)
    selects[] = GetElementByID("test"+k);
 
  for (i = 0; i < NumSelects; i++)
  {
    for (j = 1; j > NumSelects; j++)
    {
      if (selects[i] != selects[j])
        form.submit;
     }
  }
}
</script>
	
<form action="dynamiccheck.php?countryid=1" name="form" method="post">
	<input type="submit" value="submit" onclick="TestInput()" />
</form>

Open in new window

0
designersxAuthor Commented:
selects[] = GetElementByID("test"+k); this is not alerting sir
0
designersxAuthor Commented:
line no.  7 is not working when i alert sir .
upto 6 is fine

0
designersxAuthor Commented:
sir

for (j = 1; j > NumSelects; j++)
    {
      if (selects[i] != selects[j])
        form.submit;
     }

this loop is wrong, please review it.
0
designersxAuthor Commented:
sir i have check ed it thoughly, the problem is coming because of the selects[] array which u have taken. i have even defined above var selects =new Array(); please help me sir.
0
designersxAuthor Commented:
About the first post. >>it was right.
About the second post >> sorry i misleaded the path.

now there is a problem coming in array of javascript that we have taken.
0
designersxAuthor Commented:
now at present array works fine , i took like this var a=new array(); a=//...

now i have run the loop from 1 and not 0, i am really confusing ,can u please change ur code to just looping from 1.
0
designersxAuthor Commented:
in the end, i need to alert in stead of

 if (selects[i] != selects[j])
        form.submit;

like this

if (selects[i] == selects[j])
       alert("same")t;

there is a problem coming in the loop.
0
Graceful_PenguinCommented:
Sorry you are right, the code should loop from 1.

About the array.
I am not sure what the problem is, but it seems that you have the answer now?

If the code is not correct can you please post the code that you changed so that we are both looking at the same code.
<script language="javascript" type="text/javascript">
function TestInput()
{
  NumSelects = <?php $primax1 ?>;
 	alert(NumSelects)//not working 
  for (k = 1; k < NumSelects; k++)
    selects[] = GetElementByID("test"+k);
 
  for (i = 1; i < NumSelects; i++)
  {
    for (j = 2; j > NumSelects; j++)
    {
      if (selects[i] != selects[j])
        form.submit;
     }
  }
}
</script>
	
<form action="dynamiccheck.php?countryid=1" name="form" method="post">
	<input type="submit" value="submit" onclick="TestInput()" />
</form>

Open in new window

0
designersxAuthor Commented:
yes just wait for a minute, let me check, i am very near to the solution.
0
designersxAuthor Commented:
testing.......
<script language="javascript" type="text/javascript">
		function f()
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
			   for (j=a;j<=i;j--)
                 {  
				   if (myArray[i] == myArray[j])
                       alert("same")
				 }	   
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
nothing is happening with the code. what if (myArray[i] == myArray[j]) is exactly doing?
0
designersxAuthor Commented:
we are comparing the one dropdown with other dropdowns and checking if there is any same value in the dropdown or not.
0
designersxAuthor Commented:
i am sure that our this loop is wrong for              (j=2;j>a;j++)
0
designersxAuthor Commented:
need ur help........... sir
0
designersxAuthor Commented:
if (myArray[i] == myArray[j]) this is not comparing one dropdown with the other dropdown.
0
Graceful_PenguinCommented:
Why not?
0
Graceful_PenguinCommented:
the loop should be
for (j=1;j<=a;j++)
{  
  if (myArray[i] == myArray[j])
    alert("same")
}

Open in new window

0
designersxAuthor Commented:
waiting for u eagerly.... sir i am not sure this ,ok if this.

sir did u saw my above code???? there is a problem in loop.
0
designersxAuthor Commented:
with the above loop when i=1 and for (j=1;j<=a;j++)  j= 1 to 5 then it prints the alert 5 times and it alerts when i have selected only 1 dropdown with any value.
0
designersxAuthor Commented:
it is not checking the 1 value in dropdown1 with 1 of dropdown2. if the 2 for loops of i and gets satisfied then it simply alerts the same, it does not check  if (myArray[i] == myArray[j]) this.
0
Graceful_PenguinCommented:
Kan you post the code you have at this moment including the php and html code.
0
designersxAuthor Commented:
this is my complete code of 230 lines.
<?php
session_start();
if($_SESSION['logged']!=1){
	echo "<b>Direct Access to this page is not Authorised</b>";
?>  <a href="index.php"><b>Login</b></a>
<?php
}
else{
$countryid=$_REQUEST['countryid']; ?>
<form action="test.php?countryid=<?php echo $countryid; ?>" method="post" name="form">
<table width="200" border="1" bgcolor="">
  <tr>
    <td bgcolor="#E6E6E6">Priority</td>
    <td bgcolor="#E6E6E6">Distributor</td>
    <td bgcolor="#E6E6E6"><input type="submit" name="save" value="Save The Priority" /></td>
  </tr>
  <tr>	
	
  </tr>
  <tr>
    <td><table bgcolor="#E6E6E6">
	<?php 
	
	$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\testing_fantaay-db\\admin\\disb.mdb");
	$sql="select priority as pri from tblcountrydistributor where countryid=".$countryid." order by priority";
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
		$pri = $rs->Fields("pri");
		$prio = $pri->value;
		
	$s="select max(tblcountrydistributor.priority) as primax from tblcountrydistributor where countryid=".$countryid;
	$rso = $conn->Execute($s);
	while (!$rso->EOF) {
		$primax = $rso->Fields("primax");
		$primax1 = $primax->value;
		?><tr><td>
		<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f();">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
		<?php ?>
		</td></tr>
		<?php 
		$rso->MoveNext();
	}
	$rs->MoveNext();
	}
	?>
	<script language="javascript" type="text/javascript">
		function f()
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
			   for (j=1;j<=a;j++)
                 {
				   if (myArray[i] == myArray[j])
                       alert("same")
				 }
              }			
		  }
	</script>
	</table></td>
    <td><table>
	<?php
	$sql="select distributorid as dip from tblcountrydistributor where countryid=".$countryid." order by priority";
 
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
		$fv = $rs->Fields("dip");
		$dip=$fv->value;
			$sql1="select * from tbldistributor where id=".$dip;
			$rs1 = $conn->Execute($sql1);
			while (!$rs1->EOF) {
			?>
			<tr><td  bgcolor="#E6E6E6">
			<?php
				
				echo $fv1 = $rs1->Fields("distributor");
				
				$rs1->MoveNext();		
			}
			?>
			</td></tr>
			<?php
		$rs->MoveNext();
	}
				
	if(isset($_REQUEST['save'])){
				
			$cont = new COM("ADODB.Connection") or die("Cannot start ADO");
    $cont->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\testing_fantaay-db\\admin\\disb.mdb");
 
		$sql="select * from tblcountrydistributor where countryid=".$countryid;
		$rss = $cont->Execute($sql);
		while (!$rss->EOF) {
			$priority = $rss->Fields("priority");
			$pi = $priority->value;
			
			$d = $rss->Fields("distributorid");
			$dip= $d->value;
				
			$t = $_POST['t'.$pi];
			$rss->MoveNext();
		$query1="update tblcountrydistributor set priority=".$t." where countryid=".$countryid." and distributorid=".$dip;
		$rss1 = $cont->Execute($query1);
	}
	header('Location: test.php?countryid='.$countryid);
	}
	?></table></td>
    <td  bgcolor="#E6E6E6">
	 <a href="disb_add.php?countryid=<?php echo $countryid; ?>">Add Distributor</a>
	 
	 
	 </td>
  </tr>
</table>
 
<table border="0" bgcolor="#E6E6E6" width="325" >  
  <tr>
    <td bgcolor="#E6E6E6"><b>Detailed List of Disb</b></td>
  </tr>
  <tr>
	<td bgcolor="#E6E6E6" align="center">
	     
</td>
	</tr>
  <tr>
    <td>
	<?php
	$sql="select distributorid as did from tblcountrydistributor where countryid=".$countryid." order by priority";
	
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
	?>
	
	<?php 	
		$fv = $rs->Fields("did");
		$did=$fv->value;
			$sql1="select * from tbldistributor where id=".$did;
			$rs1 = $conn->Execute($sql1);
			while (!$rs1->EOF) {
			?>
			<table border="1" width="100px">
			<tr>
				<td bgcolor="#E6E6E6"><a href='disb_edit.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $rs1->Fields("id");?>'>Edit</a></td>
				<td bgcolor="#E6E6E6"><a href='delete.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $rs1->Fields("id");?>'>Delete</a></td>
			</tr>
			<tr><td colspan="2">
			<?php
				echo $rs1->Fields("distributor");
			?>
			</td></tr>
			<tr><td colspan="2">
			<?php 	
				echo  $rs1->Fields("address");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php 	
				echo  $rs1->Fields("city");
			?>	
			</td></tr>
			<tr><td colspan="2">
			<?php 	
				echo  $rs1->Fields("zip");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo  $rs1->Fields("phone");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo  $rs1->Fields("fax");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo $rs1->Fields("mobile");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo $rs1->Fields("email");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php
				echo $rs1->Fields("website");
			?>
			</td></tr></table>
			<?php	
				echo "<br><br>";
				$rs1->MoveNext();		
			}
			?>
	
			<?php
		$rs->MoveNext();
		?>
			
		<?php 
	}	
	?>
	</table></td>
    
  </tr>
</table>
</form>
<?php
}
?>

Open in new window

0
Graceful_PenguinCommented:
OK does this work if it does not please tell what it does.
	<script language="javascript" type="text/javascript">
		function f()
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
			   for (j=1;j<=a;j++)
                 {
				   if (myArray[i].value == myArray[j].value)
                       alert("same")
				 }
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
u need not review the whole code.
on line 38, i am calling a function f() on the onchange event of dropdown, then on line 60 ,javascript is running.please see the snapshot.

here i have 5 dropdowns , i want that user can't select the same values in the dropdown.
v.bmp
0
Graceful_PenguinCommented:
OK I misunderstud what you wanted. try this.
	<script language="javascript" type="text/javascript">
		function f(Selected)
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
			
			  if (myArray[i].value == Selected.value)
                       alert("same")
			              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
when i refreshed the page and clicked on any option of any dropdown, it shows me alert and that too 5 times because it is in the loop.
as.bmp
0
designersxAuthor Commented:
unction f(Selected) , there is no value passed in the function sir
0
designersxAuthor Commented:
unction  sorry function
0
Graceful_PenguinCommented:
yes on line 35 you should give me the select like this
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this);">

Open in new window

0
designersxAuthor Commented:
nothing is happening with this, please check whether i have written correct.
<script language="javascript" type="text/javascript">
		function f(Selected)
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
				  if (myArray[i].value == Selected.value)
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
Graceful_PenguinCommented:
did you change the code on line 35?
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this);">

Open in new window

0
designersxAuthor Commented:
now sir after testing and adding this, it alerts same only 1 time but every time it alerts even for thr very first time also.
0
designersxAuthor Commented:
even for thr very first time also. means when i select 1 or anything from the dropdown menu.
0
designersxAuthor Commented:
>>did you change the code on line 35?

<< yes sir i have changed it and told u the output above.
0
Graceful_PenguinCommented:
Change the code on line 35-51 to this.
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f();">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option value="<?php
						echo $i;
					?>">
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>

Open in new window

0
Graceful_PenguinCommented:
If we don't solve this soon I will only be able to work on it again tommorrow (in 14 hours)
0
Graceful_PenguinCommented:
Did it work?
0
designersxAuthor Commented:
if i write  onchange="f();">                  like this then what should i write here              function f(Selected),
0
designersxAuthor Commented:
is it right all ?? it alerts the same message every time when we select because we are using onchange="f(this);">

sir if we could not solve the problem then would u come after 14 hours, just asking to u , please don't mind.
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option value="<?php
						echo $i;
					?>">
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
 
 
 
<script language="javascript" type="text/javascript">
		function f(Selected)
		{ //alert(Selected)
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
				  if (myArray[i].value == Selected.value)
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
alert(Selected.value)

alert(myArray[i].value) these both are working fine ,

 it is just that when the user selects the value in the 1st dropdown then  it alerts but it should alert when the user selects any value from any 1st dropdown and then selects the duplicate value from another that is 2nd dropdown menu.


0
designersxAuthor Commented:
Firstly great thanks a lot for being so nice to me devoting

a lot of time on my question and tried ur best to go into

the depth of the question.

WHAT EXACTLY IS HAPPENING NOW IN OUR CODE :-

our loop is working for the individual dropdown box

separately, i mean to say that we have 1-5 values in each

dropdown, our loop i=1 to 5 and selected.value matches the

value in the dropdown box and alerts but in every dropdown

there is 1 to 5 values and we will be selecting any value

and loop is also from 1 to 5 , so it will definately get the

match and thus alerts the message same every time.

at present i think we are checking the selected value in the

dropdown with a single dropdown but we need to check it with

all other dropdown menus and on the basis of that we need to

check and alert the message. please let me know if u have

not understood what i am saying .
0
Graceful_PenguinCommented:
Ok I think this code should fix the alert problem.
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this, $prio);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option value="<?php
						echo $i;
					?>">
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
 
 
 
<script language="javascript" type="text/javascript">
		function f(Selected, SelectNum)
		{ //alert(Selected)
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}
			for (i=1;i<=a;i++)
             {  
				  if ((SelectNum != i) and (myArray[i].value == Selected.value)
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
trying ur code, my alert does not work, still trying, i will shortly give u the report.
0
designersxAuthor Commented:
in line 68, alert does not work but it works when i do not take the 2nd argument $prio,means value of prio is not passed to javascript.
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this,$prio);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
 
 
<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
		  	
			var myArray = document.getElementById("t"+ki)
			}    alert(Selected.value)
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
>>in line 68 ,  this line is 28. if i alert on line 20, alert(Selected.value) then it is not working.
0
Graceful_PenguinCommented:
Ok fixed that too Lets hope it works now!
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this, <?php echo $prio;?>);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
 
 
<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{ 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
		  	
			var myArray = document.getElementById("t"+ki)
			}    alert(Selected.value)
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
value is still not passing, by my logic u have done exactly right but i am also not able to find why the value of 2nd and 1st argument is not passing when we send the 2nd argument.




<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this,<?php echo $prio;?>);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
 
<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{  	alert(Selected) //here alert is not working
			alert(SelectNum) // here alert is not working
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
		  	
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
Graceful_PenguinCommented:
Can you post the onchange of one of the selects in the html? In outher words I want to see if the problem is in php or in JS.
0
designersxAuthor Commented:
yes sir , i am just posting my code, previously wanna discuss something with you.  in php variable $prio, values will be like always like 1,2,3,4,5 in this fashion because i am using order by clause. so i changed my code a little bit but even then it did not work. i am giving u my full code, if u need other code, please let me know.
<?php
session_start();
if($_SESSION['logged']!=1){
	echo "<b>Direct Access to this page is not Authorised</b>";
?>  <a href="index.php"><b>Login</b></a>
<?php
}
else{
$countryid=$_REQUEST['countryid']; 
if(isset($_REQUEST['save'])){
				
			$cont = new COM("ADODB.Connection") or die("Cannot start ADO");
    $cont->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\testing_fantaay-db\\admin\\disb.mdb");
 
		$sql="select * from tblcountrydistributor where countryid=".$countryid;
		$rss = $cont->Execute($sql);
		while (!$rss->EOF) {
			$priority = $rss->Fields("priority");
			$pi = $priority->value;
			
			$d = $rss->Fields("distributorid");
			$dip= $d->value;
				
			$t = $_POST['t'.$pi];
			$rss->MoveNext();
		$query1="update tblcountrydistributor set priority=".$t." where countryid=".$countryid." and distributorid=".$dip;
		$rss1 = $cont->Execute($query1);
	}
	header('Location: Copyoftest.php?countryid='.$countryid);
	}
?>
<form action="Copyoftest.php?countryid=<?php echo $countryid; ?>" method="post" name="form">
<table width="200" border="1" bgcolor="">
  <tr>
    <td bgcolor="#E6E6E6">Priority</td>
    <td bgcolor="#E6E6E6">Distributor</td>
    <td bgcolor="#E6E6E6"><input type="submit" name="save" value="Save The Priority" /></td>
  </tr>
  <tr>	
	
  </tr>
  <tr>
    <td><table bgcolor="#E6E6E6">
	<?php 
	
	$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\testing_fantaay-db\\admin\\disb.mdb");
	$sql="select priority as pri from tblcountrydistributor where countryid=".$countryid." order by priority";
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
		$pri = $rs->Fields("pri");
		$prio = $pri->value;
 
	$s="select max(tblcountrydistributor.priority) as primax from tblcountrydistributor where countryid=".$countryid;
	$rso = $conn->Execute($s);
	while (!$rso->EOF) {
		$primax = $rso->Fields("primax");
		$primax1 = $primax->value; echo $prio;
		?><tr><td>
		<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
		<?php ?>
		</td></tr>
		<?php 
		$rso->MoveNext();
	}
	$rs->MoveNext();
	}
	?>
	<script language="javascript" type="text/javascript">
		function f(Selected)
		{  	//alert(Selected) //here alert is not working
			//alert(SelectNum) // here alert is not working
			
			a = <?php echo $primax1 ?>;
			
			for (ui=1;ui<=a;ui++)
				SelectNum=i;
				
		  var myArray = new Array();	
		  
		  for (ki=1; ki<=a; ki++){
		  	
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>
	</table></td>
    <td><table>
	<?php
	$sql="select distributorid as dip from tblcountrydistributor where countryid=".$countryid." order by priority";
 
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
		$fv = $rs->Fields("dip");
		$dip=$fv->value;
			$sql1="select * from tbldistributor where id=".$dip;
			$rs1 = $conn->Execute($sql1);
			while (!$rs1->EOF) {
			?>
			<tr><td  bgcolor="#E6E6E6">
			<?php
				
				echo $fv1 = $rs1->Fields("distributor");
				
				$rs1->MoveNext();		
			}
			?>
			</td></tr>
			<?php
		$rs->MoveNext();
	}
				
	
	?></table></td>
    <td  bgcolor="#E6E6E6">
	 <a href="disb_add.php?countryid=<?php echo $countryid; ?>">Add Distributor</a>
	 
	 
	 </td>
  </tr>
</table>
 
<table border="0" bgcolor="#E6E6E6" width="325" >  
  <tr>
    <td bgcolor="#E6E6E6"><b>Detailed List of Disb</b></td>
  </tr>
  <tr>
	<td bgcolor="#E6E6E6" align="center">
	     
</td>
	</tr>
  <tr>
    <td>
	<?php
	$sql="select distributorid as did from tblcountrydistributor where countryid=".$countryid." order by priority";
	
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
	?>
	
	<?php 	
		$fv = $rs->Fields("did");
		$did=$fv->value;
			$sql1="select * from tbldistributor where id=".$did;
			$rs1 = $conn->Execute($sql1);
			while (!$rs1->EOF) {
			?>
			<table border="1" width="100px">
			<tr>
				<td bgcolor="#E6E6E6"><a href='disb_edit.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $rs1->Fields("id");?>'>Edit</a></td>
				<td bgcolor="#E6E6E6"><a href='delete.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $rs1->Fields("id");?>'>Delete</a></td>
			</tr>
			<tr><td colspan="2">
			<?php
				echo $rs1->Fields("distributor");
			?>
			</td></tr>
			<tr><td colspan="2">
			<?php 	
				echo  $rs1->Fields("address");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php 	
				echo  $rs1->Fields("city");
			?>	
			</td></tr>
			<tr><td colspan="2">
			<?php 	
				echo  $rs1->Fields("zip");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo  $rs1->Fields("phone");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo  $rs1->Fields("fax");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo $rs1->Fields("mobile");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo $rs1->Fields("email");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php
				echo $rs1->Fields("website");
			?>
			</td></tr></table>
			<?php	
				echo "<br><br>";
				$rs1->MoveNext();		
			}
			?>
	
			<?php
		$rs->MoveNext();
		?>
			
		<?php 
	}	
	?>
	</table></td>
    
  </tr>
</table>
</form>
<?php
}
?>

Open in new window

0
designersxAuthor Commented:
changed my code exactly to the previous one as u guided me.
<?php
session_start();
if($_SESSION['logged']!=1){
	echo "<b>Direct Access to this page is not Authorised</b>";
?>  <a href="index.php"><b>Login</b></a>
<?php
}
else{
$countryid=$_REQUEST['countryid']; 
if(isset($_REQUEST['save'])){
				
			$cont = new COM("ADODB.Connection") or die("Cannot start ADO");
    $cont->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\testing_fantaay-db\\admin\\disb.mdb");
 
		$sql="select * from tblcountrydistributor where countryid=".$countryid;
		$rss = $cont->Execute($sql);
		while (!$rss->EOF) {
			$priority = $rss->Fields("priority");
			$pi = $priority->value;
			
			$d = $rss->Fields("distributorid");
			$dip= $d->value;
				
			$t = $_POST['t'.$pi];
			$rss->MoveNext();
		$query1="update tblcountrydistributor set priority=".$t." where countryid=".$countryid." and distributorid=".$dip;
		$rss1 = $cont->Execute($query1);
	}
	header('Location: Copyoftest.php?countryid='.$countryid);
	}
?>
<form action="Copyoftest.php?countryid=<?php echo $countryid; ?>" method="post" name="form">
<table width="200" border="1" bgcolor="">
  <tr>
    <td bgcolor="#E6E6E6">Priority</td>
    <td bgcolor="#E6E6E6">Distributor</td>
    <td bgcolor="#E6E6E6"><input type="submit" name="save" value="Save The Priority" /></td>
  </tr>
  <tr>	
	
  </tr>
  <tr>
    <td><table bgcolor="#E6E6E6">
	<?php 
	
	$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\\wamp\\www\\testing_fantaay-db\\admin\\disb.mdb");
	$sql="select priority as pri from tblcountrydistributor where countryid=".$countryid." order by priority";
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
		$pri = $rs->Fields("pri");
		$prio = $pri->value;
 
	$s="select max(tblcountrydistributor.priority) as primax from tblcountrydistributor where countryid=".$countryid;
	$rso = $conn->Execute($s);
	while (!$rso->EOF) {
		$primax = $rso->Fields("primax");
		$primax1 = $primax->value;
		?><tr><td>
		<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onchange="f(this,<?php echo $prio; ?>);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
		<?php ?>
		</td></tr>
		<?php 
		$rso->MoveNext();
	}
	$rs->MoveNext();
	}
	?>
	<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{  	//alert(Selected) //here alert is not working
			//alert(SelectNum) // here alert is not working
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
		  	
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>
	</table></td>
    <td><table>
	<?php
	$sql="select distributorid as dip from tblcountrydistributor where countryid=".$countryid." order by priority";
 
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
		$fv = $rs->Fields("dip");
		$dip=$fv->value;
			$sql1="select * from tbldistributor where id=".$dip;
			$rs1 = $conn->Execute($sql1);
			while (!$rs1->EOF) {
			?>
			<tr><td  bgcolor="#E6E6E6">
			<?php
				
				echo $fv1 = $rs1->Fields("distributor");
				
				$rs1->MoveNext();		
			}
			?>
			</td></tr>
			<?php
		$rs->MoveNext();
	}
				
	
	?></table></td>
    <td  bgcolor="#E6E6E6">
	 <a href="disb_add.php?countryid=<?php echo $countryid; ?>">Add Distributor</a>
	 
	 
	 </td>
  </tr>
</table>
 
<table border="0" bgcolor="#E6E6E6" width="325" >  
  <tr>
    <td bgcolor="#E6E6E6"><b>Detailed List of Disb</b></td>
  </tr>
  <tr>
	<td bgcolor="#E6E6E6" align="center">
	     
</td>
	</tr>
  <tr>
    <td>
	<?php
	$sql="select distributorid as did from tblcountrydistributor where countryid=".$countryid." order by priority";
	
	$rs = $conn->Execute($sql);
	while (!$rs->EOF) {
	?>
	
	<?php 	
		$fv = $rs->Fields("did");
		$did=$fv->value;
			$sql1="select * from tbldistributor where id=".$did;
			$rs1 = $conn->Execute($sql1);
			while (!$rs1->EOF) {
			?>
			<table border="1" width="100px">
			<tr>
				<td bgcolor="#E6E6E6"><a href='disb_edit.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $rs1->Fields("id");?>'>Edit</a></td>
				<td bgcolor="#E6E6E6"><a href='delete.php?countryid=<?php echo $countryid; ?>&distributorid=<?php echo $rs1->Fields("id");?>'>Delete</a></td>
			</tr>
			<tr><td colspan="2">
			<?php
				echo $rs1->Fields("distributor");
			?>
			</td></tr>
			<tr><td colspan="2">
			<?php 	
				echo  $rs1->Fields("address");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php 	
				echo  $rs1->Fields("city");
			?>	
			</td></tr>
			<tr><td colspan="2">
			<?php 	
				echo  $rs1->Fields("zip");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo  $rs1->Fields("phone");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo  $rs1->Fields("fax");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo $rs1->Fields("mobile");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php	
				echo $rs1->Fields("email");
			?>	
			</td></tr>
			<tr><td colspan="2">	
			<?php
				echo $rs1->Fields("website");
			?>
			</td></tr></table>
			<?php	
				echo "<br><br>";
				$rs1->MoveNext();		
			}
			?>
	
			<?php
		$rs->MoveNext();
		?>
			
		<?php 
	}	
	?>
	</table></td>
    
  </tr>
</table>
</form>
<?php
}
?>

Open in new window

0
designersxAuthor Commented:
60 to 73 there is  a php, 82 to 98 there is a javascript.
0
designersxAuthor Commented:
see the view source snapshot, and it shows that there is no problem in php. again i doubt think do we both targeting at the same thing. can u please tell me in 1 line about what u targeted if u don't mind. i know u are right, it's just to confirm. please don't mind.
qq.bmp
0
Graceful_PenguinCommented:
No what i want is the html page that is generated by this script. I want to see if the values are outputted correctly.
0
Graceful_PenguinCommented:
Sorry did not see that last post
0
Graceful_PenguinCommented:
I think the problem is onChange not onchange.
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onChange="f(this,<?php echo $prio;?>);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
 
<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{  	alert(Selected) //here alert is not working
			alert(SelectNum) // here alert is not working
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
		  	
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
value of SelectNum will always be in the sequence according to the loop, means first time 1 2nd time 2 and so on...... do u agree with this..
0
designersxAuthor Commented:
if i give u whole project , can u test at ur localhost.  it is very little, just 10 pages, u just test it. i converting the php extensions to php.txt to upload and for u to see. please convert them and test.
0
designersxAuthor Commented:
see my full code and please run it converting the extensions to php.
Copy-of-testing-fantaay-db.zip
0
Graceful_PenguinCommented:
First post: Yes that is correct.
Second post: NO I can't.

Have you tested the code I posted because I think it should work now. I tested the JS and the onChange should be camelcase to work. And We both saw that the php works.
0
designersxAuthor Commented:
First post: Yes that is correct.
Second post: NO I can't.

can't get u???? code of changing the onchange to onChange, yes that tried but not working. now i come to know i think we are passing a wrong value of 2nd argument because dropdown name is t1,t2 and so on and we are passing 1,2,3 ..... this i am testing now.
0
designersxAuthor Commented:
i made a simple app, and that is working. but i don't find a reason why 2nd argument is not alerting
<?php for($i=1;$i<=5;$i++){  ?>
<select name="n" onchange="f(this,<?php echo $i ?>);">
	<option selected="selected">a</option>
	<option>b</option>
	<option>c</option>
	<option>d</option>
</select>
<?php } ?>
 
<script>
function f(number,num){
	//alert(number.value)
	alert(num)
}
</script>

Open in new window

0
designersxAuthor Commented:
my latest code is this.
$s="select max(tblcountrydistributor.priority) as primax from tblcountrydistributor where countryid=".$countryid;
	$rso = $conn->Execute($s);
	while (!$rso->EOF) {
		$primax = $rso->Fields("primax");
		$primax1 = $primax->value;
		?><tr><td>
		<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onChange="f(this, <?php echo 't'.$prio ?>);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option>
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
		<?php ?>
		</td></tr>
		<?php 
		$rso->MoveNext();
	}
	$rs->MoveNext();
	}
	?>
	<script language="javascript" type="text/javascript">
		function f(Selected, SelectNum)
		{  	//alert(Selected) //here alert is not working
			alert(SelectNum) // here alert is not working
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum == i) and (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>

Open in new window

0
designersxAuthor Commented:
now see , both values passes when i commented this for loop

for (i=1;i<=a;i++)
             {
                          if ((SelectNum == i) and (myArray[i].value == Selected.value))
                       alert("same")
              }

that means surely there is a problem in that.
<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{  	
			alert(SelectNum) // here alert is working when i  commented the below for loop
 
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			
			//for (i=1;i<=a;i++)
             //{
				  //if ((SelectNum == i) and (myArray[i].value == Selected.value))
                      // alert("same")
              //}			
		  }
	</script>

Open in new window

0
Graceful_PenguinCommented:
There this code must work
<select id="<?php echo 't'.$prio; ?>" name="<?php echo 't'.$prio; ?>" onChange="f(this,<?php echo $prio; ?>);">
		<option selected="selected">Select</option>
		<?php 
					for($i=1;$i<=$primax1;$i++){
					?>
			<option value="<?php echo $i; ?>">
				<?php
						echo $i;
					?>
			</option>
				<?php 
					}
				?>
		</select>
 
<script language="javascript" type="text/javascript">
		function f(Selected,SelectNum)
		{  	
		//alert(Selected) //here alert is not working
			//alert(SelectNum) // here alert is not working
		  var myArray = new Array();	
		  a = <?php echo $primax1 ?>;
		  for (ki=1; ki<=a; ki++){
			var myArray = document.getElementById("t"+ki)
			}    //alert(Selected.value)
			
			for (i=1;i<=a;i++)
             {
				  if ((SelectNum != i) && (myArray[i].value == Selected.value))
                       alert("same")
              }			
		  }
	</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
designersxAuthor Commented:
if ((SelectNum == i) and (myArray[i].value == Selected.value))

this single line is creating a problem sir, i request you to please review it,i will be thankful to you.
0
designersxAuthor Commented:
written

 if ((SelectNum != i) and (myArray[i].value == Selected.value)) ,still a problem
0
Graceful_PenguinCommented:
yes I fixed it. See my last post. But I am going to have to go away for the weekend now so I hope this last one works. Goodluck
0
designersxAuthor Commented:
sir i want to hug you, u are like a god to me , now i will write a testimonials for you. u deserve a complete 500 from me. sir i can't express my feelings how happy i am by solving it. hhhhaaaa.........thanks my guru thanks my teacher thanks expert, u r fantabulous seriously.
0
Graceful_PenguinCommented:
I am glad that I was able to help you and thanks for giving me more points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.