Title: How to connect HTML form and javascript?
Last modified: August 30, 2016

---

# How to connect HTML form and javascript?

 *  [StaffanS](https://wordpress.org/support/users/staffans/)
 * (@staffans)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/how-to-connect-html-form-and-javascript/)
 * I have very little knowledge about HTML, PHP and CSS and no knowledge about javascript.
   
   I got some code for a calculator from a friends site. That site is coded by her.
   The code consists both of javascript and PHP in a scriptfile and a HTML form 
   in the database. You can put some numbers in the form, push a button and then
   get an answer after some javascript calculation. I installed CSS & Javascript
   Toolbox (free version) and hoped it would help me, but it seems like if there
   is no possibility to get a connection between javascript and HTML form. I can’t
   find any plugin with a description which says it has the features I want. How
   can I connect the HTML form and javascript on a wordpress site with my little
   knowledge in coding?
 * This is the site where it works: [http://friluftsnett.net/index.php?lang=no&side=regn-ut-effektiv-temperatur](http://friluftsnett.net/index.php?lang=no&side=regn-ut-effektiv-temperatur)
   
   This is my site: [http://staffansandberg.se/friluftsliv/friluftstips/allmanna-friluftstips/rakna-ut-vindens-kyleffekt/](http://staffansandberg.se/friluftsliv/friluftstips/allmanna-friluftstips/rakna-ut-vindens-kyleffekt/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [kjodle](https://wordpress.org/support/users/kjodle/)
 * (@kjodle)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/how-to-connect-html-form-and-javascript/#post-6587020)
 * Look at the source code of your two sites and compare.
 * For example, you friend’s site has this code for the first button:
 * `<input name="calc" class="regnut1" value="Konverter til effektiv temperatur 
   >" type="button" onClick="EffektivTemp(this.form)">`
 * and your site has this code for the same button:
 * `<input class="regnut1" name="calc" type="button" value="Konvertera till effektiv
   temperatur >" />`
 * her “onClick” action is what is telling the page to fire that JavaScript code.
 * Additionally, because her site is a non-WordPress site, she included the JavaScript
   in the `<head>` of her document. Since you are using WordPress, you will either
   need a child theme or a plugin to add that code to your page’s `<head>` element.
   On her site, it’s the line that starts with:
 *     ```
       <script language="JavaScript">
       function EffektivTemp(form)	{
       ```
   
 * and ends with:
 *     ```
       form.Degsvar.value = Math.round(svar*10)/10;
       }
       </script>
       ```
   
 * (Additionally, both your site and her site are coded as HTML5, so using an `onClick`
   is a really bad idea. It will work, but it’s not the proper way to do things.)
 *  Thread Starter [StaffanS](https://wordpress.org/support/users/staffans/)
 * (@staffans)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/how-to-connect-html-form-and-javascript/#post-6587080)
 * Thanks.
    I thought I got it from the database where the page was stored, now 
   I copied from the code I get when I visit her page. It’s still something wrong,
   the button does not appear on the page and the answer square get the text for
   the button. I used CSS & Javascript Toolbox to include the script in the header.
   I have to take a look at how to do this without onClick, but a go for this solution
   in the beginning if that should work.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to connect HTML form and javascript?’ is closed to new replies.

## Tags

 * [html form](https://wordpress.org/support/topic-tag/html-form/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [StaffanS](https://wordpress.org/support/users/staffans/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/how-to-connect-html-form-and-javascript/#post-6587080)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
