CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Get Radio Button Field Value via Javascript

Print topic Send  topic

Author Message
datadoit.com
Posted: 11/06/2005, 5:15 PM

CCS 2.3; PHP4; MySQL4

I'm attempting to get the value of a radio button field via Javascript, but
it returns only 'undefined'. I'm using:

alert(document.forms['myForm'].myField.value);

myField is a radio button ListOfValues. Getting the field value works fine
if it's a textbox. How do I get it's value if it's a radio button?

datadoit.com
Posted: 11/09/2005, 6:47 AM

"datadoit.com" <mike@datadoit.com> wrote in message
news:dkm9r2$338$1@news.codecharge.com...
> CCS 2.3; PHP4; MySQL4
>
> I'm attempting to get the value of a radio button field via Javascript,
> but it returns only 'undefined'. I'm using:
>
> alert(document.forms['myForm'].myField.value);
>
> myField is a radio button ListOfValues. Getting the field value works
> fine if it's a textbox. How do I get it's value if it's a radio button?
>
----------------------------------

The silence is deafening. :-) Am I to assume this isn't possible?

Nicole

Posts: 586
Posted: 11/10/2005, 3:24 AM

Hello,
I successfully get a radiobutton value from its client side onClick event using this.value
alert(this.value);
Hope it helps.

_________________
Regards,
Nicole
View profile  Send private message
datadoit.com
Posted: 11/11/2005, 6:16 AM

Thanks Nicole. Unfortunately it's not working for me. Here's how I'm
trying to get the value:

In my form's Submit button's OnClick event (under the format tab for the
button), I have:

CheckData(); return confirm($message);

Then, in the HTML, I have:

<script language="javascript">
function CheckData()
{
$message = document.forms["myform"].myfield.value;
//$message = "Save survey answers?";
}
</script>

I commented out the second part of the message just to show that the confirm
message works. I want to be able to check some form values on the client
side BEFORE they're submitted to the server. My reasoning is that I want to
do some data checks, and confirm these with the user before submitting.

I can get the values using the above method for standard textbox fields.
Doesn't work for radio button fields. The radio buttons that I'm using are
lookups to tables in the database (ex: A 'luYesNo' table that holds
0;No;1;Yes as data records).

Thanks.

Shailendra
Posted: 11/13/2005, 10:04 PM

use document.getElementById("ur input field id").value
Quote datadoit.com:
Thanks Nicole. Unfortunately it's not working for me. Here's how I'm
trying to get the value:

In my form's Submit button's OnClick event (under the format tab for the
button), I have:

CheckData(); return confirm($message);

Then, in the HTML, I have:

<script language="javascript">
function CheckData()
{
$message = document.forms["myform"].myfield.value;
//$message = "Save survey answers?";
}
</script>

I commented out the second part of the message just to show that the confirm
message works. I want to be able to check some form values on the client
side BEFORE they're submitted to the server. My reasoning is that I want to
do some data checks, and confirm these with the user before submitting.

I can get the values using the above method for standard textbox fields.
Doesn't work for radio button fields. The radio buttons that I'm using are
lookups to tables in the database (ex: A 'luYesNo' table that holds
0;No;1;Yes as data records).

Thanks.


datadoit.com
Posted: 11/14/2005, 8:52 AM

"Shailendra" <Shailendra@forum.codecharge> wrote in message
news:5437828fccd1e2@news.codecharge.com...
> use document.getElementById("ur input field id").value
-----------------------------------

Thanks Shailendra. However, it's now returning '0', no matter what the
value chosen from the radio button control. I've verified that it is
recording the correct value when submitted. Here's what it looks like:

<script language="javascript">
function CheckData()
{
$message = document.getElementById("f_1_church_affiliated").value;
}
</script>
.
.
<td colspan="2">1. Is your school directly affiliated with a
church? <!-- BEGIN RadioButton f_1_church_affiliated --><input
type="radio" name="{f_1_church_affiliated_Name}" value="{Value}"
id="f_1_church_affiliated" {Check}>{Description}<!-- END RadioButton
f_1_church_affiliated --></td>
.
.
<!-- BEGIN Button Button_Insert --><input type="submit" value="Submit"
name="{Button_Name}" onclick="CheckData(); return confirm($message);"><!--
END Button Button_Insert -->

parma70
Posted: 11/14/2005, 11:53 AM

check this link and u will get the answer
http://www.elopersnotes.com/tips/html/finding_the_value...dio_button.php3
datadoit.com
Posted: 11/14/2005, 3:21 PM

"parma70" <parma70@forum.codecharge> wrote in message
news:54378eb1e6c471@news.codecharge.com...
> check this link and u will get the answer
> http://www.elopersnotes.com/tips/html/finding_the_value...dio_button.php3
>
> ---------------------------------------

That did it! WooHoo! Thanks parma70. Here's what I ended up with:

<script language="javascript">
function CheckData()
{
// Check Church Affiliation.
for (var i=0; i <
document.forms["tbl_school_survey_church"].f_1_church_affiliated.length;
i++)
{
if
(document.forms["tbl_school_survey_church"].f_1_church_affiliated.checked)
{
var f_1_church_affiliated_val =
document.forms["tbl_school_survey_church"].f_1_church_affiliated.value;
}
}

$message = "Church Affiliated = " + f_1_church_affiliated_val;
}
</script>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.