IT Community - Software Programming, Web Development and Technical Support

Calculations and other Operations on Field Values

This is a discussion on Calculations and other Operations on Field Values within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... Can anyone discuss briefly about the Calculations and other Operations on Field Values. Thanks & Regards P.vinothkumar...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 10-19-2007, 03:15 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Calculations and other Operations on Field Values

Hi all...


Can anyone discuss briefly about the Calculations and other Operations on Field Values.

Thanks & Regards
P.vinothkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-19-2007, 03:17 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...


How do I sum form field values together?

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-19-2007, 03:21 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How do I sum form field values together?

Hi all...


var a = '1';
var b = '2';

var c = a + b;

Or This:

var a = '1';
var b = '2';

var c = (a-0) + (b-0);

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-19-2007, 03:39 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...

How do I add form elements together, I have tried many different ways but I always either get NaN or a concenated string (ie 15 + 16 + 1 + 52 = 1615152 != 84)?

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-19-2007, 03:41 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How do I add form elements together

Hi all...

How do I add form elements together, I have tried many different ways but I always either get NaN or a concenated string (ie 15 + 16 + 1 + 52 = 1615152 != 84)?

<form>
<input type="text" name="field1" value="15">
<input type="text" name="field2" value="16">
<input type="text" name="field3" value="1">
<input type="text" name="field4" value="52">
<input type="button" value="Sum" onClick="sum(this.form)">
</form>

<script language="JavaScript"><!--
function sum(objRef) {
var result = 0;
result =+ objRef.field1.value - 0;
result =+ objRef.field2.value - 0;
result =+ objRef.field3.value - 0;
result =+ objRef.field4.value - 0;
alert(result);
}
//--></script>

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-19-2007, 03:44 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all....

How do you sort a number of lines of information in a textarea?

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-19-2007, 04:41 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How do you sort a number of lines of information in a textarea?

Hi all....


<script language="JavaScript"><!--
var splitIndex = 0;
var splitArray = new Array();

function splits(string,text) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return;

var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return;
if (i == -1) {
splitArray[splitIndex++] = string;
return;
}

splitArray[splitIndex++] = string.substring(0,i);

if (i+txtLength < strLength)
splits(string.substring(i+txtLength,strLength),tex t);

return;
}

function split(string,text) {
splitIndex = 0;
splits(string,text);
}

function join(arrayName) {
var temp = '';
for (var i=0; i<splitIndex; i++)
temp += arrayName[i] + '\n';
if (escape(temp.substring(0,1)) == '%0A')
return temp.substring(1,temp.length);
else
return temp;
}

function sort(arrayName) {
for (var i=0; i<(splitIndex-1); i++)
for (var j=i+1; j<splitIndex; j++)
if (arrayName[j] < arrayName[i]) {
var dummy = arrayName[i];
arrayName[i] = arrayName[j];
arrayName[j] = dummy;
}
}

function sorttext() {
split(document.myform.mytext.value,'\n');
sort(splitArray);
document.myform.mytext.value = join(splitArray);
}
//--></script>

<script language="JavaScript1.1"><!--
function split(string,text) {
splitArray = string.split(text);
splitIndex = splitArray.length;
}
//--></script>


<form name="myform">
<textarea name="mytext" rows="9" cols="8">
Lion
Tiger
Bear
Fox
Rabbit
Anteater
Snake
Dog
Cat
</textarea>
<p><input type="button" value="sort" onClick="sorttext()">
</form>

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-19-2007, 04:44 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...

How can I extract just the file name from a forms file upload field?

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 10-19-2007, 04:47 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How can I extract just the file name from a forms file upload field?

Hi all...


<script language="JavaScript"><!--
function extract(what) {
if (what.indexOf('/') > -1)
answer = what.substring(what.lastIndexOf('/')+1,what.length);
else
answer = what.substring(what.lastIndexOf('\\')+1,what.lengt h);
alert(answer);
}
//--></script>

<form name="myform">
<input type="file" name="myfile">
<input type="button" value="Test" onClick="extract(this.form.myfile.value)">
</form>

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 10-19-2007, 04:50 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...


How do I capture a character that is typed into a textarea and change it to another character?


Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 10-19-2007, 04:54 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How do I capture a character that is typed into a textarea and change it to another

Hi all...

How do I capture a character that is typed into a textarea and change it to another character?


<SCRIPT LANGUAGE="JavaScript"><!--
function replace(string,text,by) {
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;

var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;

var newstr = string.substring(0,i) + by;

if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),te xt,by);

return newstr;
}
//--></SCRIPT>

<FORM NAME="myForm">
<TEXTAREA COLS="20" ROWS="10" onChange="this.value=replace(this.value,'x','y')"> </TEXTAREA>
</FORM>

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 10-19-2007, 04:58 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...


How do I make two dropdown menus, where the result of the selection of both dropdown menus will be shown in a text field?


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 10-19-2007, 05:00 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How do I make two dropdown menus, where the result of the selection of both dropdown

Hi all...


How do I make two dropdown menus, where the result of the selection of both dropdown menus will be shown in a text field?


<SCRIPT LANGUAGE="JavaScript"><!--
function updateTextField() {
document.form3.result.value =
document.form1.select1.options[document.form1.select1.selectedIndex].value + ' ' +
document.form2.select2.options[document.form2.select2.selectedIndex].value
}
//--></SCRIPT>

<FORM NAME="form1">
<SELECT NAME="select1" onChange="updateTextField()">
<OPTION VALUE="0">Zero
<OPTION VALUE="1">One
<OPTION VALUE="2">Two
<OPTION VALUE="3">Three
<OPTION VALUE="4">Four
<OPTION VALUE="5">Five
<OPTION VALUE="6">Six
</SELECT>
</FORM>

<FORM NAME="form2">
<SELECT NAME="select2" onChange="updateTextField()">
<OPTION VALUE="Zero">0
<OPTION VALUE="One">1
<OPTION VALUE="Two">2
<OPTION VALUE="Three">3
<OPTION VALUE="Four">4
<OPTION VALUE="Five">5
<OPTION VALUE="Six">6
</SELECT>
</FORM>

<FORM NAME="form3">
<INPUT TYPE="TEXT" NAME="result">
</FORM>

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 10-19-2007, 05:02 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...


How can I compare two selected items from two different select form fields?


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 10-19-2007, 05:04 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How can I compare two selected items from two different select form fields?

Hi all...


<SCRIPT LANGUAGE="JavaScript"><!--
function test(what) {
if (what.select1.options[what.select1.selectedIndex].value == what.select2.options[what.select2.selectedIndex].value)
alert('They are the same');
}
--></SCRIPT>

<FORM NAME="myForm">

<SELECT NAME="select1">
<OPTION VALUE="abc">123
<OPTION VALUE="def">456
<OPTION VALUE="ghi">789
</SELECT>


<SELECT NAME="select2">
<OPTION VALUE="abc">123
<OPTION VALUE="def">456
<OPTION VALUE="ghi">789
</SELECT>

<INPUT TYPE="BUTTON" VALUE="SUBMIT" onClick="test(this.form)">

</FORM>

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 10-19-2007, 05:06 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all....


How can I constantly check to see if and when the user has entered a specific word in a text box?


Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 10-19-2007, 05:09 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How can I constantly check to see if and when the user has entered a specific word

Hi all...


How can I constantly check to see if and when the user has entered a specific word in a text box?


<FORM NAME="myForm">
<INPUT TYPE="TEXT" NAME="myText">
</FORM>

<SCRIPT LANGUAGE="JavaScript"><!--
function monitorText() {
if (document.myForm.myText.value.indexOf('skip') > -1)
alert('detected skip');
else
setTimer('monitorText()',1000); // checks field every 1000 milliseconds
}

monitorText();
//--></SCRIPT>


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 10-19-2007, 05:11 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all...


How can you remove space from a text field?

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 10-19-2007, 05:14 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default How can you remove space from a text field?

Hi all....


<SCRIPT LANGUAGE="JavaScript"><!--
function replace(string,text,by) {
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;

var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;

var newstr = string.substring(0,i) + by;

if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),te xt,by);

return newstr;
}
//--></SCRIPT>

<FORM>
<INPUT NAME="myField" TYPE="TEXT" VALUE="1 2 3 4 5 6 7 8 9 0">
<INPUT TYPE="BUTTON" VALUE="Remove Spaces" onClick="this.form.myField.value=replace(this.form .myField.value,' ','')">
</FORM>

Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 10-19-2007, 05:16 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Calculations and other Operations on Field Values

Hi all....


How can I add up the values in several text fields and place the result in another text field?


Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/html-css-javascript-coding-techniques/4128-calculations-other-operations-field-values.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 10-19-2007 04:29 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
erroneous results for certain mathematical calculations aramesh Flash Actionscript Programming 1 04-03-2008 03:00 AM
String Operations using different databases srikumar_l Database Support 0 12-05-2007 03:27 AM
Date Operations in different databases srikumar_l Database Support 3 12-04-2007 07:59 AM
Setting Field Values Pvinothkumar HTML, CSS and Javascript Coding Techniques 14 11-16-2007 05:27 AM
How can I clear the form field values after the user has submitted the form for clien itbarota HTML, CSS and Javascript Coding Techniques 1 11-01-2007 11:39 PM


All times are GMT -7. The time now is 11:30 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.