Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    field_x should have the same value as field_y except...

    Hi,
    I have a javascript-form at:
    http://www.aendekerk.be/beta/airco/bereken.html

    I'm still working on it, people on Codingforums.com have helped me alot, and i hope you still do.

    I have a formfield named "b1x1_totaal" and a formfield named "b1x1_tot_view". The first one contains a certain value (number) (depending on user input).

    I want that the second one (b1x1_tot_view) always contains the same value as the first one (b1x1_totaal) except when the value of the first one is '0,00' (zero), then, the value of 'b1x1_tot_view' should be 'X'.

    How do i do this?

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Try this:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    script>
    function 
    bla(){
    d=document.forms[0];
    if(
    parseFloat(d.b1x1_totaal.value) == 0){
    d.b1x1_tot_view.value 'X'
    }
    else {
    d.b1x1_tot_view.value d.b1x1_totaal.value}
    }
    </script>
    </head>

    <body>
    <form>
    b1x1_totaal
    <input name="b1x1_totaal" type="text" onkeyup="bla()"><br><br>
    b1x1_tot_view<input name="b1x1_tot_view" type="text">
    </form>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!!
    This one works!
    Code:
      	if(parseFloat(document.aForm.b1x1_totaal.value) == 0){ 
      	document.aForm.b1x1_tot_view.value = 'X' 
    	} 
    	else {document.aForm.b1x1_tot_view.value = document.aForm.b1x1_totaal.value}
      	if(parseFloat(document.aForm.b1x2_totaal.value) == 0){ 
      	document.aForm.b1x2_tot_view.value = 'X' 
    	} 
    	else {document.aForm.b1x2_tot_view.value = document.aForm.b1x2_totaal.value} 
      	if(parseFloat(document.aForm.b1x3_totaal.value) == 0){ 
      	document.aForm.b1x3_tot_view.value = 'X' 
    	} 
    	else {document.aForm.b1x3_tot_view.value = document.aForm.b1x3_totaal.value} 
      	if(parseFloat(document.aForm.b1x4_totaal.value) == 0){ 
      	document.aForm.b1x4_tot_view.value = 'X' 
    	} 
    	else {document.aForm.b1x4_tot_view.value = document.aForm.b1x4_totaal.value}

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Better try to keep the code shorter by using loops and shortcut notation:

    PHP Code:
    for(i=1;i<5;i++){
    document.aForm;
    if(
    parseFloat(d.elements['b1x'+i+'_totaal'].value) == 0){ 
    d.elements['b1x'+i+'_tot_view'].value 'X' 

    else 
    d.elements['b1x'+i+'_tot_view'].value d.elements['b1x'+i+'_totaal'].value}

    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    an error occured(a braqett missed)

    here's the good one

    PHP Code:
    for(i=1;i<5;i++){ 
    document.aForm
    if(
    parseFloat(d.elements['b1x'+i+'_totaal'].value) == 0){  
    d.elements['b1x'+i+'_tot_view'].value 'X'  
    }  
    else {
    d.elements['b1x'+i+'_tot_view'].value d.elements['b1x'+i+'_totaal'].value

    Whenever you have large number of similar objects on page, try using loops and any incremental way to keep the code as short as possible
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New Coder
    Join Date
    Feb 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey,
    Thanks for the tip!!!


  •  

    Posting Permissions

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