html input null,html - Javascript null input error - Stack Overflow

i have this input field

html +='

Total Bids:

';

and the button

html += 'Activate';

i get thie value of the input field via

var totalbids = document.getElementsByName('total_bids')[0].value;

if a user enters a number, it works fine, but if a user does not enter anything and press the activate button, it gives this error,

TypeError: Cannot read property 'style' of null

i want to restrict user to enter something, i already applied required in the input field but that did not work,(i dont know why) any other check with which i can restrict user to enter something?

EDIT:

I get this value in php and i have applied a check there too,

$total_bids = PSF::requestGetPOST('totalbids');

if(!$total_bids)

{

return json_encode(array('error' => 'enter a number'));

}

but it does not reach till here, as it stops with the null value error

the button leads to this function

bid_o_matic:function(id, uid, e, evt){

var totalbids = document.getElementsByName('total_bids')[0].value;

var bidval = document.getElementsByName('bidvalue')[0].value;

parent_element = $(e).parent().parent();

if(typeof(evt) != 'undefined'){

evt.preventDefault();

evt.stopPropagation();

}

if(e.attr('disabled') == 'disabled'){

return;

}

e.button('loading');

$.post('index.php', {

page:'__request',

module:'PSF_auctions',

action:'make_bid_o_matic',

id:id,

uid:uid,

totalbids: totalbids,

bidval: bidval

}, function(d){

e.button('reset');

document.getElementById("btn-bidoo").style.visibility = 'hidden';

document.getElementById("btn-deactivate").style.visibility = 'visible';

document.getElementById("totalbids").style.visibility = 'hidden';

document.getElementById("bidvalue").style.visibility = 'hidden';

if(d.error){

// document.getElementById("totalbids").style.visibility = 'visible';

// document.getElementById("bidvalue").style.visibility = 'visible';

$.auctions.alert(d.error);

document.getElementById("btn-bidoo").style.visibility = 'visible';

document.getElementById("btn-deactivate").style.visibility = 'hidden';

}

else

{

$(current_price_element).html('

Current Price

'+d.bid_value+'')

}

}, 'json');

},

and the error occurs in this line

document.getElementById("totalbids").style.visibility = 'hidden';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值