[Solved] return javascript function in JSP form [closed]


It seems like you’re confused about a basic part of html, and programming languages in general: Contexts. html is constructed out of tags. A tag may contain attributes, which may have a value.

In a tree-like form:

tag
 | attribute = value
 | attribute
tag
 | attribute = value
tag
tag
 | attribute
...

Or more concretely:

<input type="password" hidden />
<img src="https://stackoverflow.com/questions/23348596/goat.png" />
<div>Blah</div>

When the browser (and you) go over a tag and try to understand it, it expects certain characters. it knows that < starts a tag, that > ends it, that after the < comes the tag name, and so forth. Going over some text and extracting meaning is called “parsing”, and the rules you follow are called “grammar”.

In our example above, the browser sees <input type="password" hidden />, and can break it down into the following:

<input type="password" hidden />
       ^-------------^ ^----^
          attr=value    attr
^------------------------------^
              tag

The html grammar does not allow you to specify a tag within an attribute’s value. It just treats it like a regular value.

<input type="password" value="<div>blah</div>" />
       ^-------------^ ^---------------------^
          attr=value          attr=value
^-----------------------------------------------^
                       tag

When you think about it, it makes much more sense: What does it mean for a value to be a tag? What does value="<div>blah</div>" do? How do you make sense of it?

So we reach our problem: html is static, but you want to change it dynamically. Enter javascript and the DOM (Document Object Model):

var input = magically_get_the_input_element();
input.value = get_deviceprint();

The DOM is the result of parsing the html into objects you can interact with using javascript. That means that you can manipulate a page, which is exactly what you want. It’s a big topic, and I won’t endeavour to cover it in here, but here are some pointers to where you can learn about javascript and the DOM:

3

solved return javascript function in JSP form [closed]