Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Code for Radio Button validation

Posted on 2012-03-28
9
Medium Priority
?
320 Views
Last Modified: 2012-04-05
I need to add a check for Radio Button in my java script code for the form I am developing using Oracle portal 10g to make sure that one of the Radio Button is checked.I have code as per attached file for text field and fields which are selectable from the drop down menu.
 
What do I need to add or modify in my java script so that I can ensure Radio Button is checked.
Please let me know if more information is needed.
Thank you very much .
java-script.txt
0
Comment
Question by:lmymusic2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37780449
Try this

Put it in an external file so you do not need to do all that messy HTP.p and HTP.print (why is there a difference?

<script type="text/javascript">
function IsSelected(s) {
  return s.options[s.selectedIndex].value != "";
}
function IsEmpty(s){  
  if (s.length != undefined) {
    for (i=0; i<s.length;i++){
      if (s[i].value !="") return true;
    }
    return false;
  }
  else return s.value != "";
}

function IsChecked(but) {
  if (!but.length) return but.checked;
  for (var i=0;i<but.length;i++) {
    if (but[i].checked) return true;
  }
  return false;
}

function validateForm(theForm) {
  if (IsEmpty(theForm.IN_LAST_NAME)) {
    alert("Please enter last name."); 
    theForm.IN_LAST_NAME.focus();
    return false;
  } 
  
  if (!IsSelected(theForm.IN_REQUESTED_CREDIT_HOURS)) {
    alert("Please select credit hours!"); 
    theForm.IN_REQUESTED_CREDIT_HOURS.focus();
    return false;
  } 

  if (!IsChecked(theForm.SOME_RADIO_OR_CHECKBUTTON_SET)) {
    alert("Please check a radio or check button!"); 
    return false;
  } 
  return true;
}
</script>

Open in new window


I have changed the code so you can do

<form onsubmit="return validateForm(this)"

instead of having the name of the form floating around the place

I also deleted an unused focus function and cleaned up the rest
0
 

Author Comment

by:lmymusic2000
ID: 37783299
Thank you mplungjan for the input.I already have coded for other fields so I did not change to external file.Besides I do not know how to use  external file for validation.I am creating this form through a oracle package I am writing.
I  tried as per attached file but now it shows the Alert message and even after clicking OK and selecting one of the Radio button it keeps giving me same Alert and does not go beyond that point.What could be wrong in the code?


Thank you very much.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37783673
I need to see the form

Can you update

http://jsfiddle.net/mplungjan/X4qpP/

with the html rendered (view-source) ?

I will look tomorrow
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

Author Comment

by:lmymusic2000
ID: 37796160
Thank for your help.I was able to make it work.
It is working now with Radio button as well as other field validation also.
Thanks again.
0
 

Author Comment

by:lmymusic2000
ID: 37796284
I've requested that this question be closed as follows:

Accepted answer: 0 points for lmymusic2000's comment #37796160

for the following reason:

Based on the code provided by the expert I was able to modify it to suit my need and solve my issue.<br />Thank you.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 37796285
So I assume you wanted to give me some points?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37799367
In this case I have run out of t-shirts. Only glory left ;)
0
 

Author Closing Comment

by:lmymusic2000
ID: 37811848
Thank you for the solution.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
What You Need to Know when Searching for a Webhost Provider
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

618 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