开发者

Setting a Form Input Value With IE9 (Getting An Error - Unable to set value of the property 'value': object is null or undefined)

开发者 https://www.devze.com 2023-03-07 16:01 出处:网络
My PHP code looks as such: <a id=\'next_page\' HREF=\'#\' onclick=\\\"javascript:document.getElementById(\'page_to_show\').value=\'\" . ($page + 1) . \"\'; return false;\\\" rel=\'facebox\'>[N

My PHP code looks as such:

<a id='next_page' HREF='#' onclick=\"javascript:document.getElementById('page_to_show').value='" . ($page + 1) . "'; return false;\" rel='facebox'>[Next $display_per_page]</a>

As you can see, I am using document.getElementById('page_to_show').value to set the value of the hidden field "page_to_show". I have also tried setting the value of a regular text input field, and I've encountered the same error. I've also tried .Value instead of .value - no luck. This code works in IE8 and FF 3.6.17. Why not IE9? It is sound code, correct? Thank you!

Oh, I've also tried jQuery's method of $("#page_to_show").val("Page Num"); and althou开发者_Python百科gh it hasn't thrown a Javascript error,it doesn't change anything.

I've also tried a temp fix of adding "" however that didn't work either!


Here's something weird for ya. It wasn't the code. That error was from earlier code, not my updated code. For whatever reason, IE9 isn't refreshing my PHP code! Even if I shift-click refresh, it doesn't refresh my code. I had to exit the browser and open it again for it to refresh. Perhaps thats a setting. Thank you guys! That explains why it was so weird that it wasn't working!


Are you certain that your input has an id and not just a name attribute? Additionally, I've seen IE get sticky when trying to set the value of input fields that exist outside of a <form>.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号