/    Sign up×
Community /Pin to ProfileBookmark

resetting field to disabled (after enabled with js) using reset button

I am attempting to figure out how to return a field to its original disabled setting, using the reset button, after the field has been enabled using js.

[url]http://ultimaterack.ajandj.com/forwdf.htm[/url]

1) click checkbox, text field is enabled
2) click “reset” button, checkbox is unchecked but text field remains enabled

[code]
<script language=”JavaScript” type=”text/javascript”>
<!–
function enablefield(objButton) {
var strName=objButton.name;
var arrTmp=strName.split(“_”);
var index=arrTmp[0];
var strInputFieldName=”amounts[“+index+”]”;
var objInputField=objButton.form.elements[strInputFieldName];
var itschecked=(objButton.checked)?’Y’:”;
objInputField.disabled=(itschecked==’Y’)?false:true;
objInputField.value=(itschecked==’Y’)?’1′:”;
objInputField.style.backgroundColor=(itschecked==’Y’)?’#ffff33′:”;
objInputField.style.fontWeight=(itschecked==’Y’)?’bold’:’normal’;
if (itschecked==’Y’) { objInputField.select(); }

}
// –>
</script>

<form>
<input type=”checkbox” name=”ADSM” onclick=”enablefield(this);” />
<input disabled name=”amounts[ADSM]” type=”text” size=”2″ default=”0″ maxlength=”2″ />
<br /><br />
<input type=”submit” /><input type=”reset” />
</form>
[/code]

I’m guessing that I need to run some more js on the reset button but I’m at a loss for the moment. Particularly because once this is full strength, their will be literally dozens of these pairs on the page all with different, unknown names (unknown because they will be generated by a PHP script taking it’s config from different users using different data).

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@russellDec 23.2004 — <input type="reset" onclick="document.form.amounts[ADSM].disabled=true">
Copy linkTweet thisAlerts:
@jdorfauthorDec 23.2004 — Thanks for your reply, and, that would be great for the measely example I posted... but, like I said, there will be numerous pairs of these inputs all with different, unknown names...

I take that back, they will be "mostly" unknown... they will all have the same format of name="amounts[variable_here]"... if that helps
Copy linkTweet thisAlerts:
@russellDec 23.2004 — <input type=reset onclick="resetAllElements()">
<i>
</i>function resetAllElements() {
for(i=0;i&lt;document.myForm.elements.length;i++) {
document.myForm.elements[i].disabed=true;
}
}

Or suppose there are only certain elements that you are interested. give them a custom attribute, say "canDisable"

<input type=text name=myTextBox canDisable="1">
<i>
</i>function resetAllElements() {
for(i=0;i&lt;document.myForm.elements.length;i++) {
if(document.myForm.elements[i].canDisable)
document.myForm.elements[i].disabed=true;
}
}
Copy linkTweet thisAlerts:
@jdorfauthorDec 28.2004 — russell,

thanks a million, was exactly what I am trying to do, you're a life saver... we've been without power since Wednesday night, but I'm back now and appreciate you helping me out, thanks. John


P.S. For those wanting to use the above code, which is awesome, note to fix "disabled" in this line: document.myForm.elements[i].disabed=true;
Copy linkTweet thisAlerts:
@russellDec 28.2004 — oops, i'm a better programmer than speller! ? glad it helped you out.
×

Success!

Help @jdorf 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...