SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Code HTML4Strict:
    <?=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:
    Code JavaScript:
    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 :-)

  2. #2
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code JavaScript:
    var blogid = encodeURI(document.subscribe.getElementById('blogid').value);

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

  3. #3
    SitePoint Zealot FaridHadi's Avatar
    Join Date
    Nov 2008
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using childNodes and looping through them till you find "blogid".
    Something like this:

    Code JavaScript:
    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);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •