Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:54:08+00:00 2026-05-16T13:54:08+00:00

I’m processing a form with php and I want to add validation on the

  • 0

I’m processing a form with php and I want to add validation on the client side too. I read about.com’s tutorial about validating radio buttons with javascript and set up this sample according to its guidelines.

a) Why isn’t it showing the alert message?

b) How can I substitute the alert message for some innerHtml text?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>validateradio</title>


<script type="text/javascript">


function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1)  return btn[cnt].value;
    else          return null;

}




function valButton2(form){

var btn=valButton(form.group1);
if (btn==null){alert('no radio button selected');}
else alert('button value' + btn + 'selected');


}


</script>


</head>


<body style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" alink="#000088" link="#0000ff" vlink="#ff0000"><br>

<form name="myform">


 <label for="r1"><input type="radio"
name="group1" id="r1" value="1" /> button one</label> 

 <label for="r2"><input type="radio"
name="group1" id="r2" value="2" /> button two</label>

 <label for="r3"><input type="radio"
name="group1" id="r3" value="3" /> button three</label> 


<input type="submit" name="submitit" onclick="valbutton2(myform);" value="Validate" />



</form>



</body></html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:54:09+00:00Added an answer on May 16, 2026 at 1:54 pm

    Looks like a case issue. Your onclick handler for the submit button is valbutton2(myform); but the name of the function you are trying to call is actually valButton2.

    With regards to getting the innerHTML, without using a framework it can be kind of ugly. One solution would be to add an id to the labels that contains the id of the corresponding radio button:

    <label for="r1" id="lbl-r1"><input type="radio" name="group1" id="r1" value="1" /> button one</label>
    

    Then return a reference to the selected radio button from your second function instead of its value return btn[cnt]; instead of return btn[cnt].value;. Then you could access the label text using something like the following:

    var id = btn.getAttribute("id");
    var lbl = document.getElementById("lbl-" + id);
    for (var i = 0; i < lbl.childNodes.length; i++) {
        var n = lbl.childNodes[i];
        if (n.nodeType == 3) {
            alert(n.nodeValue);
        }
    }
    

    I’ve been using jQuery and other frameworks for so long now I’m more than a little rusty at doing this in straight javascript, so this could probably be improved a lot, but you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This issue was also raised in the developer forums, and… May 16, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer The straight highway makes this an exercise in dynamic programming,… May 16, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer You'll only need to upload the html files, the css… May 16, 2026 at 6:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.