2

I am facing an issue , my inline javascript code is not added in page(Created By wordpress).

code

function check()
 {
    alert("in check");
    var mname=document.getElementByID("name").value;
    var memail=document.getElementByID("email").value;

    var mresponse=document.getElementByID("response").value
   alert("name"+mname +"length"    +mname.length+"email"+memail+"length"+memail.length+"response"+mresponse+"length"+mresponse.length);

}

</script>
<table style="border: 0px;">
 <tbody>
  <tr>
  <td style="border: 0px;">Name <span style="color: red;">*</span></td>
   <td style="border: 0px;"><input id="name" type="text" name="name" /></td>
   </tr>
   <tr>
    <td style="border: 0px;">Email-Id <span style="color: red;">*</span></td>
    <td style="border: 0px;"><input id="emailid" type="text" name="emailid" /></td>
   </tr>
   <tr>
   <td style="border: 0px;">Your Response <span style="color: red;">*</span></td>
    <td style="border: 0px;"><textarea id="response" cols="40" maxlength="50"     name="response" rows="4"></textarea></td>
   </tr>
    </tbody>
   </table>
   <input onclick="check();" type="button" value="click" />

Do i need to install any plugin for allowing java script.

P.S i am not using wordpress.com ..i am developing locally

**********Updated*****************

i just try alert box

 var mname=document.getElementById("name");
   alert("in check"+mname);

and checked in firebug got following error

SyntaxError: syntax error
alert("in check"+mname);</p>

error pointing towards that 'p'. But i did not write that code. i don`t know why this is appended in generated code?

2
  • 1
    Where have you included this code? Commented Apr 16, 2014 at 6:03
  • in html code You sre using id="emailid" but in javascript you are using getElementByID("email") why? Commented Apr 16, 2014 at 6:05

3 Answers 3

1

Use this

getElementById instead of getElementByID

use ';' after

var mresponse=document.getElementById("response").value; //forgot ';'

and use

var memail=document.getElementById("emailid").value;   //use correct id

In my system is working now.

Sign up to request clarification or add additional context in comments.

Comments

1

i tried inline javascript plugin and it works for me. You have to just add follwing tags between your js code

 [inline]
   your  js code
 [/inline] 

Comments

0

Check this video tutorial:

https://www.youtube.com/watch?v=zjNVryaNz0E

Updated

Add JS like this on your any WP Page or Post It works:

 <script type="text/javascript">
   var a = 5;
   alert("hello world. The value of a is: " + a);
 </script>

FYI :it does not required any plugin for add js into WordPress page /post

I hope this helps you!!

5 Comments

i check my generarted html in firebug...but my javascript is not added to page.
@saurabh which version of WP you are using? and also from where you are adding JS code into your page i.e using dashboard OR from any php template file?
i am using wp 3.8 and adding javascript from dashboard. but WP appending </p> before any java script code..that is why its not working..i dont know why it is not recognize js.
Okay, I guess you missing something because I have checked on same wp version 3.8.2 and its working fine, let me know you one thing that appending <p> before/after script tag will note make any problem for run the JS. can you send me the full screenshot of your dashboard where you adding script on your wp page, I need to check in which mode you are adding code to page(View/Text).
I think you should define your js function i.e check() , into any external Js and include that into the given page. then it will work absolutely fine, because I have checked your code by running on wp page. it giving the same error and its because of wp not support code indentation properly in page and add extra <p> into code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.