Forum Moderators: open

Message Too Old, No Replies

Internal menu link to table cell

         

brettski788

12:57 am on Sep 3, 2010 (gmt 0)

10+ Year Member



I am trying to make a page for quoting on equipment that i deal with.

I want to have a table with dropdowns of parts that we carry and it needs to be relative to 2 different voltage selections. i need to select 12/24V or 120/240 before i select any parts. once i select one of these i would like to have a list of the corresponding parts that are selectable from dropdown menus.

when i select a certain part and quantity i need a price to come up in a seperate cell.

i use dreamweaver, i know this probably isnt possible using just html.

i've looked on several sites for a solution to this problem. i'm not sure if what i am writing is clear here, but any assistance would be nice.

from what i understand i should make an array with the values that i need and have the selections from the drop downs correspond with what array number i add.

i just dont know how to make the data appear in a seperate table cell.

JAB Creations

2:17 am on Sep 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld! :)

I think offhand it sounds like tabular data so what I would probably do is assign an id to each table row...

<tr id="example_1"><td><span>item name</span></td><td><span>item value</span></td></tr>


...and then I would access the ID and the respective table data element the following way...

document.getElementById('example_1').getElementsByTagName('td')[1].getElementsByTagName('span')[0].firstChild.nodeValue = 'example text 1776';


When you script make sure that your JavaScript is only loaded from inside the head element. A lot of people will tell you it's ok to plop it in the body element however that will quickly lead you to doing junk code that is not reliable like innerHTML or document.write in example.

Keep in mind that with getElementsByTagName the numbering starts with 0, not 1.

If you have multiple tables you may want to adjust the row names, always make sure you use reasonably specific values for id attributes (row_1_name versus row1).

Also look closely at how each part of the code is constructed, you can section off most of the HTML and concentrate on specific parts of the page. You don't want to add tons of id attributes on every single span, that would be a waste. JavaScript when used correctly should be thought of as being dynamic. You won't make much money selling a single chicken, you'd want to sell millions of chickens. So when scripting stick that in to a function that you can call over and over again with a couple parameters and that could make it invaluable to you.

Best piece of advice, sit down, and start testing it out before asking questions, you should have more then enough to work with here and when you get really stuck post example code (not links).

Oh and one last thing a lot of people confuse the terms tag and element. In this rare example getElementsByTagName is actually selecting the element's tag, not the element itself. However when you reference an image in example you would reference the img element. An element has two tags (except self-closing elements like images).

- John