0

why this code is not working? can any one help me?

<select id="cboOptions" name="cbo0ptions"  onChange="displayDiv(this.value)">
    <option selected="selected" value="">choose</option>
	<option value="1">Order 1</option>
	<option value="2">Order 2</option>
	<option value="3">Order 3</option>
	<option value="4">Order 4</option>
	</select>


<div id="1" style="display:none;">
<fieldset>
            <legend>order line</legend>
<table>
<tr><td>Item ID</td><td><input type="text" readonly="" value="<? echo $c = uniqid(); ?>" /></td></tr>
<tr><td>Item Description</td><td><input type="text" /></td></tr>
<tr><td>Item quantity</td><td><input type="text" /></td></tr>
<tr><td>Item price</td><td><input type="text" /></td></tr>
</table>
</fieldset>
</div>

		<div id="2"  style="display:none"><fieldset>
            <legend>order line</legend><table>
<tr><td>Item ID</td><td><input type="text" readonly="" value="<? echo $c = uniqid(); ?>" /></td></tr>
<tr><td>Item Description</td><td><input type="text" /></td></tr>
<tr><td>Item quantity</td><td><input type="text" /></td></tr>
<tr><td>Item price</td><td><input type="text" /></td></tr>
</table>
</fieldset>
</div>
	
	
		<div id="3"  style="display:none"><fieldset>
            <legend>order line</legend><table>
<tr><td>Item ID</td><td><input type="text" readonly="" value="<? echo $c = uniqid(); ?>" /></td></tr>
<tr><td>Item Description</td><td><input type="text" /></td></tr>
<tr><td>Item quantity</td><td><input type="text" /></td></tr>
<tr><td>Item price</td><td><input type="text" /></td></tr>
</table>
</fieldset>
</div>


		<div id="4"  style="display:none"><fieldset>
            <legend>order line</legend><table>
<tr><td>Item ID</td><td><input type="text" readonly="" value="<? echo $c = uniqid(); ?>" /></td></tr>
<tr><td>Item Description</td><td><input type="text" /></td></tr>
<tr><td>Item quantity</td><td><input type="text" /></td></tr>
<tr><td>Item price</td><td><input type="text" /></td></tr>
</table>
</fieldset>
</div>


<script type="text/javascript">

function displayDiv(id){
 //var div = document.getElementById(id+sel.selectedIndex);
// if (div) div.style.display = 'block';
 switch (id)
{
case 1:
 // code to be executed if n=label1;
 document.getElementById('id').style.display='block';
  break;
case 2:
  //code to be executed if n=label2;
  document.getElementById('id').style.display='block';
  break;
  case 3:
  //code to be executed if n=label2;
  document.getElementById('id').style.display='block';
  break;
  case 4:
  //code to be executed if n=label2;
  document.getElementById('id').style.display='block';
  break;
default:
  //code to be executed if n is different from both label1 and label2;
  document.getElementById('id').style.display='none';
}
}

</script>
4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by jkon
0

I don’t see even a single line of PHP in this code … only JavaScript that is not bad … but not your question … what do you expect this markup to do ? and what it really does ? If the problem is in JavaScript just tell us about verifications that you need…

0

i want to hide/show div by div ID through combobox but code is not working

0

There are some embedded markup languages that a browser can understand and compile like JavaScript. PHP is a server side language and you can’t do anything in a browser only using AJAX that it needs feedback from the server.

0

Latest versions of php don't support the short php tag you have used. For example, you have used <? echo $c = uniqid(); ?> , such short tags are no more supported in latest php versions, use the complete php tags in the following way
<?php echo $c = uniqid(); ?> and your problem would be solved.

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.