Jump to content

How To Disable A Field Only For A Specific Scenarios


heshan

Recommended Posts

Hi All,

 

I have a student form which is used to select grade, class, stream and payment status from drop down lists. Thereafter it can be used to generate reports which are useful when finding students who are paid student fees and who are not paid fees.

 

The 'stream' field ONLY uses when the user selects grade 12 or 13. Otherwise it should be disabled. How this can be achieved using javascript and PHP?? I have tried something like this. But it is not working...

 

if(grade >=1 && grade<= 11): echo " disabled"; endif; ?>>

 

  <tr>
    <td> </td>
    <td width="117" align="center"><label>Grade</label>
	   </td>
    <td width="69"><label>
	  <select name="grade" id="select2">
	    <option>1</option>
	    <option>2</option>
	    <option>3</option>
	    <option>4</option>
	    <option>5</option>
	    <option>6</option>
	    <option>7</option>
	    <option>8</option>
	    <option>9</option>
	    <option>10</option>
	    <option>11</option>
	    <option>12</option>
	    <option>13</option>
			    </select>
    </label></td>
    <td width="1" align="center"> </td>
    <td align="center"><label>Class</label>
	   </td>
    <td width="71"><label>
	  <select name="class" id="select3">
	    <option>A</option>
	    <option>B</option>
	    <option>C</option>
	    <option>D</option>
	    <option>E</option>
	    <option>F</option>
			    </select>
    </label></td>
    <td width="69" align="center"><label>Stream</label>
	   </td>
    <td><select name="stream" id="jumpMenu3" <?php if(grade >=1 && grade<= 11): echo " disabled"; endif; ?>>
	    <option>Maths</option>
	    <option>Science</option>
	    <option>Commerce</option>
	    <option>Art</option>
    </select></td>
  </tr>
  <tr>
    <td colspan="2">Payment Status</td>
    <td colspan="2"><label>
	  <select name="payment_status" id="select">
	    <option value="Y">Paid</option>
	    <option value="N">Not Paid</option>
	  </select>
    </label></td>
    <td> </td>
    <td colspan="2"> </td>
    <td> </td>
  </tr>
  <tr>

Link to comment
Share on other sites

For one, In PHP variables start with a $. And $grade needs to be defined.

 

But if you're saying that immediately when the user selects 12 or 13, the field should be enabled, yes, that has to be javascript. Of which you have written none.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.