Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I check the contents of this textbox in my php/mysql application

Posted on 2009-04-09
4
Medium Priority
?
239 Views
Last Modified: 2012-05-06
I have the attached checkbox section in my code.  Each checkbox has a value attached to it and calls the attached function which tallys everything and displays it in another textbox.  The client wanted me to add a Quantity box that will multiple anything selected by whatever the user puts in the quantity textbox.  I got that to work, but i want to check if the box is empty,and if empty, make the value 1,  or check if the value entered is a non-numeric value before it does the calculation.  I thought this would be simple, but I am too brain drained to get this working.  

I get this error in FF:
document.getElementById("Q_379") is null
[Break on this error] if (document.getElementById('Q_379').value == "")

Help please
function calc(theForm)
{
  //debugger;
  var elements = theForm.elements;
  var total = 0;
  var multiplier=1;
  var imgQty = 0;
  var imgTotal = 0;
  var photoQty = 0
  for(var i=0; i<elements.length; i++)
  {
      var element = elements[i];
  
        if(element.type == 'checkbox' && element.checked)
        {
            total += parseFloat(element.value);
        }
 
        else if(element.name=="Q_361" && element.checked)
        {
            multiplier = parseFloat(element.value);
        }
        if (document.getElementById('Q_379').value == "")
        {
        	projQtyBox = 1;
        }
        else
        {       
			projQtyBox = document.getElementById('Q_379').value;
        }
        
  document.getElementById('Q_330').value = total*multiplier*projQtyBox;
  
}
}

Open in new window

checkbox.JPG
0
Comment
Question by:justmelat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Robin earned 1600 total points
ID: 24111708
Probably because the new textbox you added does not have the id 'Q_379' but it's its name.

0
 
LVL 19

Expert Comment

by:Michael701
ID: 24112422
I hope that quantity box is large enough. Ok, just kidding, it's been one of those days.

And could you be any less descriptive with your element names?

Here's a snippet when I mulitply quantity and price of an item.
    if (isNaN(quantity))
    {
      error=1
      notes.innerHTML="Invalid quantity!"
    }
    else if (isNaN(price))
    {
      error=1
      notes.innerHTML="Invalid price!"
    }
    else
    {
    answer=quantity * price
    ....
    }

Open in new window

0
 
LVL 19

Expert Comment

by:Michael701
ID: 24112429
oh guess I should have also shown the variable definitions

  for (x=1; x<=<?PHP echo MAX_ORDER_LINES ?>; x++)
  {
    quantity=document.getElementById("quantity_"+x).value
    price=document.getElementById("price_"+x).value
    extension=document.getElementById("extension_"+x)
    notes=document.getElementById("notes_"+x)

Open in new window

0
 
LVL 1

Author Comment

by:justmelat
ID: 24117236
Ahhh, can't believe i didn't see that. thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question