Reputation: 457
<div class="member_management_area" style="display:none">
<div class="member_search">
<a class="member_search_zone">
<span class="glyphicon glyphicon-menu-hamburger searchMenuyo" aria-hidden="true"></span>
<span name="searchMenu" id="searchMenu">검색 유형을 선택하세요</span>
</a>
<input type="text" name="keyword">
<a class="memberSearch_bt">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</a>
<select id="choiceSearchMenu" name="type" onchange="menuDisplay(this.form)">
<option value="0"> ---- 선택하세요 ---- </option>
<option value="1">아이디로 검색</option>
<option value="2">끝 번호로 검색</option>
</select>
</div>
</div>
$('.searchMenuyo').click(function()
{
$('#choiceSearchMenu').slideDown();
});
$('#choiceSearchMenu').mouseout(function()
{
$('#choiceSearchMenu').slideUp();
});
function menuDisplay(frm)
{
var menu = frm.type.selectedIndex;
console.log(menu);
if(menu == 1)
{
document.getElementById('searchMenu').innerHTML('Search ID');
}
if(menu == 2)
{
document.getElementById('searchMenu').innerHTML('Search Last PhoneNumber');
}
}
If you select the value of the select option from the slideDown menu, the value must be changed, but continue to var menu = frm.type.selectedIndex; In this part, Uncaught TypeError: Can not read property 'type' of null.
Why is this error happening and how can I fix it?
I would appreciate it if you could help me.
Upvotes: 0
Views: 858
Reputation: 14541
The error "Uncaught TypeError: Can not read property 'type' of null" means that the frm
variable is undefined. Meaning, it isn't getting its value when the function is called during onchange
event.
var menu = frm.type.selectedIndex;
Also, regarding your query about innerHTML
, you could set its value like this:
document.getElementById('searchMenu').innerHTML = 'Search ID';
Upvotes: 1