0

Hello, I'm using php code to retrieving an array from database and place the result into checkboxes but after the last checkbox input there is text input (hidden by default) and the last check box name is 'other'. I want to make the text in visible if 'other' is checked i used this code:

<script type="text/javascript">
			if (document.getElementById('other').checked = true) { 
			document.getElementById('whatever').style.visibility = "visible"; 
			} else { 
			document.getElementById('whatever').style.visibility = "hidden"; 
			} 
			
</script> 
<input name="pVital[]" type="checkbox" id="pVital[]" value="I &amp; O" checked="<?php if (in_array('I &amp; O', $pvitals)) echo "checked"; else echo "unchecked"; ?>" />I &amp; O<br/>
   	  <input <?php if (in_array('Daily Weight', $pvitals)) echo "checked"; else echo "unchecked";  ?> name="pVital[]" type="checkbox" id="pVital[]" value="Daily Weight" />Daily Weight<br/>
   	  <input <?php if (in_array('Foley Catheter', $pvitals)) echo "checked"; else echo "unchecked"; ?> name="pVital[]" type="checkbox" id="pVital[]" value="Foley Catheter" />Foley Catheter<br/>
   	  <input <?php if (in_array('other', $pvitals)) echo "checked"; else echo "unchecked"; ?> name="pVital[]" type="checkbox" id="other"  value="other" />Other<br/>
        <input name="pVital[]" type="text" id="whatever" style="visibility: hidden;" value="<?php if (in_array('other', $pvitals)) echo end($pvitals); ?>">

but this is not work :(
Just i want to make this text input visible whenever 'other' is checked and not necessary wither event is occurred or not.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by divyakrishnan
0

Try this code

<script type="text/javascript">
			if (document.getElementById('other').checked = true) { 
			document.getElementById('whatever').style.visibility = "visible"; 
			} else { 
			document.getElementById('whatever').style.visibility = "hidden"; 
			} 
			
</script> 
<input name="pVital[]" type="checkbox" id="pVital[]" value="I &amp; O" checked="<?php if (in_array('I &amp; O', $pvitals)) echo "checked"; else echo "unchecked"; ?>" />I &amp; O<br/>
   	  <input <?php if (in_array('Daily Weight', $pvitals)) echo "checked"; else echo "unchecked";  ?> name="pVital[]" type="checkbox" id="pVital[]" value="Daily Weight" />Daily Weight<br/>
   	  <input <?php if (in_array('Foley Catheter', $pvitals)) echo "checked"; else echo "unchecked"; ?> name="pVital[]" type="checkbox" id="pVital[]" value="Foley Catheter" />Foley Catheter<br/>
   	  <input <?php if (in_array('other', $pvitals)) echo "checked"; else echo "unchecked"; ?> name="pVital[]" type="checkbox" id="other"  value="other" />Other<br/>
        <input name="pVital[]" type="text" id="whatever"   <?php if (in_array('other', $pvitals)) { ?>  style="visibility: visible;"   <?php } else { ?>    style="visibility:hidden" <?php } ?>  value="<?php if (in_array('other', $pvitals)) echo end($pvitals); ?>">
0

Thank you divyakrishnan, this is work fine after little change in last line because it contain "duplicate attribute" error I change it to: <input name="pVital[]" type="text" id="whatever" <?php if (in_array('other', $pvitals)) { $vis = 'style="visibility: visible;"'; echo $vis; ?> <?php } else { ?> style="visibility:hidden" <?php } ?> value="<?php if (in_array('other', $pvitals)) echo end($pvitals); ?>"> and it works. Thank you again :)

This question has already been answered. 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.