Jump to content

Recommended Posts

I'm doing this tutorial from ajax for dummies and it's proving I'm a dummy. I'm apparently a slow learner with this. I have the ebook so I don't have the supplemental materials, so I can't see the whole example. The page loads two color schemes to color text. I can't learn things by abandoning an example that I don't understand how to fix. Please help.

 

I have this that loads the information from options1.php

<form>
<select size="1" id="optionList" onchange="setOption()">
<option>Select a Scheme</option>
</select>
<input type="button" value = "Use Color Scheme 1" onclick = "getOptions('1')">
<input type="button" value = "Use Color Scheme 2" onclick = "getOptions('2')">
</form>
<div id="targetDiv" width = 100 height = 100>Color this Text</div>

 

I know options1.php works because I can go to it and it'll show the xml file just fine.

 

and here are my functions:

var options;

function listOptions() {
var loopIndex;
var selectControl = document.getElementById('optionList');
for (loopIndex = 0; loopIndex < options.length; loopIndex++) {
selectControl.options[loopIndex] = new Option(options[loopIndex].firstChild.data);
}
}

function setOption() {
document.getElementById('targetDiv').style.color = options[document.getElementById('optionsList').selectedIndex].firstChild.data;
}

function getOptions(scheme) {
var url = "options1.php?scheme="+scheme;
if (XMLHttpRequestObject){
XMLHttpRequestObject.open("GET", url, true);

XMLHttpRequestObject.onreadystatechange = function() {
if (XMLHttpRequestObject.readystate == 4 && XMLHttpRequestObject.status == 200){
var xmlDocument = XMLHttpRequestObject.responseXML;
options = xmlDocument.getElementByTagName("option");
listOptions();
}
}
XMLHttpRequestObject.send(null);
}
}

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/134919-solved-i-cant-get-a-tutorial-to-work/
Share on other sites

XMLHttpRequestObject.readyState == 4

.--------------------------^  needs to be a capital S

 

options = xmlDocument.getElementsByTagName("option");

---------------------------------^ needs an s

 

 

Otherwise it worked fine, populated the left side drop down with colors...

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.