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>

Recommended Answers

All 7 Replies

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…

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

how can i do this in php?

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.

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.

instead of

<? echo $c = uniqid(); ?>

try this

<? $c = uniqid(); echo $c; ?>
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.