/    Sign up×
Community /Pin to ProfileBookmark

Reseting Radial Button Fields

I have this script in an external javascript file and I know it works mostly. The script is supposed to reset all of the fields I tell it to to a certain value. The only problem I’m having is with radial buttons. I get a field has no properties error message for these fields. My guess is that it has something to do with the [] that tell it which radial button to mark as checked. Does anyone have any ideas on how to fix this?

HTML Code:

<form id=”EstimateRequest” action=”/Pages/EstimateRequestDU.asp” method=”post” name=”EstimateRequest”>
<input type=”text” name=”txtFlatFinishedSize1″ size=”15″ maxlength=”20″ tabindex=”16″>
<input type=”radio” name=”grpCover1″ value=”Yes” tabindex=”18″> Yes
<input type=”radio” name=”grpCover1″ value=”No” tabindex=”19″> No
<input type=”radio” name=”grpCover1″ value=”NA” checked tabindex=”20″> N/A
<input type=”checkbox” name=”chkTCNA1″ value=”NA” checked tabindex=”28″> N/A
<button name=”cmdClearOne” value=”” type=”button” onclick=”ClearFields(‘EstimateRequest’, ‘txtFlatFinishedSize1,grpCover1[2],chkTCNA1’, ‘value,checked,checked’, ‘,true,true’, ‘Are you sure you want to clear all of Item One?’)”>Clear</button>

Javascript Code:

function ClearFields(strForm,strFields,strTypes,strValues,strMessage){
var ClearMessage = confirm(strMessage);
var x = document.forms[strForm];
var strFieldsArray = strFields.split(“,”);
var strTypesArray = strTypes.split(“,”);
var strValuesArray = strValues.split(“,”);
for(i in strFieldsArray){
x[strFieldsArray[i]][strTypesArray[i]] = strValuesArray[i];

to post a comment

6 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 01.2007 — you need to give a Boolean value to the checked attribute, or your arguments 'true' are strings, not Booleans...

Why not passing the arguments straight as arrays, to avoid an unnecessarily split() method?:
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function ClearFields(strFieldsArray,strTypesArray,strValuesArray,strMessage){
for(var i=0;i&lt;strFieldsArray.length;i++){
strFieldsArray[i][strTypesArray[i]] = strValuesArray[i];
&lt;form id="EstimateRequest" action="/Pages/EstimateRequestDU.asp" method="post" name="EstimateRequest"&gt;
&lt;input type="text" name="txtFlatFinishedSize1" size="15" maxlength="20" tabindex="16"&gt;
&lt;input type="radio" name="grpCover1" value="Yes" tabindex="18"&gt; Yes
&lt;input type="radio" name="grpCover1" value="No" tabindex="19"&gt; No
&lt;input type="radio" name="grpCover1" value="NA" checked tabindex="20"&gt; N/A
&lt;input type="checkbox" name="chkTCNA1" value="NA" checked tabindex="28"&gt; N/A
&lt;button name="cmdClearOne" value="" type="button" onclick="ClearFields([COLOR="Red"][txtFlatFinishedSize1,grpCover1[2],chkTCNA1][/COLOR], [COLOR="Red"]['value','checked','checked'][/COLOR],[COLOR="Red"]['',true,true][/COLOR], 'Are you sure you want to clear all of Item One?')"&gt;Clear&lt;/button&gt;
Copy linkTweet thisAlerts:
@nbcrockettauthorOct 01.2007 — Why not passing the arguments straight as arrays, to avoid an unnecessarily split() method?:[/QUOTE]
Is that how you have it set up in your last post?
Copy linkTweet thisAlerts:
@KorOct 01.2007 — Is that how you have it set up in your last post?[/QUOTE]
Obviously. I'll mark them with red color. Have a look again at my code.
Copy linkTweet thisAlerts:
@KorOct 01.2007 — ...and you don't need to use the form element as a reference root for its elements. When calling a function on some event [I]from within a form's element[/I], the other elements of the form can be passed as arguments directly by their name, as objects.
Copy linkTweet thisAlerts:
@nbcrockettauthorOct 01.2007 — Thanks that's really nice to know! In your example you used this code:
[CODE]for(var i=0;i<strFieldsArray.length;i++){[/CODE]
In my original post I used this:
[CODE]for(i in strFieldsArray){[/CODE]
They both seem to do the same thing. Is one better than the other or did you just use the one you're use to using?


Help @nbcrockett spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 11.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @bahaedd,
tipped: article
amount: 1000 SATS,

tipper: @Balmasexy,
tipped: article
amount: 1000 SATS,

tipper: @mbsaad,
tipped: article
amount: 1000 SATS,