0

Previously I asked about how I could call separate values from a text file without using php ( Include .txt content WITHOUT server side lang? ), and with some of your help I solved the problem:

<script type="text/javascript">
jQuery.get('db.txt', function(data) {
    $('#db').html(data);
     var element = $("#db").text().split("|"); 
     $('#1').text(element[1]);
     $('#3').text(element[3]);
   });
  </script>

  <span id="db" style="display:none;"></span>

  <span id="1"></span>
  <span id="3"></span>

If my text file looks like this Name1 | Number1 | Name2 | Number2 | it will display:

Number 1 Number 2

Works great, except I have ONE little problem left.

Before, when I used php, I had an OnClick function that looked like this:

onClick="simpleCart.add('name=Productname', 'price=<?php echo ''.$field[$loop][1].''; ?>','quantity=1');

The price was echoed from the database with php, but now I can't use any server side language any more. <span id="1"></span> gets the same value as <?php echo ''.$field[$loop][1].''; ?> does, I just don't know how to write it in the OnClick function? I need the span value to be equal the price.

Hope you can help me out here!

Community
  • 1
  • 1
jessifelt
  • 75
  • 3
  • 9

1 Answers1

1
$('span#1').click(function() {
     /* your code like
     simpleCart.add('name=Productname', 'price=' + $('span#1').text(),'quantity=1');
    */
});

or

$('span#1').bind('click', function() {
    /* your code like
     simpleCart.add('name=Productname', 'price=' + $('span#1').text(),'quantity=1');
    */
});

check jQuery API: http://api.jquery.com/click/

Sang
  • 2,790
  • 2
  • 20
  • 17
  • @jessifelt glad to hear that. but please google it before you ask something. whatever you want to do, somebody has done it before. – Sang Dec 27 '11 at 12:09