PHP & JavaScript

Recently  i really had a tough time doing something very trivial and still weighing my head. I am back to the drawing board to learn javascript, cos i taught i could hide  from this one.

I have become more addicted to PHP that i want to do everything in PHP but i was enlightened about a fact about php that i did not know and even if i knew i did not think that was the problem i was facing.

“Problem: I have  two select form where by the values of the first field is related to the second in that when a value of the first field is select the value of the second field changes and all the data is selected from the database;”

I was successful somehow to do that in PHP but it did not work as i expected cos u have to refresh each time for the data to change.

I will appreciate if u can contribute to this post….

Advertisements
    • Francis Adu-Gyamfi
    • August 26th, 2010

    Your requirements are not clear and neither is the diction. However, from what you statement looks like, the following example is a skeleton of what you might want to achieve, assuming you understand all that is going on.

    var select1 = document.getElementById(“select1”);
    var select2 = document.getElementById(“select2”);

    select1.addEventListener(‘change’,function() {
    select2.value = select1.value;

    // make ajax call to the database, this example uses the JQuery JS library
    var query = “id=” + select2.value;
    $.post(‘ajax_page.php’,query, function(data) {
    var target_div = document.getElementById(“target”);
    target_div.innerHTML = data;
    } );
    }, false);

    • gidmakus
    • May 31st, 2011

    thank francis for your response

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: