JavaScript How to link the html button to php? link html button to javascript function,link html button to

how do I connect the button (which is in HTML page) to connect to php url, once the ON/OFF button is clicked. the code basically have to call the php once the button is clicked and when the php is called it need register the ON/OFF to my database along with starting time. can please anyone help me out with this code because i'm new and really stuck. this thing needs to work without javascript or jquery stuff.

http://i.stack.imgur.com/8JAYn.jpg

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <style>
    h1 {
        padding-top: 50px;
        text-align: center;
        color: white;
        margin-right:60px;
    }
    </style>
        <title> Washing Machine Control System</title>
        <link rel="stylesheet" type="text/css" target='_blank' href="BK.css"/>
        <link rel="stylesheet" type="text/css" target='_blank' href="MachineButtons.css"/>
        <script src="http://code.jquery.com-1.11.3.min.js"></script>

    </head>

    <body bgcolor = "Black"> 


    <h1>Machine Controller</h1>

        <br></br>
        <br></br>


    <div id="icons"><img src="D:\Year 4 (Sem1&2)\Mobile Technologies\Coursework\Website\WM1.jpg"  alt="Machine One" style="width:150px;height:228px;"/></a></div>

            <label class="switch">
                <input class="switch-input" type="checkbox" />
                <span class="switch-label" data-on="M1 On" data-off="M1 Off"></span> <span class="switch-handle"></span> 
            </label>

    <div id="icons2"><img src="D:\Year 4 (Sem1&2)\Mobile Technologies\Coursework\Website\WM2.jpg" alt="Machine Two" style="width:150px;height:228px;"/></a></div>

            <label class="switch">
                <input class="switch-input" type="checkbox" />
                <span class="switch-label" data-on="M2 On" data-off="M2 Off"></span> <span class="switch-handle"></span> 
            </label>

    <div id="icons4"><img src="D:\Year 4 (Sem1&2)\Mobile Technologies\Coursework\Website\WM3.jpg"  alt="Machine Three" style="width:150px;height:228px;"/></a></div>
            <label class="switch">
                <input class="switch-input" type="checkbox" />
                <span class="switch-label" data-on="M3 On" data-off="M3 Off"></span> <span class="switch-handle"></span> 
            </label>

    <div id="icons3"><img src="D:\Year 4 (Sem1&2)\Mobile Technologies\Coursework\Website\WM4.jpg" alt="Machine Four" style="width:150px;height:228px;"/></a></div>

            <label class="switch">
                <input class="switch-input" type="checkbox" />
                <span class="switch-label" data-on="M4 On" data-off="M4 Off"></span> <span class="switch-handle"></span> 
            </label>

    </body>
    </html>
Answer:1

I think you're going to have to solve this in stages.

If you're trying to get the HTML field values to connect to a database via PHP, you'll need to look at your HTML mark up first, as it's not prepared enough to achieve this. Input elements need to sit within form elements in order to initiate a PHP write-to or callback from a database. For example;

<form method="GET/POST" action="theNameOfYourPHPFile.php">
  <input class="switch-input" type="checkbox" name="washingMachine1" />
<input class="switch-input" type="checkbox" name="washingMachine2" />

etc...

Once you've got this all in place, you'll then be able to access the values in the inputs using your php functions in the php file you're pointing the form to. Accessing their on/off values via this

<?php $washingMachine1 = $_REQUEST['washingMachine1']; 
etc... 

?>

But you'll need more PHP coding practice to take this further. Worth spending some time to learn more about forms and their interaction with PHP via GET and POST methods. Good luck.

Answer:2

there is two way to call a php file from button using form submit and another is submit a form using ajax.

<form action='url of php file' method="post or get" ..... .... </form>

on submit button click form is submited to define by action.

another way

use simple button and on click of button using ajax call a php file without redirect

Answer:3

Use a before the input fields or the values you want to send and add the php page to which you want to send the input field values in form action and in that php page write the insert query according to your needs. eg:

Answer:4

When dynamically changing content within a div is there a way of delaying the display of the new content until all layout is complete? I am using javascript and ajax to update the contents of a div ...

When dynamically changing content within a div is there a way of delaying the display of the new content until all layout is complete? I am using javascript and ajax to update the contents of a div ...

I am trying to filter out all objects based on a string attribute like this: var data = $.parseJSON(valid_json); data = data.filter(function (el) { return (el.name == 'myName'); }); This returns ...

I am trying to filter out all objects based on a string attribute like this: var data = $.parseJSON(valid_json); data = data.filter(function (el) { return (el.name == 'myName'); }); This returns ...

  1. filter json string c#
  2. filter json string
  3. filter json string java
  4. filter json string javascript
  5. filter json string python
  6. filter json string jquery
  7. json filter string contains
  8. php filter json string
  9. filter json query string

I'm trying to divide 100 by a number, so I get the percentage of that number to put in a variable that is into a FOR ... and that FOR put the percentage inside an Array ... More or less This: var ...

I'm trying to divide 100 by a number, so I get the percentage of that number to put in a variable that is into a FOR ... and that FOR put the percentage inside an Array ... More or less This: var ...

  1. divide whole number javascript
  2. divide number using javascript
  3. divide number with string javascript
  4. javascript divide number into equal parts
  5. javascript divide number into array
  6. javascript divide number by 2
  7. javascript divide number integer
  8. javascript divide number into parts
  9. divide two numbers in javascript
  10. javascript divide number in array
  11. javascript divide number decimals

I have a single page html code with 3 different Tabs in that.I have a requirement of chaining the URL for each tab. I have seen some resources for changing the browser history using windows.history....

I have a single page html code with 3 different Tabs in that.I have a requirement of chaining the URL for each tab. I have seen some resources for changing the browser history using windows.history....

  1. windows change password every 90 days
  2. change picture every windows 10
  3. windows change password every month
  4. windows change picture every