Changing Strings to Integers

Results 1 to 2 of 2

Thread: Changing Strings to Integers

  1. #1
    Join Date
    Dec 1969

    Default Changing Strings to Integers

    Hi there!<BR><BR>I am trying to:<BR><BR>1) take a value from a form (a number)<BR>2) bring into a java script function<BR>3) change the number<BR>4) return it back to the form<BR><BR>However it only see the passed parameter (in the java script function) as a string. And then it won&#039;t let me work with this value. I want to figure out how to make it into an integer in the function. THANKS!!<BR><BR>Here&#039;s what I have so far...<BR><BR>THIS IS THE SELECT FORM TYPE, IT LISTS DIFFERENT NUMBERS:<BR>&#060;select name="SubTotalPrice" onchange="pSaveNeighborhood (window.document.Form_1.SubTotalPrice.options[selectedIndex].text);" &#062; <BR><BR><BR>THIS IS THE FUNCTION THAT CALCULATES THE INITIAL NUMBER:<BR>&#060;SCRIPT language="JavaScript"&#062; <BR>function pSaveNeighborhood (sub_total_price)<BR>{ <BR> var iPercentFee = .029;<BR> var iFee = .30;<BR> var iTotal;<BR><BR><BR>iTotal = (sub_total_price * iPercentFee) + iPercentFee;<BR>alert(&#039;iTotal&#039; + iTotal)<BR> <BR>} <BR>&#060;/SCRIPT&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Changing Strings to Integers

    Try parseInt(), parseFloat() and the Math object... <BR><BR>&#060;SCRIPT language="JavaScript"&#062; <BR>function pSaveNeighborhood (sub_total_price)<BR>{ <BR>var iPercentFee = .029;<BR>var iFee = .30;<BR>var iTotal;<BR><BR>iTotal = (parseFloat(sub_total_price) * parseFloat(iPercentFee)) + ParseFloat(iPercentFee);<BR>alert(&#039;iTotal&#03 9; + iTotal)<BR><BR>} <BR>&#060;/SCRIPT&#062; <BR><BR>I didn&#039;t try this it may need more work, but it should point you in the rioht direction.<BR><BR><BR>

Posting Permissions

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