PDA

View Full Version : hopefully a simple solution?


ojoonline
10-10-2005, 12:07 AM
hi,

I found this script here on the forum and was hoping someone could help me modify it??

It's perfect except for my use, except i would like it to count the spaces too.


<script language="JavaScript" type="text/javascript">
<!--

function Calculate(obj,m,opid){
nu=obj.value.replace(/\s/g,'').length;
document.getElementById(opid).value='£'+(nu*m).toFixed(2);
}
//-->
</script></head>

<body>
<input id="ip" size="10" onkeyup="Calculate(this,1.6,'op');" onblur="Calculate(this,1.6,'op');"><br>
<input id="op" size="10"><br>


thanks!!

jo

nikkiH
10-10-2005, 09:16 PM
Just take out the line that removes the spaces and count the object value instead.

nu=obj.value.replace(/\s/g,'').length;
remove that line

document.getElementById(opid).value='£'+(obj.value*m).toFixed(2);
Change that line to above.

ojoonline
10-15-2005, 01:07 AM
thanks Nikki. Now I need to be able to remove line breaks and tabs in the text that is input in the textarea.

Can someone show me how this is done?

thanks, jo

nikkiH
10-17-2005, 01:55 PM
Same way. Just change the expression in the replace.

ojoonline
10-18-2005, 08:05 AM
thanks. Can you help me with the syntax? I'm not sure of how to have two things to replace and also the regular expression?

much appreciated!

jo

Philip M
10-18-2005, 06:53 PM
nu=obj.value.replace(/\n\t/gi,'');

i.e replace newlines and horizontal tabs by nothing.