Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to print a radio button value without print_r?

basically I want it to display things like the alert action for e, but have it read the variable. If the variable is e then display text "blah blah".

<HTML>

<HEAD>

<TITLE>Sample Form with Radio Buttons</TITLE>

<SCRIPT Language="JavaScript">

<!--

function reportValue(frm){

var radioArray = frm.question1

var i

var value

for (i=0; i < radioArray.length; i++){

if (radioArray[i].checked){

value = radioArray[i].value

break

}

}

if (value == "a")

return true

if (value == "b")

return true

if (value == "c")

return true

if (value == "d")

return true

if (value == "e")

{alert("You chose " + "?\n" + value)

}

else{

alert("Something went wrong " + "\n" + value)

return false

}

}

//-->

</SCRIPT>

</HEAD>

<BODY bgColor="#FFFFFF">

<form method="post" action="" name="Question1" onSubmit="return reportValue(this)">

<p>This is where you put question one:</p>

<blockquote>

<p>

<input type="radio" name="question1" value="a">

Option 1<br>

<input type="radio" name="question1" value="b">

Option 2<br>

<input type="radio" name="question1" value="c">

Option 3<br>

<input type="radio" name="question1" value="d" >

Option 4<br>

<input type="radio" name="question1" value="e" >

Option 5</p>

<P><INPUT Type="Submit" Value="Submit">

</blockquote>

</form>

<br/>

<?

print_r($_POST);

?>

</BODY>

</HTML>

1 Answer

Relevance
  • 9 years ago
    Favorite Answer

    I've drafted and posted a template (complete with source code and a live example) for you here: http://jsfiddle.net/MythOfEchelon/Jppsk/4/ (Updated, as per your request by message, so it no longer uses alert() or a submit button).

    I've also tidied up your code and validated it as HTML5.

    If you have any more questions, feel free to contact me on Twitter: @mythofechelon

    Source(s): Web Developer / Programmer
Still have questions? Get your answers by asking now.