Page 1 of 1
php and DOM
Posted: Fri Aug 09, 2002 7:06 pm
by Indium
Does php understand the DOM? Is it possible to drill down to a specific object like can be done with Javascript, e.g. how would the following javascript code be written in php.
Code: Select all
document.form.selectname.selectedindex.value
Can anybody point me to some links for that kind of stuff?
Posted: Sat Aug 10, 2002 2:12 am
by volka
first of all: please
read this sticky thread
document.form.selectname.selectedindex.value is a client-side 'runtime-value' that php will probably never see.
Posted: Sat Aug 10, 2002 1:10 pm
by Indium
Ok, so php doesn't understand javascript. I was under the impression php could be used to get around the cross-browser issues of javascript and the issue of javascript being disabled by the client. If you can't access a form object and it's properties using php then how can php help with these issues?
Posted: Sat Aug 10, 2002 1:38 pm
by BDKR
I was under the impression that php could be used to get around the cross-browser issues of javascript ...
Yes, this is true. It (I should say, "The Developer") does this by sending a script to a browser based on what that browser is.
If you can't access a form object and it's properties using php then how can php help with these issues?
Is it the object you need, or the data returned when the submit button is pressed? That makes a big difference. Explain why you would need the object so that we can begin to understand and possibly help.
Later on,
BDKR
Posted: Sat Aug 10, 2002 4:09 pm
by Indium
What I had in mind was two dropdown menu's. The the selection of the first menu would dynamically generate the selections for the second dropdown menu. The values of the selections from each menu would be submitted to a script that would generate the url of the appropriate page.
I could do this in javascript but would like to do this in php. The only reasons for doing this in php is to learn the language and to try to circumvent the problems of using a javascript. I guess I am trying to fit the problem to php rather than match php to the problem, just so I can learn php.
Posted: Mon Aug 12, 2002 5:05 pm
by BDKR
Well, you could do it with PHP, but with each selection, the form and it's info needs to make a trip back to the server. This is far less than ideal and the user won't like you much for it either.
That siad, Javascript makes a lot of sense along these lines. Below is the function that I use.
Code: Select all
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem)
{
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--)
{
selectCtrl.optionsїi] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null)
{
j = 0;
}
else
{
selectCtrl.optionsї0] = new Option(prompt);
j = 1;
}
if (itemArray != null)
{
// add new items
for (i = 0; i < itemArray.length; i++)
{
selectCtrl.optionsїj] = new Option(itemArrayїi]ї0]);
if (itemArrayїi]ї1] != null)
{
selectCtrl.optionsїj].value = itemArrayїi]ї1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.optionsї0].selected = true;
}
}
Pick something in one drop down and it populates another drop down based on that choice. If you need help with it, let me know.
Later on,
BDKR
Thanks
Posted: Mon Aug 12, 2002 6:27 pm
by Indium
Thanks, I'll give it a try.