[Javascript] Help to debug this
Paul Novitski
paul at juniperwebcraft.com
Wed Aug 16 20:44:06 CDT 2006
At 04:51 PM 8/16/2006, Marcelo Wolfgang wrote:
>Can someone here please tell me why nothing happens in the above code ?
>
><script type="text/javascript">
> function
> addToCart(catalogID){
> window.location='cart.cfm?act=add&storeOwner=paula&item_id='+catalog.ID+'&prodSize='+getElementByID(prodSizeSelect).value+'&prodColor='+getElementByID(prodColorSelect).value;
> }
></script>
>
>Here's the HTML:
>
><div id="prodDescription">
> <div id="prodDesc-size">
> <div id="prodSize-dropdown">
> <select id="prodSizeSelect" name="prodSize">
> <option value="P">P</option>
> <option value="M">M</option>
> <option value="G">G</option>
> </select>
> </div>
> </div>
> <div id="prodDesc-color">
> <select id="prodColorSelect" name="prodColor">
> <option value="dourado">dourado</option>
> <option value="uva">uva</option>
> <option value="preto">preto</option>
> </select>
> </div>
> <div id="prodDesc-addToCart"><a href="##"
>onClick="document.getElementById('item-added').className='show';addToCart(5);">Colocar
>no carrinho<img src="images/prodaddCart_icon.gif" width="16"
>height="16" alt="Colocar no carrinho" /></a></div>
></div>
>
>Can anyone tell me what I'm doing wrong here ?
I can see a couple of things:
1) There is no element with the id "item-added" so the 'Colocar no
carrinho' onlick event will fail.
2) getElementByID should be getElementById
3) getElementByID(prodSizeSelect) should be getElementById("prodSizeSelect")
4) getElementByID(prodColorSelect) should be getElementById("prodColorSelect")
I recommend that you separate your HTML and your javascript instead
of including your javascript inline. Also, if you break your long
statements into shorter steps, it will be easier to debug.
I would also like to suggest that giving us a link to a complete HTML
page online will get you a better quality of criticism than inserting
javascript in your email message.
Regards,
Paul
More information about the Javascript
mailing list