473,706 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing for blank input...

Me
I need to test for blank inputs and run a routine "if" the input is
blank. This will be used internally on a LAN to calculate selling price
if the "sell" input is blank and a margin is supplied, and to calculate
a margin if the margin input is blank and the sell price is supplied.
The "cost" is set and will be doled out by the CGI. I've tried checking
for a zero variable length ".length" and couldn't get it to work. It
always fires if you check for -1 even if there is something in the
input, and it never fires if you set it any higher. I'm sure I'm just
doing it wrong. Here's where I'm at:

<html>
<head>
<SCRIPT LANGUAGE="JavaS cript">
<!--HIDE
function doMath( ) {

// var one will be set by the CGI when in use

var one = eval(document.t heForm.
elements[0].value)
var two = eval(document.t heForm.
elements[1].value)
var three = eval(document.t heForm.
elements[2].value)
// Run only if sell input is blank

var margin = ((one / three) * 100)
document.theFor m.elements[1].value = margin

// Run only if sell input is blank

var sell = (one / ((100 - two) / 100))
document.theFor m.elements[2].value = sell

}
//STOP HIDING-->
</SCRIPT>
<BODY><FORM NAME="theForm">
Cost <INPUT TYPE="text"> Margin <INPUT TYPE="text"> Sell <INPUT TYPE="text">
<INPUT TYPE="button" VALUE="Calculat e"
onClick="doMath ( )">
</FORM>
</body>
</html>
Suggestions appreciated. :-)
Jul 23 '05 #1
1 1936
Me
Me wrote:
I need to test for blank inputs and run a routine "if" the input is
blank. This will be used internally on a LAN to calculate selling price
if the "sell" input is blank and a margin is supplied, and to calculate
a margin if the margin input is blank and the sell price is supplied.
The "cost" is set and will be doled out by the CGI. I've tried checking
for a zero variable length ".length" and couldn't get it to work. It
always fires if you check for -1 even if there is something in the
input, and it never fires if you set it any higher. I'm sure I'm just
doing it wrong. Here's where I'm at:


Got it. Dumb syntax problem. Here's what worked.

<html>
<head>
<SCRIPT LANGUAGE="JavaS cript">

function doMath( ) {
var one = eval(document.t heForm.elements[0].value)
var two = eval(document.t heForm.elements[1].value)
var three = eval(document.t heForm.elements[2].value)
// Run only if margin input is blank

if (document.theFo rm.elements[1].value.length== 0){
var margin = (100 - ((one / three) * 100));
document.theFor m.elements[1].value = margin
}

// Run only if sell input is blank

if (document.theFo rm.elements[2].value.length== 0){
var sell = (one / ((100 - two) / 100));
document.theFor m.elements[2].value = sell
}

}

</SCRIPT>
</head>

<BODY>

<FORM NAME="theForm">
Cost <INPUT TYPE="text"> Margin <INPUT TYPE="text"> Sell <INPUT TYPE="text">
<INPUT TYPE="button" VALUE="Calculat e" onClick="doMath ( )">
</FORM>

</body>
</html>
Jul 23 '05 #2

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

Similar topics

12
3282
by: dan glenn | last post by:
Hi. I'm finding that if I have text entered into a <textarea ...> </textarea> in a form, and that text has leading blank lines (with no spaces or anything else), that when I retrieve the entered text, I lose the leading blank line. Each time it goes through a post any top-leading blank line is lost. Only one- if I have several blank lines in a row at the top, only the first is lost. (If the top blank line has a single space, it's handled...
7
3234
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically generated, though. I'd like to capture the NAME of every HTML form field element on the server, even if that element is submitted blank. The trouble is, with, say, radio buttons or checkboxes for example, a *blank* element does not get submitted at all.
1
5550
by: Monte Chan | last post by:
Hi all, I have the following codes, <script language="JavaScript"> function check_stuff(field) { alert("blank out the field now"); field.value = ""; } </script>
14
2745
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
5
10184
by: JackRazz | last post by:
Anyone know the regular expression to match a blank line where the byte sequence is "0D 0A 0D 0A" ive tried "\r\n\r\n+", "^$+" "\n\r" with no success. Any Ideas? Thanks - JackRazz This is the code fragment I'm trying Dim r As Regex, m As Match, i As Integer
72
5252
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
2
1383
by: Jake Barnes | last post by:
At a certain point in my code, I need to blank the value in a file input. The situation comes up when a user first thinks they want to upload something from their harddrive, but then they change their mind and decide to choose a file from an online archive. I thought I could get a reference to the input and then set value to blank, but that only works in FireFox. For IE, I only got this to work by setting innerHTML to blank: if...
4
2176
by: fish | last post by:
Consider this page: http://college.hmco.com/esl/vestri_solomon/top20/1e/students/exercises/unit16/exe03.html A user is asked to select a relative pronoun from a drop down list, and, if all the blanks are correct, they will be moved to the next question. Currently, if the user gets the first blank correct, any of the following answers, right or wrong, are accepted. The code is old, this much I know. As far as I can see, it's failling...
2
4394
by: UofFprogrammer | last post by:
I am experimenting with several ways to test for the end of file for an input file .txt If, for example, I have a text (test.txt) file that had: ab 5 fgd 3 fdfe 3 aasa 4 (intentionally blank line) where the first input is a character array and the second is an integer value.
0
8695
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9154
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8987
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7900
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5937
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4708
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3142
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2499
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.