Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable / Enable form value..

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i have a check box and a value list on a form. These are generated within php. Each check box has the same name but dirrerent id and each value list has the same name but different id..

How can i check the select box to disable the value list, and set the value to "". And how can i un select the Check box and re-enable the value list??

Here is the code for my check box at the moment...

Code:
<input type="checkbox" class="button" name="NotRemoved[]" id="<?php echo $Unique_ID?>" value="<?php echo $Unique_ID?>"/></input>

Here is the code for my value list..

Code:
<select name="BinNumber[]" class="button" id="<?php echo $Unique_ID?>">
  			  		<option value=""></option>
            		<option value="1">1</option>
					<option value="2">2</option>
 					<option value="3">3</option>
 					<option value="4">4</option>
 					<option value="5">5</option>
  					<option value="6">6</option>
 					<option value="7">7</option>
 					<option value="8">8</option>
  					<option value="9">9</option>
  					<option value="10">10</option>
				</select>

Please can anyone help!!!

Kindest regards,

Brian
 
something like this?

Code:
<script langauge="javascript">
var cSelection = 0;
function toggleDropDown(a,b) {
	var ddl = document.getElementById(a);
	var cbx = document.getElementById(b);
	if (cbx.checked) {
		cSelection = ddl.selectedIndex;
		ddl.selectedIndex = 0;
		ddl.disabled = true;
	} else {
		ddl.selectedIndex = cSelection;
		ddl.disabled = false;
	}
}
</script>

<input type="checkbox" class="button" name="NotRemoved[]" id="cbx" value="value" onclick="toggleDropDown('ddl',this.id)";/></input>
<select name="BinNumber[]" class="button" id="ddl">
	<option value=""></option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
	<option value="10">10</option>
</select>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Hi, thanks for your reply! It works fine however it modifies the name of the id - which stops my value being updated in the myqsl database...

this is what i have done... have put an x infront of the unique id as without it the check box comes disabled.

Code:
				<input type="checkbox" class="button" name="NotRemoved[]" id="<?php echo $Unique_ID?>" value="<?php echo $Unique_ID?>" onclick="toggleDropDown('x<?php echo $Unique_ID?>',this.id)";/></input>
</input>
                 </td> 
                 <td>
                 <select name="BinNumber[]" class="button" id="x<?php echo $Unique_ID?>">
  			  		<option value=""></option>
            		<option value="1">1</option>
					<option value="2">2</option>
 					<option value="3">3</option>
 					<option value="4">4</option>
 					<option value="5">5</option>
  					<option value="6">6</option>
 					<option value="7">7</option>
 					<option value="8">8</option>
  					<option value="9">9</option>
  					<option value="10">10</option>
				</select>
                 <input name="BinNumberID[]" type="hidden" id="<?php echo $Unique_ID?>" value="<?php echo $Unique_ID?>" />

the only other way is to strip the x off the front of the value before i process it, i think???

Many thanks,

Brian
 
so do you have it working, or do you need something else? I don't know what the rest of your code looks like so I can't help (if you need it) with the sql stuff....

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Sorry! I need to modify my code to work with it! As the unique id is prefixed with an 'x', please can you show me how to remove it, below is the bit of the code i am useing...

Code:
 for ($i=0; $i < count($_POST['BinNumberID']); $i++) {
                $BinNumberID = $BinNumberID . $_POST['BinNumberID'][$i] . " "; 
				$chk .= $_POST['BinNumberID'][$i] . "," ;
		  	    $_SESSION['BinNumberID']=$BinNumberID;

etc...


many thanks

Brian
 
I'm too new to PHP to write that for you...perhaps this will help:



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top