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!

if checkbox checked....

Status
Not open for further replies.

speedyrudolf

Programmer
Sep 2, 2009
27
0
0
RO
Hi. I'm making a website that includes a form, and I kind of hit a bump with the php.
Code:
PHP:
{for($i=0; $i<22; $i++)
    {if($_POST["Navs".$i]=='ON')
     {$message.=$i.", ";}}

HTML:
<tr><td width="425"><input type="checkbox" id="Navs0" onClick="Cont_pag5_3()"><img name="But_nav" src="buttons/a_la_carte_p1.jpg" onMouseOver="Nav_but(0, 0)" onMouseOut="Nav_but(1, 0)" onMouseDown="Nav_but(2, 0)" onMouseUp="Nav_but(0, 0)"></td>
<td width="425"><input type="checkbox" id="Navs1" onClick="Cont_pag5_3()"><img name="But_nav" src="buttons/artemis_p1.jpg" onMouseOver="Nav_but(0, 1)" onMouseOut="Nav_but(1, 1)" onMouseDown="Nav_but(2, 1)" onMouseUp="Nav_but(0, 1)"></td></tr>
<tr><td width="425"><input type="checkbox" id="Navs2" onClick="Cont_pag5_3()"><img name="But_nav" src="buttons/aura_p1.jpg" onMouseOver="Nav_but(0, 2)" onMouseOut="Nav_but(1, 2)" onMouseDown="Nav_but(2, 2)" onMouseUp="Nav_but(0, 2)"></td>
<td width="425"><input type="checkbox" id="Navs3" onClick="Cont_pag5_3()"><img name="But_nav" src="buttons/avail_p1.jpg" onMouseOver="Nav_but(0, 3)" onMouseOut="Nav_but(1, 3)" onMouseDown="Nav_but(2, 3)" onMouseUp="Nav_but(0, 3)"></td></tr>
ETC to Navs21
The problem is that the php doesn't "see" if the checkboxes ar checked or not, so that part of $message remains empty...What am I doing wrong? Thank you in advance. Bye.
 
Code:
for($i=0; $i<22; $i++){
   if(empty($_POST["Navs".$i])){
       //checkbox is OFF
   } else {
       //checkbox is ON
   }
}

unchecked checkboxes are not submitted by browsers. so you need to test for their absence.
 
well, you might want to give the <input> elements a name value. that's considered 'necessary' in the web-design world.
 
so...it doesn't work with id...??
ok...be back with another post in about 5 minutes...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top