8 Replies - 1958 Views - Last Post: 14 August 2012 - 06:22 AM

#1 adolf625  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 161
  • Joined: 22-November 08

Run Update Query as soon as Radio Button is selected

Posted 08 August 2012 - 01:51 PM

I am working on an inventory program and I need the status of the inventory to update just by selecting the radio button. Is there a way to do this without having to use a submit button? I need the query to run as soon as the radio button is checked.
Is This A Good Question/Topic? 0
  • +

Replies To: Run Update Query as soon as Radio Button is selected

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,083
  • Joined: 18-April 07

Re: Run Update Query as soon as Radio Button is selected

Posted 08 August 2012 - 04:13 PM

You can do that with an AJAX call to a PHP script that will run the update for you. What you are describing is a piece of functionality that is client side and out of the scope of PHP itself. If you ask the folks over in the Javascript forum I am sure they can show you how you can use jQuery or some other Javascript framework to make this sort of thing effortless.

:)
Was This Post Helpful? 1
  • +
  • -

#3 adolf625  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 161
  • Joined: 22-November 08

Re: Run Update Query as soon as Radio Button is selected

Posted 08 August 2012 - 04:31 PM

Ok thanks I will post it over there and see if they can give me an idea on how to do it.
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,276
  • Joined: 28-March 11

Re: Run Update Query as soon as Radio Button is selected

Posted 08 August 2012 - 05:12 PM

Lets merge both of your topics...
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Run Update Query as soon as Radio Button is selected

Posted 08 August 2012 - 06:11 PM

Give your radio button (although I would argue this is the wrong UI element for the functionality, should be an actual button) an ID or unique class name.

Use a jQuery selector for the ID or class to attach a click event handler to the element which uses jQuery.post() to post to the PHP page which performs the update.
Was This Post Helpful? 1
  • +
  • -

#6 adolf625  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 161
  • Joined: 22-November 08

Re: Run Update Query as soon as Radio Button is selected

Posted 09 August 2012 - 08:52 AM

Ok here is what I got so far, but I am having trouble passing the values to the php file, does this look right or am I missing something

			
<script language="javascript">
            	function update(sys_status, my_system){
					$.post("updateStatus.php",
                	{ status: "sys_status", system: "my_system" }, function(data){alert("Data Loaded: " + sys_status); });	
				}
            </script>	
                
                
             <li style='line-height: 150%'> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" id="status">
             	<label title="Set Status" for="setStatus" accesskey="p">Set Status: </label>
                
                <input type="radio" name="status" id="status"  value="w" onclick="update('w', <?php echo $strHW_Asset;?>)"/>In Use&nbsp;
                <input type="radio" name="status" id="status"  value="i" onclick="update('i', <?php echo $strHW_Asset;?>)"/>Inactive&nbsp;
                <input type="radio" name="status" id="status"  value="n" onclick="update('n', <?php echo $strHW_Asset;?>)"/>Destroyed
                <input type="hidden" name="statusID" value="true" />
            </form>

This post has been edited by adolf625: 09 August 2012 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Run Update Query as soon as Radio Button is selected

Posted 09 August 2012 - 02:34 PM

Well the next step in debugging would be to see what the value of the $_POST data received by updateStatus.php is.
Was This Post Helpful? 0
  • +
  • -

#8 adolf625  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 161
  • Joined: 22-November 08

Re: Run Update Query as soon as Radio Button is selected

Posted 14 August 2012 - 05:31 AM

Whenever the data is fed back in the alert box it is coming back empty, do I actually need to read the data in with a function call like I have done or am I going about that wrong?
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Run Update Query as soon as Radio Button is selected

Posted 14 August 2012 - 06:22 AM

Look at the documentation, particularly the examples and take notice of what they're doing when they do something with what comes back to the server.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1