I am trying to add an items price depending on the item that is selected in the Dopdown list. I want the price to be displayed inside the cell next to the drop down list without having to refresh the page. i have an <td> tag that has an ID attribute inside of it and i am trying to get document.getElementById("FramePrice") to see if that can write to the cell and there will be no need to refresh the page if the user selects a different item. If there is not way of doing this can somone give me ideas on another way that should at least print an items price to the cell depending on which items is selected. I have included my Javascript and my HTML. any help would be appreciated.
Here is the Javascript
function fillFrameCompany(){
//this function is used to fill the category list on load
addOption(document.drop_list.FCompany, "Specialized", "Specialized", "");
addOption(document.drop_list.FCompany, "Sinister", "Sinister", "");
addOption(document.drop_list.FCompany, "Giant", "Giant", "");
addOption(document.drop_list.FCompany, "Santa Cruz", "Santa Cruz", "");
addOption(document.drop_list.FCompany, "Cannondale", "Cannondale", "");
addOption(document.drop_list.FCompany, "Kona", "Kona", "");
addOption(document.drop_list.FCompany, "NS", "NS", "");
addOption(document.drop_list.FCompany, "Rockey Mountain", "Rockey Mountain", "");
addOption(document.drop_list.FCompany, "Trek", "Trek", "");
addOption(document.drop_list.FCompany, "Haro", "Haro", "");
}
function SelectFrame(){
//ON selection of category this function will work
removeAllOptions(document.drop_list.Frame);
addOption(document.drop_list.Frame, "Select Frame", "Select Frame", "Select Frame");
if(document.drop_list.FCompany.value == 'Specialized'){
addOption(document.drop_list.Frame,"Demo 8", "Demo 8");
addOption(document.drop_list.Frame,"Demo 8 Frame", "Demo 8 Frame");
addOption(document.drop_list.Frame,"Demo 7", "Demo 7");
}
if(document.drop_list.FCompany.value == 'Sinister'){
addOption(document.drop_list.Frame,"R9", "R9");
addOption(document.drop_list.Frame,"Mustang", "Mustang");
addOption(document.drop_list.Frame,"Ridge", "Ridge", "");
addOption(document.drop_list.Frame,"Gruitr", "Gruitr", "");
addOption(document.drop_list.Frame,"DNA", "DNA", "");
}
if(document.drop_list.FCompany.value == 'Giant'){
addOption(document.drop_list.Frame,"Anthem Advanced", "Anthem Advanced", "");
addOption(document.drop_list.Frame,"Anthem", "Anthem", "");
addOption(document.drop_list.Frame,"Glory DH", "Glory DH", "");
addOption(document.drop_list.Frame,"Trance Advanced", "Trance Advanced", "");
addOption(document.drop_list.Frame,"Trance", "Trance", "");
addOption(document.drop_list.Frame,"Trance X", "Trance X", "");
addOption(document.drop_list.Frame,"Reign X", "Reign X", "");
addOption(document.drop_list.Frame,"Reign", "Reign", "");
addOption(document.drop_list.Frame,"Glory", "Glory", "");
addOption(document.drop_list.Frame,"STP", "STP", "");
addOption(document.drop_list.Frame,"XTC Alliance", "XTC Alliance", "");
addOption(document.drop_list.Frame,"XTC", "XTC", "");
addOption(document.drop_list.Frame,"Youkon FX", "Youkon FX", "");
addOption(document.drop_list.Frame,"Youkon", "Youkon", "");
addOption(document.drop_list.Frame,"Rincon", "Rincon", "");
addOption(document.drop_list.Frame,"Boulder SE", "Boulder SE", "");
addOption(document.drop_list.Frame,"Boulder", "Boulder", "");
}
}
function FramePrice(){
var frames = new Array();
frames[0] = "Glory";
frames[1] = "Glory DH";
for
(i=0; i<frames.length;i++)
{
switch(frames[i])
case 0:
document.getElementById("FramePrice").write;
break;
case 1;
document.getElementById("FramePrice").write;
}
}
function fillHeadsetCompany(){
addOption(document.drop_list.HCompany, "Cane Creek", "Cane Creek", "");
}
function SelectHeadset(){
removeAllOptions(document.drop_list.Headset);
addOption(document.drop_list.Headset, "Headset", "Select Headset", "");
if(document.drop_list.HCompany.value == 'Cane Creek'){
addOption(document.drop_list.Headset,"1", "1");
addOption(document.drop_list.Headset,"2", "2");
addOption(document.drop_list.Headset,"3", "3");
}
}
//////////////////
function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}
function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
I place most of the blame for the crappy state of gaming on smartphones. But Unreal Engine gets some of the blame also for allowing everyone and their dog to make a video game. The diamonds get buried in a massive dunghill, which from the sound of it is about to grow much larger.
Hello,
There were some claims he was involved in the malware scene in Montréal in the 00's, but I don't think they were ever substantiated.
Regards,
Aryeh Goretsky
Question
mtber
I am trying to add an items price depending on the item that is selected in the Dopdown list. I want the price to be displayed inside the cell next to the drop down list without having to refresh the page. i have an <td> tag that has an ID attribute inside of it and i am trying to get document.getElementById("FramePrice") to see if that can write to the cell and there will be no need to refresh the page if the user selects a different item. If there is not way of doing this can somone give me ideas on another way that should at least print an items price to the cell depending on which items is selected. I have included my Javascript and my HTML. any help would be appreciated.
Here is the Javascript
function fillFrameCompany(){ //this function is used to fill the category list on load addOption(document.drop_list.FCompany, "Specialized", "Specialized", ""); addOption(document.drop_list.FCompany, "Sinister", "Sinister", ""); addOption(document.drop_list.FCompany, "Giant", "Giant", ""); addOption(document.drop_list.FCompany, "Santa Cruz", "Santa Cruz", ""); addOption(document.drop_list.FCompany, "Cannondale", "Cannondale", ""); addOption(document.drop_list.FCompany, "Kona", "Kona", ""); addOption(document.drop_list.FCompany, "NS", "NS", ""); addOption(document.drop_list.FCompany, "Rockey Mountain", "Rockey Mountain", ""); addOption(document.drop_list.FCompany, "Trek", "Trek", ""); addOption(document.drop_list.FCompany, "Haro", "Haro", ""); } function SelectFrame(){ //ON selection of category this function will work removeAllOptions(document.drop_list.Frame); addOption(document.drop_list.Frame, "Select Frame", "Select Frame", "Select Frame"); if(document.drop_list.FCompany.value == 'Specialized'){ addOption(document.drop_list.Frame,"Demo 8", "Demo 8"); addOption(document.drop_list.Frame,"Demo 8 Frame", "Demo 8 Frame"); addOption(document.drop_list.Frame,"Demo 7", "Demo 7"); } if(document.drop_list.FCompany.value == 'Sinister'){ addOption(document.drop_list.Frame,"R9", "R9"); addOption(document.drop_list.Frame,"Mustang", "Mustang"); addOption(document.drop_list.Frame,"Ridge", "Ridge", ""); addOption(document.drop_list.Frame,"Gruitr", "Gruitr", ""); addOption(document.drop_list.Frame,"DNA", "DNA", ""); } if(document.drop_list.FCompany.value == 'Giant'){ addOption(document.drop_list.Frame,"Anthem Advanced", "Anthem Advanced", ""); addOption(document.drop_list.Frame,"Anthem", "Anthem", ""); addOption(document.drop_list.Frame,"Glory DH", "Glory DH", ""); addOption(document.drop_list.Frame,"Trance Advanced", "Trance Advanced", ""); addOption(document.drop_list.Frame,"Trance", "Trance", ""); addOption(document.drop_list.Frame,"Trance X", "Trance X", ""); addOption(document.drop_list.Frame,"Reign X", "Reign X", ""); addOption(document.drop_list.Frame,"Reign", "Reign", ""); addOption(document.drop_list.Frame,"Glory", "Glory", ""); addOption(document.drop_list.Frame,"STP", "STP", ""); addOption(document.drop_list.Frame,"XTC Alliance", "XTC Alliance", ""); addOption(document.drop_list.Frame,"XTC", "XTC", ""); addOption(document.drop_list.Frame,"Youkon FX", "Youkon FX", ""); addOption(document.drop_list.Frame,"Youkon", "Youkon", ""); addOption(document.drop_list.Frame,"Rincon", "Rincon", ""); addOption(document.drop_list.Frame,"Boulder SE", "Boulder SE", ""); addOption(document.drop_list.Frame,"Boulder", "Boulder", ""); } } function FramePrice(){ var frames = new Array(); frames[0] = "Glory"; frames[1] = "Glory DH"; for (i=0; i<frames.length;i++) { switch(frames[i]) case 0: document.getElementById("FramePrice").write; break; case 1; document.getElementById("FramePrice").write; } } function fillHeadsetCompany(){ addOption(document.drop_list.HCompany, "Cane Creek", "Cane Creek", ""); } function SelectHeadset(){ removeAllOptions(document.drop_list.Headset); addOption(document.drop_list.Headset, "Headset", "Select Headset", ""); if(document.drop_list.HCompany.value == 'Cane Creek'){ addOption(document.drop_list.Headset,"1", "1"); addOption(document.drop_list.Headset,"2", "2"); addOption(document.drop_list.Headset,"3", "3"); } } ////////////////// function removeAllOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--) { //selectbox.options.remove(i); selectbox.remove(i); } } function addOption(selectbox, value, text ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); }Here is my HTML
Link to comment
https://www.neowin.net/forum/topic/646382-javascript-adding-text-to-table-cell/Share on other sites
13 answers to this question
Recommended Posts