1desman1
asked on
Javascript error
Hi Experts
I have an error that i'm stuck with; here is the code
<script language="JavaScript">
var DomYes=document.getElement ById?1:0;
function set_child_listbox(parentOb ject,child Object,chi ldArray,sp anToHide) {
//Clear child listbox
for(var i=childObject.length;i>0;i --) {
childObject.options[i] = null;
}
childObject.options[0] = new Option("Select Value","");
var sel_index = parentObject.options[paren tObject.se lectedInde x].value;
if (sel_index == "") {
childObject.disabled = true;
} else {
childObject.disabled = false;
var childIndex = 1;
for (i = 0; i < childArray.length; i++) {
if (childArray[i][1] == sel_index) {
childObject.options[childI ndex] = new Option(childArray[i][2], childArray[i][0]);
childIndex++;
}
}
}
//Select first option
childObject.selectedIndex = 0;
//Hide dependent grid
if (spanToHide != "") {
if (DomYes) {
document.getElementById(sp anToHide). style.disp lay="none" ;
} else {
document.all[spanToHide].s tyle.displ ay="none";
}
}
}
function reload_page() {
var sel_index = document.store_productsSea rch.s_cate gory_id.op tions[docu ment.store _productsS earch.s_ca tegory_id. selectedIn dex].value ;
var sel_subindex = document.store_productsSea rch.s_prod uct_id.opt ions[docum ent.store_ productsSe arch.s_pro duct_id.se lectedInde x].value;
if (sel_subindex != "") {
document.location.href = document.location.pathname + "?" + "s_product_id=" + sel_subindex+"&s_category_ id=" + sel_index;
}
}
function disable_child_listbox(span ToHide) {
//Disable second listbox
if (document.store_productsSe arch.s_cat egory_id.s electedInd ex == "") {
document.store_productsSea rch.s_prod uct_id.dis abled = true;
}
//Hide dependent grid
if (document.store_productsSe arch.s_pro duct_id.se lectedInde x == "") {
if (spanToHide != "") {
if (DomYes) {
document.getElementById(sp anToHide). style.disp lay="none" ;
} else {
document.all[spanToHide].s tyle.displ ay="none";
}
}
}
}
window.onload = function() {
disable_child_listbox("Pro ducts");
}
var Product = new Array(
new Array(12,7,"Canvas prints"),
new Array(11,7,"Foam mounted pictures"),
new Array(10,7,"Lasting posters"),
new Array(13,7,"Photographic resizing")
);
</script>
The code is related to 2 list boxes; the first has an option (the 2nd is disabled by default AND isn't 1st error) when the first is selected the 2nd is enabled and the relivant options are populated via the above array
<select onchange="set_child_listbo x(this, document.store_productsSea rch.s_prod uct_id,Pro duct,'Prod ucts');" name="s_category_id">
<option value="" selected>Select Value</option>
<OPTION VALUE="5">Flyers</OPTION>
<OPTION VALUE="1">Photos</OPTION>
<OPTION VALUE="7">PRECIOUS MEMORIES</OPTION>
<OPTION VALUE="6">Signage Display products</OPTION>
<OPTION VALUE="2">Subscriptions</O PTION>
</select>
</td>
</tr>
<tr class="Controls">
<th>Sub category</th>
<td>
<select name="s_product_id">
<option value="" selected>Select Value</option>
</select>
so there is 2 errors:
1st error is:- The 2nd listbox should be disabled untill an option is shown
2nd error is this line >>>>document.getElementByI d(spanToHi de).style. display="n one"; (says object required)
Thanks for reading
I have an error that i'm stuck with; here is the code
<script language="JavaScript">
var DomYes=document.getElement
function set_child_listbox(parentOb
//Clear child listbox
for(var i=childObject.length;i>0;i
childObject.options[i] = null;
}
childObject.options[0] = new Option("Select Value","");
var sel_index = parentObject.options[paren
if (sel_index == "") {
childObject.disabled = true;
} else {
childObject.disabled = false;
var childIndex = 1;
for (i = 0; i < childArray.length; i++) {
if (childArray[i][1] == sel_index) {
childObject.options[childI
childIndex++;
}
}
}
//Select first option
childObject.selectedIndex = 0;
//Hide dependent grid
if (spanToHide != "") {
if (DomYes) {
document.getElementById(sp
} else {
document.all[spanToHide].s
}
}
}
function reload_page() {
var sel_index = document.store_productsSea
var sel_subindex = document.store_productsSea
if (sel_subindex != "") {
document.location.href = document.location.pathname
}
}
function disable_child_listbox(span
//Disable second listbox
if (document.store_productsSe
document.store_productsSea
}
//Hide dependent grid
if (document.store_productsSe
if (spanToHide != "") {
if (DomYes) {
document.getElementById(sp
} else {
document.all[spanToHide].s
}
}
}
}
window.onload = function() {
disable_child_listbox("Pro
}
var Product = new Array(
new Array(12,7,"Canvas prints"),
new Array(11,7,"Foam mounted pictures"),
new Array(10,7,"Lasting posters"),
new Array(13,7,"Photographic resizing")
);
</script>
The code is related to 2 list boxes; the first has an option (the 2nd is disabled by default AND isn't 1st error) when the first is selected the 2nd is enabled and the relivant options are populated via the above array
<select onchange="set_child_listbo
<option value="" selected>Select Value</option>
<OPTION VALUE="5">Flyers</OPTION>
<OPTION VALUE="1">Photos</OPTION>
<OPTION VALUE="7">PRECIOUS MEMORIES</OPTION>
<OPTION VALUE="6">Signage Display products</OPTION>
<OPTION VALUE="2">Subscriptions</O
</select>
</td>
</tr>
<tr class="Controls">
<th>Sub category</th>
<td>
<select name="s_product_id">
<option value="" selected>Select Value</option>
</select>
so there is 2 errors:
1st error is:- The 2nd listbox should be disabled untill an option is shown
2nd error is this line >>>>document.getElementByI
Thanks for reading
ASKER
@ b0lscott
Still the error with
2. The function getElementById() needs to have the id treated as a string. For example ...
document.getElementById("s panToHide" )
Still the error with
2. The function getElementById() needs to have the id treated as a string. For example ...
document.getElementById("s
I looked at the code a little too quick. spanToHide is a variable isn't it, not the value of the id? If it is a variable then remove the quote marks. What does the element look like that has the id of Products? Please provide that block of code too. Search the document and make sure you find id="Products" only once.
bol
bol
Why can't you call the function onload of body instead of window.onload
What HTML element has: id='Products' ?
If you still like to use window.onload, then move your window.onload at the end of your html file:
Example:
<html>
<head></head>
<body>
--
--
</body>
</html>
<script>
window.onload = function() {
disable_child_listbox("Pro ducts");
}
</script>
Example:
<html>
<head></head>
<body>
--
--
</body>
</html>
<script>
window.onload = function() {
disable_child_listbox("Pro
}
</script>
ASKER
@ goops1
That now disables the 2nd list box but still the "Object Required" error on this line >>> document.getElementById(sp anToHide). style.disp lay="none" ;
You mentioned earlier to place this in the body; not knowing javascript very well, how do I do that
Thanks
That now disables the 2nd list box but still the "Object Required" error on this line >>> document.getElementById(sp
You mentioned earlier to place this in the body; not knowing javascript very well, how do I do that
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. Add disabled to the select tag. Something like this ...
<select name="s_product_id" disabled>
2. The function getElementById() needs to have the id treated as a string. For example ...
document.getElementById("s
Let me know if you have any questions or need more information.
b0lsc0tt