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...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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.... |
| |||
| 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.... |
| |||
| 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.... |
| |||
| 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... |
| |||
| 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... |
| |||
| 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... |
| |||
| 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.... |
| |||
| 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... |
| |||
| 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.... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |