Click to See Complete Forum and Search --> : document.getElementBy.....


halbesma
02-05-2006, 02:31 AM
Hi,
I don't use JS very much but the follow code I want to change so the value it gives is in an input box.
Basically what the script does is it adds up a few fields (drop down menus) and displays a price of the selected options in the fields. But this is displayed as:

<div id=total></div>



But I want it to display the total in an input text box instead.
The following is the code for some of the script, I think I've post all that is relavent for the code.
Please help!


function calc_me (obj) {



var total = 0;



for (i=0; i<names_selects.length; i++) {



var el = eval("obj.form." +names_selects[i]);



var val = el.options[el.selectedIndex].value;



get_price = eval(el.name + "_prices['" + val + "']");



if (el.name == 'key_disk_space') {



val = val/50;



}



get_unit_price = (val != 0) ? get_price/val : 0;



document.getElementById(el.name + '_row').innerHTML = "$" +display_dec_string(get_price);



tmp_v = el.options[el.selectedIndex].value;



tmp_p = eval(names_selects[i] + "_prices['" + tmp_v + "']");



if (el && el.options[el.selectedIndex].value) total+= parseFloat(tmp_p);



}



document.getElementById('total').innerHTML = "$" +display_dec_string(total);



}

function show_hide(id)
{
var tmp;
eval("tmp = document.getElementById('"+id+"').style.display");
if(tmp == 'none')
{
eval("document.getElementById('"+id+"').style.display = 'block'");
document.cookie = id + "=" + escape('block') + "; path=/";
}else{
eval("document.getElementById('"+id+"').style.display = 'none'");
document.cookie = id + "=" + escape('none') + "; path=/";
}
}

Fang
02-05-2006, 02:49 AM
document.getElementById('total').value

Stop using eval; it's not necessary:
document.getElementById(id).style.display = 'none';

halbesma
02-05-2006, 03:00 AM
Stop using eval; it's not necessary:
document.getElementById(id).style.display = 'none';

Sorry, I am not quite understanding extactly which part of the script I should change....

How can I use this to display the value in a input text box?

Fang
02-05-2006, 08:08 AM
This line: eval("document.getElementById('"+id+"').style.display = 'block'");
becomes: document.getElementById(id).style.display = 'block';