[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Radio buttons disabled fields...validation

Posted on 2006-04-28
5
Medium Priority
?
296 Views
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++){
    if(checkElem[elem[i].className]){
      elem[i].disabled=(elem[i].className!=theBtn.value);
    }
  }
}

<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.");
theForm.new_shpm_pol.focus();
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???
0
Comment
Question by:NTGrE
5 Comments
 
LVL 1

Expert Comment

by:ravinadiminti
ID: 16565772
Could not understand what is required. Can you please elaborate a little more or give a list of conditions.
0
 
LVL 25

Accepted Solution

by:
devic earned 2000 total points
ID: 16566278
I don't see all the page and maybe it's not the best solution, but I would doit so:
=====================================================
<script>
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)
{
      theBtn.form.new_shpm_pol.disabled=theBtn.value=="pre";
}
</script>
<form  action="http://www.sembel.net/tools/q.php" 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>
</form>
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16566367
Hi,
I'm not sure that I've completely understood you but maybe you need the following:
Replace
if (theForm.new_shpm_pol.value == "" )
with
if ((theForm.new_shpm_pol.value == "" ) || (theForm.sel_shpm.value != "new"))
0
 

Author Comment

by:NTGrE
ID: 16569515
Thnx devic !!!
I didnt know that the && working and for Javascript.
Thnx for your time.....
0
 
LVL 25

Expert Comment

by:devic
ID: 16569576
you are welcome NTGrE ;)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), 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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

872 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