hillman
03-27-2006, 06:14 PM
Hi, I'm pretty inexperienced with javascript so any help anyone can give would be greatly appreciated.
I have an sql query that produces a dynamic list box. My project will eventually have a number of these which will be used to populate a 'search box' text field which will be submitted as a search string.
I have been playing around with the code from http://javascript.internet.com/forms/selection-box.html#source.
With this code i have been able to create multiple select boxes that populate a single box.
Is it possible to use this code along with my sql statement so that the entries from my dynamic list box can be used to populate the 'choicebox'. Basically so that it works in the same way, ie with no screen refresh.
I realise there is no direct communication between js and php but I thought because I am creating HTML elements that would bridge the gap - php 'creates' the HTML and then js can pull the values from the HTML. Or does it not work like this?
As I said above any help would be great, thanks in advance.
hillman
This is the list box creation part of my sql query:
$active_job_list = '<select name="active_job_list" size="10 onchange="moveOverActive();">';
while($active_jobs = mysql_fetch_array($sql_active_jobs, MYSQL_ASSOC)){
$active_job_list .= ' <option value="' . $active_jobs['job_id'] . '">' . $active_jobs['job_title'] . '</option>';
}
$active_job_list .= '</select>';
and the js:
function moveOverActive()
{
var boxLengthActive = document.choiceForm.choiceBox.length;
var selectedItemActive = document.choiceForm.active_job_list.selectedIndex;
var selectedTextActive = document.choiceForm.active_job_list.options[selectedItemActive].text;
var selectedValueActive = document.choiceForm.active_job_list.options[selectedItemActive].value;
var a;
var isNewActive = true;
if (boxLengthActive != 0) {
for (a = 0; a < boxLengthActive; a++) {
thisitemActive = document.choiceForm.choiceBox.options[a].text;
if (thisitemActive == selectedTextActive) {
isNewActive = false;
break;
}
}
}
if (isNew) {
newoptionActive = new Option(selectedTextActive, selectedValueActive, false, false);
document.choiceForm.choiceBox.options[boxLengthActive] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
I have an sql query that produces a dynamic list box. My project will eventually have a number of these which will be used to populate a 'search box' text field which will be submitted as a search string.
I have been playing around with the code from http://javascript.internet.com/forms/selection-box.html#source.
With this code i have been able to create multiple select boxes that populate a single box.
Is it possible to use this code along with my sql statement so that the entries from my dynamic list box can be used to populate the 'choicebox'. Basically so that it works in the same way, ie with no screen refresh.
I realise there is no direct communication between js and php but I thought because I am creating HTML elements that would bridge the gap - php 'creates' the HTML and then js can pull the values from the HTML. Or does it not work like this?
As I said above any help would be great, thanks in advance.
hillman
This is the list box creation part of my sql query:
$active_job_list = '<select name="active_job_list" size="10 onchange="moveOverActive();">';
while($active_jobs = mysql_fetch_array($sql_active_jobs, MYSQL_ASSOC)){
$active_job_list .= ' <option value="' . $active_jobs['job_id'] . '">' . $active_jobs['job_title'] . '</option>';
}
$active_job_list .= '</select>';
and the js:
function moveOverActive()
{
var boxLengthActive = document.choiceForm.choiceBox.length;
var selectedItemActive = document.choiceForm.active_job_list.selectedIndex;
var selectedTextActive = document.choiceForm.active_job_list.options[selectedItemActive].text;
var selectedValueActive = document.choiceForm.active_job_list.options[selectedItemActive].value;
var a;
var isNewActive = true;
if (boxLengthActive != 0) {
for (a = 0; a < boxLengthActive; a++) {
thisitemActive = document.choiceForm.choiceBox.options[a].text;
if (thisitemActive == selectedTextActive) {
isNewActive = false;
break;
}
}
}
if (isNew) {
newoptionActive = new Option(selectedTextActive, selectedValueActive, false, false);
document.choiceForm.choiceBox.options[boxLengthActive] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}