www.webdeveloper.com
Results 1 to 3 of 3

Thread: Little form onclick script

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Question Little form onclick script

    Hi,

    I have a problem with this script in IE. It won't do what I want, it just returns 0 in the var "prijs". In FF it is working fine. (I use this code as a onclick script on a form)

    Code:
    var selects = document.getElementsByTagName('SELECT');
    for(var i = 0 ; i< selects.length; i++){
    if(selects[i].name== 'h6074[]'){
    		var cellenid = selects[i].id;
    		break;
       }
    }
    var inputs = document.getElementsByTagName('INPUT');
    for(var i = 0 ; i< inputs.length; i++){
    if(inputs[i].name== 'h8aaf'){
    		var bedragid = inputs[i].id;
    		break;
    }
    }
    var cellen = document.getElementById(cellenid).value;
    var prijs = cellen*10;
    document.getElementById(bedragid).value = prijs;
    As you can see I can't adress the id's directly. I only have the name of the inputs. So that's why the code is so long.

    I hope some can help me.

    Grz

  2. #2
    Join Date
    Nov 2009
    Posts
    5
    I did a test with part of your code and nothing was wrong.
    Even with the use of indirect ID, the code worked well.
    Maybe, your loop "FOR" has a mistake.

    Try to put a alert(...) comand to see the value of variable "cellen", like this:

    >ar cellen = document.getElementById(cellenid).value;
    alert(cellen);
    >ar prijs = cellen*10;
    >document.getElementById(bedragid).value = prijs;

    If the cellen=0 so the code before this step has something wrong.

  3. #3
    Join Date
    Nov 2009
    Posts
    2
    I used "selectedIndex" instead of "value" and all worked fine.

    Tnx for the input.

    Grz

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles