1

For the below text box:

<input type="text" style="" onkeypress="javascript:doit_onkeypress(event);" />

this script is working fine.

<script type="text/javascript">
  function doit_onkeypress(event){
    if (event.keyCode == 13 || event.which == 13){
      // here my action works
    }
  }
</script>

But my problem is images (instead of text area) are creating dynamically.

i am trying to execute same as

<input type="text" style="" onkeypress="  <script type="text/javascript">
  function doit_onkeypress(event) {
    if (event.keyCode == 13 || event.which == 13) {
      // here my action works
    }
  }
 </script>" />

is it possible as above with modifications?

why because for dynamically generating images i can't write java script on key press actions for every image. every image the action url is different.

5
  • <input type="text" style="" onkeypress="<script type="text/javascript"> function doit_onkeypress(event){ if (event.keyCode == 13 || event.which == 13){ here my action works } } </script> " /> is it possible? Commented Mar 17, 2016 at 8:59
  • Try to use addEventListener instead. Commented Mar 17, 2016 at 9:02
  • Why you do not use first code, where is the problem in first ? Commented Mar 17, 2016 at 9:08
  • My images are generating dynamically. for every image onkeypress we have to hit diff urls. Commented Mar 17, 2016 at 9:11
  • Can you show your code where you create those images? Commented Mar 17, 2016 at 9:23

2 Answers 2

1

You can pass target with the doit_onkeypress() method and make only one keypress method. From target, you can get your actionURL.

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

Comments

0

There can be only js code inside onkeypress= value.

You cannot paste html code such as <script> there.

There is not enought info about dynamic images part to help further.

Comments

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.