Jump to content

Changing DIV content on select change


Darkmatter5

Recommended Posts

Here's the HTML

<script type="text/javascript" src="/library/scripts/selectclass.js" /></script>

<select name='class' method='get' class='text_boxes' onchange='showClassdescr(this.value)'>
<option value='6'>Charismatic</option>
<option value='5'>Dedicated</option>
<option value='2'>Fast</option>
<option value='4'>Smart</option>
<option value='1'>Strong</option>
<option value='3'>Tough</option>
</select>
<div id="class_descr"><b>Class description will display here when a class is chosen.</b></div>

 

Here's the Javascript file

var xmlhttp

function showClassdescr(str) {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url="/library/scripts/getclassdescr.php";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function stateChanged() {
    if (xmlhttp.readyState==4) {
        document.getElementById("class_descr").innerHTML=xmlhttp.responseText;
    }
}

function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

 

Here's the getclassdescr.php file

<?php
  include_once('library/config.php');
  
  $q=$_GET["q"];
  $result=mysql_query("SELECT descr FROM classes WHERE class_id='$q'");
  while($row=mysql_fetch_array($result)) { echo "$row[descr]"; }
?>

 

Here's the file locations

pcbuilder.php

/library/config.php

/library/scripts/getclassdescr.php

/library/scripts/selectclass.js

 

When I change the selection it does nothing.  How can I test this a piece at a time or does anyone readily see the error?  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/161068-changing-div-content-on-select-change/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.