I have a textbox which is disabled by default... the onclick works and enables it to be typed in, but when i click the radio button away.. it doesn't disable the textbox again
Any clues ?
<input type="radio" name="group1" value="website" OnBlur="javascript:document.getElementById('websiteurl').d开发者_运维百科isabled = true;" OnClick="javascript:document.getElementById('websiteurl').disabled = false;">
<input name="websiteurl" type="text" id="websiteurl" value="http://" size="50" disabled="true" />
Thanks in advance
Lee
There is no attribute "enabled". You would have to set disabled to "disabled" to disable an input, or remove the attribute "disabled" to enable it.
disabled="true" is the wrong syntax, it should be disabled="disabled"
There is no attribute enabled
. You use disabled
and set it to true
or false
.
Besides that:
Use lowercase attributes (otherwise it's not valid XHTML); there's no need to put javascript:
in front of it.
Additionally, it is better to attach events from JavaScript code instead of inlining them. Especially if you use a library like jQuery it's extremely easy:
$('input[name=group1][value=website]').blur(function() {
$('#websiteurl').attr('disabled', 'true');
}).click(function() {
$('#websiteurl').removeAttr('disabled');
});
(of course a #id
would be much better instead of the input[name=group1][value=website]
selector)
Change enabled to disabled and it will work.
There is no enabled property.
Not totally sure on the context, but wouldn't a checkbox be more appropriate in this situation to disable or enable a textbox?
$('input[type="checkbox"]').click(function() {
if (this.checked) {
$('#websiteurl').removeAttr('disabled');
}
else {
$('#websiteurl').attr('disabled', true);
}
});
Try disabled=true
instead of enabled=false
精彩评论