...

View Full Version : Throws the exception that the element is undefined.



GarciaM
07-02-2012, 11:54 AM
I have a paging control that dynamically adds the individual page numbers for the user to click on, but I noticed that the page didn't want to refresh.

I did a lot of debugging and finally found where it was breaking; it's like it can't find the element h_page:


function do_Post(pageNum) {
var frm = document.forms[0];
try {
frm.h_page.value = pageNum;
frm.submit();
}
catch(Error) {
alert(Error.Message);
}
}

And then right at the top of the page I have to hidden variable:

<input type="hidden" id="h_page" value=""/>

What could be causing this? I've been stuck on this for a while and none of my googling has brought back anything that has helped me.

vwphillips
07-02-2012, 12:24 PM
either give the input a name


<input type="hidden" name="h_page" value=""/>

or


function do_Post(pageNum) {
var frm = document.forms[0];
try {
document.getElementById('h_page').value = pageNum;
frm.submit();
}
catch(Error) {
alert(Error.Message);
}
}

GarciaM
07-02-2012, 12:31 PM
Thank you. The latter fixed my problem.
Strange thing is that I have the same function on another website and there the former worked 100%.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum