Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › HTML form needing variables
New Posts  All Forums:Forum Nav:

HTML form needing variables

post #1 of 4
Thread Starter 
Hello again,

I am still working on the project I posted about a couple weeks ago. I'm at the point now where I need to apply a mathematical formula from multiple entries on an HTML form that saves the data to a MySQL database via PHP.

There is no PHP code in the form, all data is saved to the database using the submit to execute PHP script.

I want this to redo the formula each time any of the numerical values in the form change or a if one of 15 checkboxes change. I imagine Javascript is the best way to go to do this using onChange. My question is, how can I assign HTML textbox values to a variable and also set a variable if any of the 15 checkboxes are checked or unchecked? I imagine I'm going to have to use PHP in the HTML form?

Thanks in advance
Speedy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 EX58-UD4P NVIDIA GeForce GTX 285 Corsair  
Hard DriveCoolingOSMonitor
Seagate Barracuda CM Hyper 212+ Ubuntu 12.04 w/KDE 25.6" Hanns-G 
KeyboardPowerCaseMouse
Saitek Eclipse II Corsair 750 Watt Antec 902 Logitech Wireless Trackball 
  hide details  
Reply
Speedy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 EX58-UD4P NVIDIA GeForce GTX 285 Corsair  
Hard DriveCoolingOSMonitor
Seagate Barracuda CM Hyper 212+ Ubuntu 12.04 w/KDE 25.6" Hanns-G 
KeyboardPowerCaseMouse
Saitek Eclipse II Corsair 750 Watt Antec 902 Logitech Wireless Trackball 
  hide details  
Reply
post #2 of 4
to determine if a checkbox is checked or not in javascript you can use soemthing like
Code:
function blablabla(checkbox) {
       if( checkbox.checked)
//say hi
       else
//say bye
    }

as for the textbox, I don't quite understand what you want. You can either get them on another page through POST, for example, or in the same page using javascript and the textbox's ID.
Code:
function blabla2(textboxID){
   document.getElementById(textboxID).//doSomethingHere
}
post #3 of 4
Thread Starter 
i'm working with about 50 text boxes that will be potentially have data, do i need to do a function for every textbox and checkbox?
Speedy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 EX58-UD4P NVIDIA GeForce GTX 285 Corsair  
Hard DriveCoolingOSMonitor
Seagate Barracuda CM Hyper 212+ Ubuntu 12.04 w/KDE 25.6" Hanns-G 
KeyboardPowerCaseMouse
Saitek Eclipse II Corsair 750 Watt Antec 902 Logitech Wireless Trackball 
  hide details  
Reply
Speedy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7 920 EX58-UD4P NVIDIA GeForce GTX 285 Corsair  
Hard DriveCoolingOSMonitor
Seagate Barracuda CM Hyper 212+ Ubuntu 12.04 w/KDE 25.6" Hanns-G 
KeyboardPowerCaseMouse
Saitek Eclipse II Corsair 750 Watt Antec 902 Logitech Wireless Trackball 
  hide details  
Reply
post #4 of 4
This definitely depends on what you want to do with that data.

But I would say if it's a similar thing for each one, you can always put it inside a single function. Maybe requires a little more work to do so, but doable.

By the way, you could loop through them like:
Code:
function blabla2(textboxID){
   document.getElementById(textboxID+"1").//doSomethingHere
   document.getElementById(textboxID+"2").//doSomethingHere
}

Or parse the element to the function using this when you call it, like:
Code:
/*html code in here*/value="checkbox" onClick="javascriptFunction(this);" /*html code in here*/
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › HTML form needing variables