jquery - Using .val().length != 0 to show textbox -
i working survey, note section after every question. notes should come after pressing end or f10 first time. after skipping ahead question 2, , going question 1, note section question 1 should again hidden if there no notes.
however, if there writing in notes section @ all, want them remain visible after returning question 1 question 2.
i trying accomplish using .val().length != 0 display notes if there 1 character written. i'm not sure if issue here .val().length or preventdefault command, want prevent default action in case not display notes.
<style> #[% questionname() %]_div {display:none} </style> <script> $(document).keydown(checknote); function checknote(f){ f = f || window.event; if (f.keycode == '121' || f.keycode == '35'){ f.preventdefault(f); $("#[% questionname() %]_div").css('display', 'block'); } } function displaynote(d){ d = d || window.event; if ($("#[% questionname() %]_div").val().length != 0) { d.preventdefault(d); $("#[% questionname() %]_div").css('display', 'block'); } } <script>
if tell me issue might or provide alternative .val().length != 0 if that's problem, helpful.
thanks!
is element #[% questionname() %]_div
input?
$(...).val()
works input elements (if call function on, say, div
, return empty string).
if it's div
working with, use $(...).text()
or $(...).html()
retrieve content.
Comments
Post a Comment