SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HTTP Request and checkbox onchange

    I'm trying to get a checkbox to send a request upon change, but it's not working.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    var http;
    if(window.XMLHttpRequest) {
    	http = new XMLHttpRequest();
    }
    	else if(window.ActiveXObject) {
    	http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    function updateList() {
    	http.open('GET','includes/scripts/update.php?id=1',true);
    	http.send(null);
    }</script>
    </head>
    <body>
    <input type="checkbox" value="1" onchange="javascript:updateList()" />
    </body>
    </html>
    See anything wonky?

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont think checkboxes have a change event

    try onclick

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gimbles View Post
    i dont think checkboxes have a change event

    try onclick
    yeah, I'd tried that earlier. No go.

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Could be the other end of it isn't working then. Try onclick="alert('test');" and you should see that working.
    - Robert

  5. #5
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just figured it out, and it's one of those "Is it plugged in?" moments. I needed to use the FULL URL to send variables via GET.

    duh.

    Thanks for the replies

  6. #6
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just ran across another issue. The name of the checkbox is ln_id[] (I get the value in a php array). I need to get the clicked checkbox's value and pass it to the updateList() function. I think my problem is the braces, but I don't know how to solve that.

    Code:
    <script type="text/javascript">
    var http;
    if(window.XMLHttpRequest) {
    	http = new XMLHttpRequest();
    }
    	else if(window.ActiveXObject) {
    	http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    function updateList() {
    	// need to get the value of the checkbox when clicked so that I can pass it to the next page
    	var list = document.form.ln_id[].value;
    	
    	http.open('GET','http://www.mysite.com/js/ajax/update_mailing_lists.php?id=1&list=list',true);
    	http.send(null);
    }
    </script>
    
    <input type="checkbox" onclick="javascript:updateList();" name="ln_id[]" id="ln_id[]" value="1" />
    <input type="checkbox" onclick="javascript:updateList();" name="ln_id[]" id="ln_id[]" value="2" />
    <input type="checkbox" onclick="javascript:updateList();" name="ln_id[]" id="ln_id[]" value="3" />

  7. #7
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onclick="javascript:updateList(this.value);"

    Code javascript:
    function updateList(value) {
    	// need to get the value of the checkbox when clicked so that I can pass it to the next page
     
    	http.open('GET','http://www.mysite.com/js/ajax/update_mailing_lists.php?id=1&value='+value,true);
    	http.send(null);
    }

    Also IDs must be unique.

  8. #8
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by M-M-J View Post
    onclick="javascript:updateList(this.value);"

    Code javascript:
    function updateList(value) {
    	// need to get the value of the checkbox when clicked so that I can pass it to the next page
     
    	http.open('GET','http://www.mysite.com/js/ajax/update_mailing_lists.php?id=1&value='+value,true);
    	http.send(null);
    }

    Also IDs must be unique.
    Perfect! Thank you


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
  •