0

I have a select list with dynamic content such

Honorar, 120.00
Porti, 7.50
Spesen, 12.00

This values are stored x_ko_leistungsart. I am selecting only one option (no multi selection) and would like to have the values after comma such 120.00 for Honorar and 7.50 if the the option porti is selected.

I am using the following function to get these values. unfortunately it does not work. I get only the value 10 assiged...

Could you please have a look to the code where the mistake can be? Regards thanks mpol_ch

function SelectAnsatz() {
    document.fkostenedit.x_ko_ansatz.value = '10';
    var Ansatz=0;  
    var splitted;  
    var elements = document.getElementsByName("x_ko_leistungsart[]");
    splitted = elements.nextSibling.nodeValue.split(",");
    Ansatz = parseFloat(splitted[1]);
    document.fkostenedit.x_ko_ansatz.value = Ansatz.toFixed(2);
}
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
user727198
  • 89
  • 1
  • 2
  • 11

2 Answers2

1

Take a look at document.getElementsByName("x_ko_leistungsart[]");

I'll give you a hint: The "value" you're getting from that is not what you're expecting. You can reduce at least two lines of code by expanding on the getElementByName function.

You can find more information here: http://www.w3schools.com/dom/dom_nodes_get.asp

anAgent
  • 2,550
  • 24
  • 34
  • I checked it but have not success. Please just keep in mind, that I want to have the value after "," of selected row (opiton). It is drop down list... – user727198 Feb 20 '12 at 17:40
  • Take a look at this post for the answer by @Paolo Bergantino. I'm pretty sure it will point you in the right direction. [link](http://stackoverflow.com/questions/1085801/how-to-get-selected-value-of-dropdownlist-using-javascript) – anAgent Feb 20 '12 at 23:54
0

I solves my problem with an onchange even on x_ko_leistungsart. Here is the function:

Thanks mpol_ch

function SelectAnsatz(){

var x=document.getElementById("x_ko_leistungsart");Ansatz=x.options[x.selectedIndex].text.split(","); document.fkostenedit.x_ko_ansatz.value = Ansatz[1]; }

user727198
  • 89
  • 1
  • 2
  • 11