By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,728 Members | 1,081 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,728 IT Pros & Developers. It's quick & easy.

contactenating radio select values to one hidden field

P: n/a
I am trying to concatenate selected values from numerous radio button
sets into 1 series and assign it to a single hidden field. I have
never done javascript before and I continue to run into problem after
problem (object has no properties, undefined functions, etc.)

So, I am really hoping someone can end the madness for me.

Just so it's understood, the id's and names of the radio buttons vary
with a row in a table so I CANT know the name of the radio field
before hand -- I must compute it. Below is relavent code. The HTML
form is first and the the javascript. I need a {2,1,4} series returned
from combined();

Christian

http://christian.bongiorno.org
--------------------html first-----------------------
<input type="hidden" id="importance" name="importance" value="notset">
<input type="hidden" id="numReqs" name="numReqs" value="14">

<tr>
<td width="40%" class="subSectionHeader">
OM Organization and Management
</td>

<td align="left">
&nbsp;<a href="/WebESWAT_PIV/assessment/
assessmentControlCriticalityPage.do?
assessmentId=1&amp;requirementId=100"
onclick="popupAdjustCriticality(this);return false;">Adjust
Criticality</a>
</td>
<td align="center">
<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance1"
NAME="importance1" VALUE="1" >1
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance1"
NAME="importance1" VALUE="2" checked>2
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance1"
NAME="importance1" VALUE="3" >3
<!--</td>-->

<!--<td BGCOLOR="#003366">-->

<INPUT TYPE=RADIO id="importance1"
NAME="importance1" VALUE="4" >4
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance1"
NAME="importance1" VALUE="5" >5
<!--</td>-->

</td>
</tr>
<tr>
<td width="40%" class="subSectionHeader">
RQ PIV Requests
</td>

<td align="left">
&nbsp;<a href="/WebESWAT_PIV/assessment/
assessmentControlCriticalityPage.do?
assessmentId=1&amp;requirementId=200"
onclick="popupAdjustCriticality(this);return false;">Adjust
Criticality</a>
</td>
<td align="center">

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance2"
NAME="importance2" VALUE="1" checked>1
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance2"
NAME="importance2" VALUE="2" >2
<!--</td>-->
<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance2"
NAME="importance2" VALUE="3" >3
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance2"
NAME="importance2" VALUE="4" >4
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance2"
NAME="importance2" VALUE="5" >5
<!--</td>-->

</td>

</tr>
<tr>
<td width="40%" class="subSectionHeader">
IP Identity Proofing
</td>

<td align="left">
&nbsp;<a href="/WebESWAT_PIV/assessment/
assessmentControlCriticalityPage.do?
assessmentId=1&amp;requirementId=300"
onclick="popupAdjustCriticality(this);return false;">Adjust
Criticality</a>
</td>
<td align="center">
<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance3"
NAME="importance3" VALUE="1" >1
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance3"
NAME="importance3" VALUE="2" >2
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance3"
NAME="importance3" VALUE="3" >3
<!--</td>-->

<!--<td BGCOLOR="#003366">-->

<INPUT TYPE=RADIO id="importance3"
NAME="importance3" VALUE="4" checked>4
<!--</td>-->

<!--<td BGCOLOR="#003366">-->
<INPUT TYPE=RADIO id="importance3"
NAME="importance3" VALUE="5" >5
<!--</td>-->

</td>
</tr>

---------------------------java script-------------------------
function combine() {
document.assessmentControlSelectionForm.importance .value =
concatRadios();
alert("importance value " +
document.assessmentControlSelectionForm.importance .value);
}
function concatRadios() {
var rtnValue = "";
alert("number of requirements: " +
document.assessmentControlSelectionForm.numReqs.va lue);
for( var i=0; i<
document.assessmentControlSelectionForm.numReqs.va lue; i++ ) {
var obj = document.getElementById("importance" + i);
alert("object name" + obj.name);
if(obj) {
rtnValue = rtnValue + obj.value + ",";
}
}

return rtnValue;
}

Feb 2 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"Sideswipe" <ch*****************@gmail.comwrote in
news:11*********************@s48g2000cws.googlegro ups.com:
for( var i=0; i<
document.assessmentControlSelectionForm.numReqs.va lue; i++ ) {
var obj = document.getElementById("importance" + i);
alert("object name" + obj.name);
if(obj) {
rtnValue = rtnValue + obj.value + ",";
}
}
You make the common assumption that you can retrieve the value of the
checked radio button with ".value" but it is not that simple. You need
to poll each radio button and see if it is checked. Like this:

for(var i=0; i<document.forms[0].importance1.length; i++){
if (document.forms[0].importance1[i].checked) {
alert('importance1 value is ' +
document.forms[0].importance1[i].value)
}
};
Feb 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.