Issue: I have a statement if Master$ <> 0 then they can't enter an input$. else they can enter input$. The only thing is...I can't force a user to always have input$, they may or may not. So....right now, I'd like to have a check if TotalQty >0 and Master$ = 0 then check input$, if input$ is 0 then prompt enter amt.
but in order to look at TotalQty I need javascript to sum on the fly as numbers are entered in 1Q, 2Q, 3Q, 4Q...how should I go about this?
right now if i edit and enter qty's and master$ is $0 and I don't enter an Input$...then all my calculations stay at $0.
....if they enter qty and master is $0 then must something in Input$.
Rebelle, July 24th, 2009 01:54 PM
Last edited by Rebelle; July 24th, 2009 at 02:04 PM.
This can be done. I had a javascript that basically did a sum across columns and down rows as numbers were entered. It's really fun (sorry, it was for a previous company, so I don't have it any more).
- Are your input fields in an HTML table; so it looks like a spreadsheet?
- If so, name your text boxes so you can locate them by name, such as ID="TB_01_04" would be Row 1 Column 4
- Create the javascript and execute it as the onblur event for every input text box.
- In the JS either sum across the row or down the column or both and then set the value of the approprate total text box.
Clear as mud?
Wolffy, July 24th, 2009 03:08 PM
Wolffy
.-- ----- ..-. ..-. -.-- Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.
anyh00t....
ok, yes i have in table like attachment.
first 4 fields are inputs for Qtrs...then is a Total Qty across but this only populates after saving right now...then it either see if Master$ (in blue) OR field(input$-if master is $0) and takes that x QtrQty's and then by x TotalQtry. this again, only after save is hit.
so is it better to go this route, once user inputs qty, onblur the total qty and then check if master$ is $0 and prompt user to input $? just trying to think of the best way or how this should be handled...
After looking at your screen shot, I'm gong to revise how I would do this. Basically, you are wanting to validate the form on submit to ensure that all input$ text boxed have a value greater then 0, and if not, scold the user and not submit the form.
Create an onSubmit javascript event handler. If you name all your input$ text boxes with the same name, then you can do a document.getElementsByName("input$") to return a collection of the input$ text boxes. Loop through the collection and check the value and if you find an input$ text box without a valid value, take the approriate action and return false to cancel the submit.
The "appropriate action" could be just about anything. Consider putting a hidden text field right next to each input$ text box with a ! (or some other glyph) as its value. Then, when your loop finds an invalid input$, make the !-glyph unhidden again. The trick part here is finding the !-glyph for the text box in error. If the text box and the !-glyph are in the same <td> node, then you should be able to locate the <td> node using the .parentNode method on the text box. Its a bit of work, but would look slick (and is pretty much now ASP.NET does its validation).
A little bit less work would be to change the background color of the errant text box to red, or some other gosh offal color.
Wolffy, July 24th, 2009 06:02 PM
Last edited by Wolffy; July 24th, 2009 at 06:11 PM.
Wolffy
.-- ----- ..-. ..-. -.-- Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.
Bookmarks