www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] add var to array

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Location
    Durban
    Posts
    12

    resolved [RESOLVED] add var to array

    I have an array that I add items to.
    everything works if I add values but a need to add a variable value and it keeps saying NAN.
    Below my code:
    Code:
    <script type="text/javascript">
    	var cs = parseFloat(document.getElementsByName("target_value")[0].value) * 595;
    </script>
    This works:
    Code:
    onclick="simpleCart.add('name=Swanniebraai Complete','price=595', 'dollar=61');return false;"
    the problem is that the dollar value must change according to the exchange rate, I have a input box named target_value which holds the exchange rate value.
    I have tried the following:
    Code:
    onclick="cart.add('name=Swanniebraai Complete','price=595', 'dollar=<script>parseFloat(document.getElementsByName(\'target_value\')[0].value)</script>');return false;"
    and
    Code:
    onclick="cart.add('name=Swanniebraai Complete','price=595', 'dollar=cs'"
    and
    Code:
    onclick="cart.add('name=Swanniebraai Complete','price=595', 'dollar=<script>cs</script>'"
    Please help urgently. Please please please.

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,687
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script>
    var cs=4;
    
    function add(a,b,c){
     alert(c);
    }
    </script></head>
    
    <body>
    <input type="button" name="" value="TEST" onclick="add('name=Swanniebraai Complete','price=595', 'dollar='+cs);"/>
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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