te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>html - disable textbox using javascript - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - disable textbox using javascript - Stack Overflow

programmeradmin1浏览0评论

As the title says, i am, trying to disable textbox when i open the file

<form name='registration' action="registration.php" method="post" onSubmit="return formValidation();">
    <table>
        <tr>
            <td>FirstName:</td>     
            <td><input type = "Text" name = "firstname" id="1"></p></td>
        </tr>
    </table>
</form>

and I try ti disable it using the following javascript code:

function formValidation() {
    var fn = document.registration.firstname;
    if(fname_validation(fn)) {}
    document.getElementById("1").disabled = true;
}

function fname_validation(fn) {
    var fn_len = fn.value.length;
    var fn_char = /^[A-Za-z]+$/;
    if (fn_len == 0) {
        alert("first name cannot empty");
        return false;
    }
    if (!fn.value.match(fn_char)) {
        alert("first name must enter alphabet only");
        return false;
    } else {
        return true;
    }
}

Why the text box still does not disable?

As the title says, i am, trying to disable textbox when i open the file

<form name='registration' action="registration.php" method="post" onSubmit="return formValidation();">
    <table>
        <tr>
            <td>FirstName:</td>     
            <td><input type = "Text" name = "firstname" id="1"></p></td>
        </tr>
    </table>
</form>

and I try ti disable it using the following javascript code:

function formValidation() {
    var fn = document.registration.firstname;
    if(fname_validation(fn)) {}
    document.getElementById("1").disabled = true;
}

function fname_validation(fn) {
    var fn_len = fn.value.length;
    var fn_char = /^[A-Za-z]+$/;
    if (fn_len == 0) {
        alert("first name cannot empty");
        return false;
    }
    if (!fn.value.match(fn_char)) {
        alert("first name must enter alphabet only");
        return false;
    } else {
        return true;
    }
}

Why the text box still does not disable?

Share Improve this question edited Jul 20, 2020 at 15:09 service-paradis 3,3984 gold badges37 silver badges48 bronze badges asked Sep 15, 2013 at 15:36 AskerAsker 852 gold badges2 silver badges11 bronze badges 4
  • First, there is noo radio button. Second, when do you want to disable your text input Right now, the function that make your input disabled is called on form submit. So, your input will be disabled only when you submit your form... probably to late. If you want your input to be disabled at start, your input should look like this – service-paradis Commented Sep 15, 2013 at 16:27
  • omg, i wrongly put the title. i want to test how to disable textbox using javascript when i go to the html page. so when i open html file, the textbox is directly disabled – Asker Commented Sep 15, 2013 at 16:31
  • stackoverflow./questions/8484181/… Side note: I remend using jQuery rather than javascript (jQuery is javascript and makes life easier). – Dom Commented Sep 15, 2013 at 16:32
  • i believe code and references that are given by you guys are working, but i tried to put it on my javascript file and still not working – Asker Commented Sep 15, 2013 at 16:46
Add a ment  | 

2 Answers 2

Reset to default 7

Right now, the function that make your input disabled is called on form submit. So, your input will be disabled only when you submit your form... probably too late.

If you want to disable your input from start, your input should look like this

<input type="Text" name="firstname" id="firstname" disabled="disabled" />

Or if you want to disable it with javascript, you have to execute it on load. Something like this:

window.onload = function() {
  document.getElementById('firstname').disabled = true;
};

If you want the textbox to be disabled on page load, add the disabled attribute to your input

<input type = "Text" name = "firstname" id="1" disabled />
发布评论

评论列表(0)

  1. 暂无评论