0

I am trying to assign pound value for input box. I am getting error can u please help me? if i give alert means its showing the value but i cant see the input value in inputbox I have tried below code

var valchrCode = String.fromCharCode('163');
var abc = valchrCode + 30;
document.getElementById("mrp30ppm").value = abc;
alert(abc );
0

Code is working.Please check input field have id like below and jQuery library included for this particular page.

Check console if any error post in your question.

<input id="mrp30ppm" type="text" name="" />

<script type="text/javascript">// <![CDATA[
var valchrCode = String.fromCharCode('163');
var abc = valchrCode + 30;
document.getElementById("mrp30ppm").value = abc;
// ]]></script>
  • i have tried same but i cant see the value of inputbox – user5506072 Mar 4 '16 at 10:17
  • Have you check console log? any error there – Prashant Valanda Mar 4 '16 at 10:19
  • Yes, I have checked I didnt get any error – user5506072 Mar 9 '16 at 12:02
0

If your javascript code is executed before the input field is to the page you will get the null exception error.

Make you that the element exists when you use

document.getElementById("mrp30ppm").value

You can use window.onload or $(document).ready function( (if you want to use jQuery).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.