SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy clicking on yes radio button want to activate text box how??

    hello friends,

    actually i am new with javascript. please help me.

    i have radio button, and one text box, i want my text box activate only when i click "YES" radio button.

    following is the html code for it
    HTML Code:
    <div class="ro">
    <label class="col1">ICU:</label>
    <? if($icu == "Y" ){ ?>
    
    <span class="col4b"><input type="radio" name="icu" id="icu" checked="checked" title="Select your medical council" value="Y" onchange="disabStatecouncil(this.value,regiFrm);" /> Medical Council of India
    <? }else if($icu == "N"){ ?>
    <input type="radio" name="icu" id="icu" disabled="disabled"  title="Select your medical council" value="N" onchange="disabStatecouncil(this.value,regiFrm);" /> Medical Council of India
    <label class="col1">[If yes] No. of ICU Beds:</label><? }?>
    <? if($icu == "Y"){ ?>
    <span class="col2"><input type="text" name="no_of_bed_icu" id="no_of_bed_icu" title="Enter your medical council" value="no_of_bed_icu" size="25" class="textbox"  />
    <? }else{ ?>
    <input type="text" name="no_of_bed_icu" id="no_of_bed_icu" disabled="disabled" title="Enter your medical council" value="no_of_bed_icu" size="25" onfocus="this.value='';" class="textbox"  />
    <? } ?>
    </label><br />
    </span>
    </div>
    and javascript code is as follows,
    Code JavaScript:
    ffunction disabStatecouncil(councilVal,cont){
     
       if(councilVal == "N"){
          cont.icu.disabled = true;
       }
       else if(councilVal == "Y"){
       frmName.stateCouncil.disabled = false;
       }
     }
    please tell me what to do?
    thanks in advance.

  2. #2
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi i hope the below link helps you..
    http://www.w3schools.com/js/tryit.as...yjs_form_radio

  3. #3
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks prakar for your quick reply.
    but that wont help me. because i don't want radio buttons value in my text box.
    when user click on yes radio button he/she should allowed to write in text box.
    i want something like that.

    any suggesion?

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The php code you have will only display one radio button either Yes or No - so there is no choice to make.

    Once you get that fixed, you can flip the display attribute of the text box using javascript:
    Code:
    function disabStatecouncil(councilVal,cont){
     
       if(councilVal == "N"){
          cont.no_of_bed_icu.disabled = "disabled";
       }
       else if(councilVal == "Y"){
          cont.no_of_bed_icu.disabled = "";
       }
    }

  5. #5
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face still one problem

    thanks jimfraser, yesterday only i found this solution but thanks a lot,

    still i have one problem when i click on "Yes" and when i will come to end of my form means on Submit i want to check if radio buttons value is "Yes" than you cant leave the text box empty sort of
    Code JavaScript:
    else if((document.cont.icu.value =="Y") && (document.cont.no_of_bed_icu.value !=""))
    						{
    							alert("Please enter No. of beds in ICU ");
    							document.cont.no_of_bed_icu.focus();
    							return false;
    	}

    this is what my i am trying, but no luck found yet.
    i think some problem is here,
    (document.cont.icu.value =="Y")
    means how would javascript knows that radio buttons value is "yes" or not?

    please help me.
    thanks in advance.

  6. #6
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    finally i got the solution.
    if(document.cont.icu[0].checked )
    {
    alert("Please enter No. of beds in ICU ");
    document.cont.no_of_bed_icu.focus();
    return false;
    }
    may it will be helpful for someone.
    site point rocks!!
    thank you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •