A small php 'ifelse' coding, help needed

Discussion in 'PHP' started by surya, Dec 29, 2008.

  1. #1
    i've attached an image..
    what i want is,
    the checkboxes/radio buttons below metro should not be enabled if metro is checked..
    if metro is not clicked, the 1000 metres above mean sea level & Notified Hill area should be enabled only if Hillstation Resident is clicked..
    any tips would be of much help to me..
    thanks
     

    Attached Files:

    surya, Dec 29, 2008 IP
  2. anthonyr

    anthonyr Peon

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mmmmm.... i guess you can use this coding:

    for metro checkbox add : name="metro"...

    And then start the PHP programming e.g:

    <?PHP
    $metro = $_POST['metro'];
    
    if(!isset($metro)){ ?> //and you add the other checkboxes or radio buttons
    
    <?; } 
    
    else{?> //add some text or anything... 
    <?;}?>  
    PHP:
     
    anthonyr, Dec 29, 2008 IP
  3. surya

    surya Peon

    Messages:
    720
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    @ anthonyr
    cool.. thanks mate..
    gonna try now
     
    surya, Dec 29, 2008 IP
  4. surya

    surya Peon

    Messages:
    720
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it didnt work :(
    here is the code for it,
    <form submit="step2.html">
    <p>Name:<input type="text" name="name">
    <p>Type:
    <input type="radio" name="male" value="true"> Male
    <input type="radio" name="female" value="false"> Female
    <input type="radio" name="child" value="false"> Child</input>
    <p>Living/Working in <input type="radio" name="metro" value="false">Metro</input>
    <p><input type="checkbox" name="hill" value="false">  Hillstation Resident: </input>
    <p><input type="radio" name="hill1000" value="false"> 1000 metres above mean sea level </input>
    <p><input type="radio" name="hillnotified" value="false"> Notified Hill area </input>
    <p><input type="checkbox" name="under" value="false"> Working in mines </input>
    <p><input type="checkbox" name="island" value="false"> Living in Island </input>
    <p><input type="submit" value="submit">
    </form>
    Code (markup):
    even if not all, can anyone atleast tell how to make the following?

    if the radio button metro is enabled, everything below should be disabled..?
     
    surya, Dec 29, 2008 IP
  5. anthonyr

    anthonyr Peon

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <form action="<? $_SERVER['PHP_SELF'];?>">
    <p>Name:<input type="text" name="name">
    <p>Type:
    <input type="radio" name="male" value="true"> Male
    <input type="radio" name="female" value="false"> Female
    <input type="radio" name="child" value="false"> Child
    <p>Living/Working in <input type="radio" name="metro" >Metro
    <? $metro = $_POST['metro'];
    if(!isset($metro)){ echo" <p><input type='checkbox' name='hill' value='false'> Hillstation Resident: </p>
    <p><input type='checkbox' name='under' > Working in mines </p>
    <p><input type='checkbox' name='island' > Living in Island </p>
    " ;
    $hill =$_POST['hill'];
    if(isset($hill)){echo " <p><input type='radio' name='hill1000' > 1000 metres above mean sea level </p>
    <p><input type='radio' name='hillnotified' > Notified Hill area </p>";}
    else{;} }?>
    <input type="submit" value="submit">
    </form>


    this must work... but youll find the extra options after hitting the submit button... or else you will have to use some javascript... gd luck then... try this one and tell me if there are any mistakes as i haven't tested it...
     
    anthonyr, Dec 30, 2008 IP
    surya likes this.
  6. anthonyr

    anthonyr Peon

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    here is what i came up with javascript... P.S: in the attached files..


    P.S: Convert Both *.txt files to .js files...


    there's still one more file i can't upload ill post it directly here and u name it :
    jquery-1.2.6.pack and save it as .js file... too bad im not able to send the last file... so give me some email so i could send the file to...
     

    Attached Files:

    anthonyr, Jan 1, 2009 IP