disable text feilds based on list selection

Discussion in 'JavaScript' started by ciuchs, Mar 8, 2009.

  1. #1
    I am trying to enable/disable text fields based on what the user selects from a drop down list. if the user selects email then only the email field will be available to the user and so forth for the other fields. I am new to JS and could use some help. thanks

    
    <form action="nextalumni.php" method="post" name="alumni">
        	<label>&dagger; If yes to the above question, how may we contact you?</label>
            <select name="Method" id="Method_Select">
              <option value="" selected="selected">--</option>
              <option value="Email" >Email</option>
              <option value="Phone">Phone</option>
              <option value="Mail">Mail</option>
              <option value="Email&Phone">Email & Phone</option>
              <option value="Email&Mail">Email & Mail</option>
              <option value="Phone&Mail">Phone & Mail</option>
              <option value="All">All methods</option>
            </select>
    <input name="Email" type="text" size="35"  />
    <input name="Address" type="text" size="35" />
    <input name="City" type="text" size="25" />
    <select name="State" >
        		<option value="" selected="selected">Choose a State</option>
        		<option value="UNK">Outside US / Canada</option>
        		<option value="AL">Alabama</option>
    </select>
    <input name="Zipcode" type="text" size="15" />
    </form>
    
    Code (markup):
    I shortened the state option just to keep the post short
    again thanks
     
    ciuchs, Mar 8, 2009 IP
  2. shubhamjain1

    shubhamjain1 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not tested.!!!

    
    <form action="nextalumni.php" method="post" name="alumni">
        	<label>&dagger; If yes to the above question, how may we contact you?</label>
            <select name="Method" id="Method_Select">
              <option value="" selected="selected">--</option>
              <option value="Email" onclick="document.getElementById('Address').disabled=true;document.getElementById('City').disabled=true;">Email</option>
              <option value="Phone">Phone</option>
              <option value="Mail">Mail</option>
              <option value="Email&Phone">Email & Phone</option>
              <option value="Email&Mail">Email & Mail</option>
              <option value="Phone&Mail">Phone & Mail</option>
              <option value="All">All methods</option>
            </select>
    <input name="Email"  id="Email" type="text" size="35"  />
    <input name="Address"  id="Address" type="text" size="35" />
    <input name="City" id="City" type="text" size="25" />
    <select name="State" >
        		<option value="" selected="selected">Choose a State</option>
        		<option value="UNK">Outside US / Canada</option>
        		<option value="AL">Alabama</option>
    </select>
    <input name="Zipcode" type="text" size="15" />
    </form>
    
    Code (markup):
     
    shubhamjain1, Mar 9, 2009 IP
  3. ciuchs

    ciuchs Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    worked thanks
     
    ciuchs, Mar 9, 2009 IP