• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Need code possible Javascript

WebWatcher

New Member
Hey Guys,
Looking for some code that will do the following.

Read values from a mysql db. Three field A, B, C,

Of now there will be 5 records on a page:

A B C
A B C
A B C
etc

At the end of the line is a yes and a no button. If the yes botton is clicked then we need to change the value of 'C' in the db from yes to no! I want this done without the page reloading...


Any clues?????
 
you will need something similar to this...

HTML:
function offerStatusChange(p, r, id){

    var ajaxRequest; // The variable that makes Ajax possible!
    try {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer Browsers
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
	
	var img_id = r+id;
	var original_html = document.getElementById(img_id).innerHTML;
	
	document.getElementById(img_id).innerHTML = '<img src="ajax-loader-t.gif" />';
    var num = id;
    var queryString = "?id=" + num;
	
	ajaxRequest.open("GET", p + "toggle.php" + queryString + "&r=" + r, false);
    ajaxRequest.send(null);
	var response = true;
	
	if (response) {
		if (original_html.split('check_gray.png')[0]==original_html) {
			new_html = original_html.replace(/check.png/, 'check_gray.png');
		} else{
			new_html = original_html.replace(/check_gray.png/, 'check.png');
		}
		document.getElementById(img_id).innerHTML = new_html;
		expandcontent(id)
	}
		
}

create a file named toggle.php...

build out your php to handly the query string being passed from the js and update the table.

and use the js like so...

PHP:
<a href="" onClick="offerStatusChange(\''.INCS_URL.'\', \'status\', \'' . $list['id'] . '\'); return false;"><img src="'.$status_img.'" border="0"></a>

you will need to change the variables accordingly to the query pulled, but, i don tknow what you do and dont have, so, i just that for an example.
 
Back
Top