Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP click for results

  • 21-05-2010 10:28pm
    #1
    Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭


    lets say database
    Baby has 2 results BabyFood and BabyNeeds

    anyway on clicking Baby i can show BabyFood and Babyneeds ?

    obviously cant use href tag and a php function, silly.
    i can think of a silly way of storing the results in an array for all the values in question and upon click showing the particular div, but thats beyond practical and limited dynamic wise.

    i could use a form but id have to make all the vales eg:Baby into a button
    and i dont want to go to a new page. I.e no page refreshes !?

    <B>EDIT:</B>
    i have something work with ajax, but only work for a button, can anyone help me manipulate the functions below for it to work for a link? 'aaa'
    [PHP]<input type="submit" value="load() GET" id="load_get" />

    <A href="" id="load_get">aaa</a>

    <div id="result" class="functions">
    </div>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script&gt;
    <script type="text/javascript">



    $.ajaxSetup ({
    cache: false
    });
    var ajax_load = "<img class='loading' src='img/load.gif' alt='loading...' />";

    // load() functions
    var loadUrl = "load.php";
    $("#load_basic").click(function(){
    $("#result").html(ajax_load).load(loadUrl);
    });



    $("#load_get").click(function(){
    $("#result")
    .html(ajax_load)
    .load(loadUrl, "language=php&version=5");


    });




    // $.get()
    $("#get").click(function(){
    $("#result").html(ajax_load);
    $.get(
    loadUrl,
    {language: "php", version: 5},
    function(responseText){
    $("#result").html(responseText);
    },
    "html"
    );
    });


    </script>[/PHP]


Comments

  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    I've never tried it but you can get a link to fire an AJAX request. If the AJAX function is called myAJAXFunction() then simply do this:
    <a href="javascript:myAJAXFunction();">link text</a>
    

    Hope that helps but still unsure about what it is you actually want to do. If you can clarify there may be an easier way to do it.

    Regards,
    RD


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    i think for jquery i can just set the id=get
    and it will call get click function

    basically
    i just want a simple javascript/ajax script that pass a variable to a php function


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Placebo wrote: »
    i think for jquery i can just set the id=get
    and it will call get click function

    basically
    i just want a simple javascript/ajax script that pass a variable to a php function
    So you want to call that script using a link?

    Why don't you use <a href="javascript:myfunction();">my link</a>


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Not sure if this will help. I don't use Jquery (really need to start it) but instead direct AJAX which probably isn't the most productive. But anyways something like this...

    [ajax.js]
    var xmlHttp = createXmlHttpRequestObject();
    
    function createXmlHttpRequestObject()
    {
    	var xmlHttp;
    	try
    	{
    		xmlHttp = new XMLHttpRequest();
    	}
    	catch(e)
    	{
    		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
    										"MSXML2.XMLHTTP.5.0",
    										"MSXML2.XMLHTTP.4.0",
    										"MSXML2.XMLHTTP.3.0",
    										"MSXML2.XMLHTTP",
    										"Microsoft.XMLHTTP");
    		for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++)
    		{
    			try
    			{
    				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
    			}
    			catch(e) { }
    		}
    	}
    	if (!xmlHttp)
    		alert("Error Creating the XML HttpRequest Object");
    		else
    			return xmlHttp;
    }
    
    function GetNames(babyname, param2)
    {
    	document.getElementById('babynameresultsdiv').innerHTML='<p>Sending your request...</p>';
    	if (xmlHttp)
    	{
    		try
    		{
    			
    			var divelement = "babynameresultsdiv";
    				xmlHttp.open("GET", 'myphpscript.php?babyname='++'&anotherparam='+param2, true);
    		
    			xmlHttp.onreadystatechange = 
    			
    			function handleRequestStateChange()
    {
    	
    	myDiv = document.getElementById(divelement);
    	if (xmlHttp.readyState == 1)
    	{
    		myDiv.innerHTML = "<p>Sending your request...</p>";
    	}
    	else if (xmlHttp.readyState==2)
    	{
    		myDiv.innerHTML = "<p>Sending your request...</p>";
    
    	}
    	else if (xmlHttp.readyState==4)
    	{
    		if (xmlHttp.status == 200)
    		{
    			try
    			{
    				//This is where the output returned from php script will be put in the div
    				var response = xmlHttp.responseText;
    				myDiv.innerHTML = ""+response+"";
    				
    			}
    			catch(e)
    			{
    				alert("Error Getting baby names");
    			}
    		}
    		else
    		{
    		alert("There was a problem retrieving content:\n" + xmlHttp.statusText);
    		}
    	}
    }
    			xmlHttp.send(null);
    		}
    		catch(e)
    		{
    			alert ("Can't connect to server:\n" + e.toString());
    		}
    	}
    }
    

    [mypage.html]
    # Include the js script
    # Call the GetNames method using a link with a href = javascript:GetBabyNames()
    # Have a div to display content.
    


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    might be missing something but can you not use this?

    http://api.jquery.com/jQuery.post/

    point it towards a php file that grabs the data you pass it and display the results if any?


  • Advertisement
Advertisement