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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.