473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

javascript string manipulation

YT
Hello,

Here's the situation:
I have several fields split into 2 sections (Debt & Equity) on a form that should only take numerical values. The page is a mix of Javascript & ASP such that when the user visits the page, the initial values of the field are filled in by Session cookies. When the cursor leaves a field, the code checks to see if the entry is a number, and if it is not then it replaces it with a "0". Then it checks each field for empty entries and when it finds one, it replaces it with an "0". Then it totals up the entries in a sub-total and then totals up the two sub-totals.

See the code below for details (should be self-explanatory).

The goal is to modify the code to find out if the user has entered in a comma for one of the numbers. Ie. these are all dollar values, and as such when someone enters in 10,000 the code resets that field to a zero. what I'd like to do is to modify the code such that the ** check process looks for commas in each field AND removes them ** before number checking and blank entry checking.
Can you help me?! Thanks in advance!!!!!

yt

CURRENT CODE:

<SCRIPT LANGUAGE='JavaScript'>
<!-- // Hide from old browsers ...
function Formsubmit () {
document.frm_q2.submit();
return;
}

function Initialize() {
frm_q2.q2_debt_homeequity.value = "<%=Session("q2_debt_homeequity")%>";
frm_q2.q2_debt_banks.value = "<%=Session("q2_debt_banks")%>";
frm_q2.q2_debt_otherfinancial.value = "<%=Session("q2_debt_otherfinancial")%>";
frm_q2.q2_debt_creditcards.value = "<%=Session("q2_debt_creditcards")%>";
frm_q2.q2_debt_government.value = "<%=Session("q2_debt_government")%>";
frm_q2.q2_debt_spouse.value = "<%=Session("q2_debt_spouse")%>";
frm_q2.q2_debt_familyorfriends.value = "<%=Session("q2_debt_familyorfriends")%>";
frm_q2.q2_debt_formerowners.value = "<%=Session("q2_debt_formerowners")%>";
frm_q2.q2_debt_other.value = "<%=Session("q2_debt_other")%>";

frm_q2.q2_equity_ownersavings.value = "<%=Session("q2_equity_ownersavings")%>";
frm_q2.q2_equity_spouse.value = "<%=Session("q2_equity_spouse")%>";
frm_q2.q2_equity_familyorfriends.value = "<%=Session("q2_equity_familyorfriends")%>";
frm_q2.q2_equity_formerowners.value = "<%=Session("q2_equity_formerowners")%>";
frm_q2.q2_equity_investors.value = "<%=Session("q2_equity_investors")%>";
frm_q2.q2_equity_other.value = "<%=Session("q2_equity_other")%>";

DebtCheck();
EquityCheck();
}

function DebtCheck() {
if ( isNaN( frm_q2.q2_debt_homeequity.value ) ) frm_q2.q2_debt_homeequity.value = "0";
if ( isNaN( frm_q2.q2_debt_banks.value ) ) frm_q2.q2_debt_banks.value = "0";
if ( isNaN( frm_q2.q2_debt_otherfinancial.value ) ) frm_q2.q2_debt_otherfinancial.value = "0";
if ( isNaN( frm_q2.q2_debt_creditcards.value ) ) frm_q2.q2_debt_creditcards.value = "0";
if ( isNaN( frm_q2.q2_debt_government.value ) ) frm_q2.q2_debt_government.value = "0";
if ( isNaN( frm_q2.q2_debt_spouse.value ) ) frm_q2.q2_debt_spouse.value = "0";
if ( isNaN( frm_q2.q2_debt_familyorfriends.value ) ) frm_q2.q2_debt_familyorfriends.value = "0";
if ( isNaN( frm_q2.q2_debt_formerowners.value ) ) frm_q2.q2_debt_formerowners.value = "0";
if ( isNaN( frm_q2.q2_debt_other.value ) ) frm_q2.q2_debt_other.value = "0";

if ( frm_q2.q2_debt_homeequity.value == "" ) frm_q2.q2_debt_homeequity.value = "0";
if ( frm_q2.q2_debt_banks.value == "" ) frm_q2.q2_debt_banks.value = "0";
if ( frm_q2.q2_debt_otherfinancial.value == "" ) frm_q2.q2_debt_otherfinancial.value = "0";
if ( frm_q2.q2_debt_creditcards.value == "" ) frm_q2.q2_debt_creditcards.value = "0";
if ( frm_q2.q2_debt_government.value == "" ) frm_q2.q2_debt_government.value = "0";
if ( frm_q2.q2_debt_spouse.value == "" ) frm_q2.q2_debt_spouse.value = "0";
if ( frm_q2.q2_debt_familyorfriends.value == "" ) frm_q2.q2_debt_familyorfriends.value = "0";
if ( frm_q2.q2_debt_formerowners.value == "" ) frm_q2.q2_debt_formerowners.value = "0";
if ( frm_q2.q2_debt_other.value == "" ) frm_q2.q2_debt_other.value = "0";
//alert("Please check your email details are correct before submitting")
frm_q2.q2_debt_subtotal.value = parseFloat( frm_q2.q2_debt_homeequity.value ) + parseFloat( frm_q2.q2_debt_banks.value ) + parseFloat( frm_q2.q2_debt_otherfinancial.value ) + parseFloat( frm_q2.q2_debt_creditcards.value ) + parseFloat( frm_q2.q2_debt_government.value ) + parseFloat( frm_q2.q2_debt_spouse.value ) + parseFloat( frm_q2.q2_debt_familyorfriends.value ) + parseFloat( frm_q2.q2_debt_formerowners.value ) + parseFloat( frm_q2.q2_debt_other.value ) ;

TotalCheck();
}

function EquityCheck() {
if ( isNaN( frm_q2.q2_equity_ownersavings.value ) ) frm_q2.q2_equity_ownersavings.value = "0";
if ( isNaN( frm_q2.q2_equity_spouse.value ) ) frm_q2.q2_equity_spouse.value = "0";
if ( isNaN( frm_q2.q2_equity_familyorfriends.value ) ) frm_q2.q2_equity_familyorfriends.value = "0";
if ( isNaN( frm_q2.q2_equity_formerowners.value ) ) frm_q2.q2_equity_formerowners.value = "0";
if ( isNaN( frm_q2.q2_equity_investors.value ) ) frm_q2.q2_equity_investors.value = "0";
if ( isNaN( frm_q2.q2_equity_other.value ) ) frm_q2.q2_equity_other.value = "0";

if ( frm_q2.q2_equity_ownersavings.value == "" ) frm_q2.q2_equity_ownersavings.value = "0";
if ( frm_q2.q2_equity_spouse.value == "" ) frm_q2.q2_equity_spouse.value = "0";
if ( frm_q2.q2_equity_familyorfriends.value == "" ) frm_q2.q2_equity_familyorfriends.value = "0";
if ( frm_q2.q2_equity_formerowners.value == "" ) frm_q2.q2_equity_formerowners.value = "0";
if ( frm_q2.q2_equity_investors.value == "" ) frm_q2.q2_equity_investors.value = "0";
if ( frm_q2.q2_equity_other.value == "" ) frm_q2.q2_equity_other.value = "0";
//alert("Please check your email details are correct before submitting")
frm_q2.q2_equity_subtotal.value = parseFloat( frm_q2.q2_equity_ownersavings.value ) + parseFloat( frm_q2.q2_equity_spouse.value ) + parseFloat( frm_q2.q2_equity_familyorfriends.value ) + parseFloat( frm_q2.q2_equity_formerowners.value ) + parseFloat( frm_q2.q2_equity_investors.value ) + parseFloat( frm_q2.q2_equity_other.value );

TotalCheck();
}

function TotalCheck() {
frm_q2.q2_total.value = parseFloat( frm_q2.q2_debt_subtotal.value ) + parseFloat( frm_q2.q2_equity_subtotal.value );
}
//-->
</SCRIPT>

Jul 20 '05 #1
1 15448
Write and implement a function similar to the following:

function removeComma( val )
{
re = /,/gi;
return( val.replace( re, "" ));
}

Hope that helps.

N. Clements
Brainbench MVP for _Javascript
www.brainbench.com
no****@spam.spam.spam.242.mailshell.com
Remove 2nd through 4th spam to reply.
"YT" <yt@MAPSONfunkychickens.org> wrote in
news:xU*****************@newscontent-01.sprint.ca:
Hello,

Here's the situation:
I have several fields split into 2 sections (Debt & Equity) on a form
that should only take numerical values. The page is a mix of
Javascript & ASP such that when the user visits the page, the initial
values of the field are filled in by Session cookies. When the cursor
leaves a field, the code checks to see if the entry is a number, and
if it is not then it replaces it with a "0". Then it checks each field
for empty entries and when it finds one, it replaces it with an "0".
Then it totals up the entries in a sub-total and then totals up the
two sub-totals.

See the code below for details (should be self-explanatory).

The goal is to modify the code to find out if the user has entered in
a comma for one of the numbers. Ie. these are all dollar values, and
as such when someone enters in 10,000 the code resets that field to a
zero. what I'd like to do is to modify the code such that the ** check
process looks for commas in each field AND removes them ** before
number checking and blank entry checking.
Can you help me?! Thanks in advance!!!!!

yt

CURRENT CODE:

<SCRIPT LANGUAGE='JavaScript'>
<!-- // Hide from old browsers ...
function Formsubmit () {
document.frm_q2.submit();
return;
}

function Initialize() {
frm_q2.q2_debt_homeequity.value =
"<%=Session("q2_debt_homeequity")%>"; frm_q2.q2_debt_banks.value =
"<%=Session("q2_debt_banks")%>";
frm_q2.q2_debt_otherfinancial.value =
"<%=Session("q2_debt_otherfinancial")%>";
frm_q2.q2_debt_creditcards.value =
"<%=Session("q2_debt_creditcards")%>";
frm_q2.q2_debt_government.value =
"<%=Session("q2_debt_government")%>"; frm_q2.q2_debt_spouse.value
= "<%=Session("q2_debt_spouse")%>";
frm_q2.q2_debt_familyorfriends.value =
"<%=Session("q2_debt_familyorfriends")%>";
frm_q2.q2_debt_formerowners.value =
"<%=Session("q2_debt_formerowners")%>"; frm_q2.q2_debt_other.value
= "<%=Session("q2_debt_other")%>";

frm_q2.q2_equity_ownersavings.value =
"<%=Session("q2_equity_ownersavings")%>";
frm_q2.q2_equity_spouse.value =
"<%=Session("q2_equity_spouse")%>";
frm_q2.q2_equity_familyorfriends.value =
"<%=Session("q2_equity_familyorfriends")%>";
frm_q2.q2_equity_formerowners.value =
"<%=Session("q2_equity_formerowners")%>";
frm_q2.q2_equity_investors.value =
"<%=Session("q2_equity_investors")%>";
frm_q2.q2_equity_other.value = "<%=Session("q2_equity_other")%>";

DebtCheck();
EquityCheck();
}

function DebtCheck() {
if ( isNaN( frm_q2.q2_debt_homeequity.value ) )
frm_q2.q2_debt_homeequity.value = "0"; if ( isNaN(
frm_q2.q2_debt_banks.value ) ) frm_q2.q2_debt_banks.value = "0";
if ( isNaN( frm_q2.q2_debt_otherfinancial.value ) )
frm_q2.q2_debt_otherfinancial.value = "0"; if ( isNaN(
frm_q2.q2_debt_creditcards.value ) )
frm_q2.q2_debt_creditcards.value = "0"; if ( isNaN(
frm_q2.q2_debt_government.value ) )
frm_q2.q2_debt_government.value = "0"; if ( isNaN(
frm_q2.q2_debt_spouse.value ) ) frm_q2.q2_debt_spouse.value = "0";
if ( isNaN( frm_q2.q2_debt_familyorfriends.value ) )
frm_q2.q2_debt_familyorfriends.value = "0"; if ( isNaN(
frm_q2.q2_debt_formerowners.value ) )
frm_q2.q2_debt_formerowners.value = "0"; if ( isNaN(
frm_q2.q2_debt_other.value ) ) frm_q2.q2_debt_other.value = "0";

if ( frm_q2.q2_debt_homeequity.value == "" )
frm_q2.q2_debt_homeequity.value = "0"; if (
frm_q2.q2_debt_banks.value == "" ) frm_q2.q2_debt_banks.value =
"0"; if ( frm_q2.q2_debt_otherfinancial.value == "" )
frm_q2.q2_debt_otherfinancial.value = "0"; if (
frm_q2.q2_debt_creditcards.value == "" )
frm_q2.q2_debt_creditcards.value = "0"; if (
frm_q2.q2_debt_government.value == "" )
frm_q2.q2_debt_government.value = "0"; if (
frm_q2.q2_debt_spouse.value == "" ) frm_q2.q2_debt_spouse.value =
"0"; if ( frm_q2.q2_debt_familyorfriends.value == "" )
frm_q2.q2_debt_familyorfriends.value = "0"; if (
frm_q2.q2_debt_formerowners.value == "" )
frm_q2.q2_debt_formerowners.value = "0"; if (
frm_q2.q2_debt_other.value == "" ) frm_q2.q2_debt_other.value =
"0";
//alert("Please check your email details are correct before
submitting") frm_q2.q2_debt_subtotal.value = parseFloat(
frm_q2.q2_debt_homeequity.value ) + parseFloat(
frm_q2.q2_debt_banks.value ) + parseFloat(
frm_q2.q2_debt_otherfinancial.value ) + parseFloat(
frm_q2.q2_debt_creditcards.value ) + parseFloat(
frm_q2.q2_debt_government.value ) + parseFloat(
frm_q2.q2_debt_spouse.value ) + parseFloat(
frm_q2.q2_debt_familyorfriends.value ) + parseFloat(
frm_q2.q2_debt_formerowners.value ) + parseFloat(
frm_q2.q2_debt_other.value ) ;

TotalCheck();
}

function EquityCheck() {
if ( isNaN( frm_q2.q2_equity_ownersavings.value ) )
frm_q2.q2_equity_ownersavings.value = "0"; if ( isNaN(
frm_q2.q2_equity_spouse.value ) ) frm_q2.q2_equity_spouse.value =
"0"; if ( isNaN( frm_q2.q2_equity_familyorfriends.value ) )
frm_q2.q2_equity_familyorfriends.value = "0"; if ( isNaN(
frm_q2.q2_equity_formerowners.value ) )
frm_q2.q2_equity_formerowners.value = "0"; if ( isNaN(
frm_q2.q2_equity_investors.value ) )
frm_q2.q2_equity_investors.value = "0"; if ( isNaN(
frm_q2.q2_equity_other.value ) ) frm_q2.q2_equity_other.value =
"0";

if ( frm_q2.q2_equity_ownersavings.value == "" )
frm_q2.q2_equity_ownersavings.value = "0"; if (
frm_q2.q2_equity_spouse.value == "" )
frm_q2.q2_equity_spouse.value = "0"; if (
frm_q2.q2_equity_familyorfriends.value == "" )
frm_q2.q2_equity_familyorfriends.value = "0"; if (
frm_q2.q2_equity_formerowners.value == "" )
frm_q2.q2_equity_formerowners.value = "0"; if (
frm_q2.q2_equity_investors.value == "" )
frm_q2.q2_equity_investors.value = "0"; if (
frm_q2.q2_equity_other.value == "" ) frm_q2.q2_equity_other.value
= "0";
//alert("Please check your email details are correct before
submitting") frm_q2.q2_equity_subtotal.value = parseFloat(
frm_q2.q2_equity_ownersavings.value ) + parseFloat(
frm_q2.q2_equity_spouse.value ) + parseFloat(
frm_q2.q2_equity_familyorfriends.value ) + parseFloat(
frm_q2.q2_equity_formerowners.value ) + parseFloat(
frm_q2.q2_equity_investors.value ) + parseFloat(
frm_q2.q2_equity_other.value );

TotalCheck();
}

function TotalCheck() {
frm_q2.q2_total.value = parseFloat( frm_q2.q2_debt_subtotal.value
) + parseFloat( frm_q2.q2_equity_subtotal.value );
}
//-->
</SCRIPT>


Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Davide R. | last post by:
Ciao a tutti, vi spiego il mio problema Ho una pagina HTML che referenzia un CSS esterno. Ho alcuni elementi HTML che appartengolo ad una classe (chiamiamola "class1"). Avrei la necessitą,...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
3
by: Pavils Jurjans | last post by:
Hello, I am looking for some API that abstracts away all the differences in XML DOM parsers that are presnt in all supporting browsers - MSIE, Mozilla, Opera, Safari. Perhaps that is implemented...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
5
by: Alex Maghen | last post by:
I frequently find myself wanting to insert some basic client-side JavaScript functions in the page of an ASPX of mine. But I find it so frustrating that I have to actually contruct my JavaScript in...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
12
by: lorlarz | last post by:
Unobtrusive JavaScript leads to BUILDERS (e.g. drag drop activity builder) Once you totally remove JS from a web page, and learn the shortcuts and efficiencies provided by a library like...
76
by: lorlarz | last post by:
Crockford's JavaScript, The Good Parts (a book review). This shall perhaps be the world's shortest book review (for one of the world's shortests books). I like Douglas Crockford (because I am a...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.