How to write inline javascript in wordpress page - Stack Overflow

I am facing an issue , my inlinejavascript code isnotadded in page(Created By wordpress). codefun

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 ..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?

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. ..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?

Share Improve this question edited Apr 16, 2014 at 6:41 sar asked Apr 16, 2014 at 6:00 sarsar 1,2974 gold badges24 silver badges51 bronze badges 2
  • 1 Where have you included this code? – Amit Garg Commented Apr 16, 2014 at 6:03
  • in html code You sre using id="emailid" but in javascript you are using getElementByID("email") why? – Himanshu Commented Apr 16, 2014 at 6:05
Add a ment  | 

3 Answers 3

Reset to default 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.

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] 

Check this video tutorial:

https://www.youtube./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!!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745321628a4622469.html

相关推荐

  • How to write inline javascript in wordpress page - Stack Overflow

    I am facing an issue , my inlinejavascript code isnotadded in page(Created By wordpress). codefun

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信