Radio buttons disabled fields...validation

Posted on 2006-04-28
Last Modified: 2012-06-22
Hello Again.
So far(with your help) iv done 2 radio buttons that when the second selected i disable a textarea field..

function checkForm(theBtn, checkElem){
  var elem = theBtn.form.elements;
  for(var i=0;i<elem.length;i++){

<input name="sel_shpm" type="radio" value="pre"  checked onClick="checkForm(this,{pre:1,'new':1})">
<input name="sel_shpm" type="radio" value="new"  onClick="checkForm(this,{pre:1,'new':1})">

and the text field

<textarea name="new_shpm_pol" cols="50" rows="5" disabled class="new"></textarea>

So far for the validation af the textarea i was using

if (theForm.new_shpm_pol.value == "" )
alert("You must enter new_shpm_pol Information.");
return (false);

but now seems that i must put in
if (theForm.new_shpm_pol.value == "" ) and the condition that the 2nd radio button is selected to display error only
if (2nd radio button is selected <strong>AND</strong>the textarea is not empty)

How i can do this???
Question by:NTGrE
    LVL 1

    Expert Comment

    Could not understand what is required. Can you please elaborate a little more or give a list of conditions.
    LVL 25

    Accepted Solution

    I don't see all the page and maybe it's not the best solution, but I would doit so:
    function checkForm(theForm)
          if(theForm.new_shpm_pol.value=="" && theForm.sel_shpm[1].checked)
                alert("to display error only");
                return false;
          else if(theForm.new_shpm_pol.value!="" && theForm.sel_shpm[0].checked)
                alert("he textarea is not empty!");
                return false;
          return true;

    function sel(theBtn)
    <form  action="" onsubmit="return checkForm(this)">
          <input name="sel_shpm" type="radio" value="pre"  checked onClick="sel(this)">
          <input name="sel_shpm" type="radio" value="new"  onClick="sel(this)">
          <textarea name="new_shpm_pol" cols="50" rows="5" disabled class="new"></textarea>
          <input type=submit>
    LVL 11

    Expert Comment

    I'm not sure that I've completely understood you but maybe you need the following:
    if (theForm.new_shpm_pol.value == "" )
    if ((theForm.new_shpm_pol.value == "" ) || (theForm.sel_shpm.value != "new"))

    Author Comment

    Thnx devic !!!
    I didnt know that the && working and for Javascript.
    Thnx for your time.....
    LVL 25

    Expert Comment

    you are welcome NTGrE ;)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now