Strange error in ajax subscription script!?!

I’m trying to make this ajax subscriptions script to work and it works allmost fine except 1 thing… The “blogid” allways gets to be “2” nomatter what I put in the hidden blogid field?

Can somebody please help me.

The form:

<?=include_once("js/blog/subscribe_js.php");?>
<div id="insert_response">

    <form action="javascript:insert()" method="post">
    <input name="userid" type="hidden" id="userid" value="48"/>
    <input name="blogid" type="hidden" id="blogid" value="99"/>
    <input type="submit" name="Submit" value="Subscribe to this blog"/>
    </form>

</div>

The js where something goes wrong:

function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();


var nocache = 0;
function insert() {

document.getElementById('insert_response').innerHTML = "Subscribing..."

var userid = encodeURI(document.getElementById('userid').value);
var blogid = encodeURI(document.getElementById('blogid').value);

nocache = Math.random();

http.open('get', 'js/blog/subscribe_insert.php?userid='+userid+'&blogid='+blogid+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){ 
var response = http.responseText;

document.getElementById('insert_response').innerHTML = 'Subscription success...';
}
}

Please help… Thanks in advance :slight_smile:

I have found the fault but noit sure how to correct it. There is another ajaxscript on the page which uses some of the same parameters. I thourgt I could overwrite tis by calling the form “subscribe” and then get the field data like this:

var blogid = encodeURI(document.subscribe.getElementById('blogid').value);

But this is a no go… How do I do this?

Try using childNodes and looping through them till you find “blogid”.
Something like this:


var blogid;
var tmp=document.getElementById('subscribe').childNodes;
for(var i=0; i<tmp.length; i++) {
	if(tmp.item(i).id=='blogid') {
		blogid=tmp.item(i).value;
	}
}
alert(blogid);