add more than one name to the form

Asked

Viewed 49 times

2

I have the following problem, I have a image map, where by clicking on the coordinates the result appears inside a <input type="text" />, but I can only name one of the clicked coordinates.

I would like to know how to insert more than one coordinated name within it input.

Follows the code:

<html>
<head>

<script type="text/javascript">
        function local(name){
           document.myform.post_localp.value = name
        }
    </script>

</head>

<body>
<form name="myform" action="" method="POST">
    <input type="text" name="post_localp" size="20">

<div id="anterior" style="display:none" class="imgAnterior">
    <img src="imagem.png" alt="anterior" usemap="#tutorials">  &nbsp;                           
            <map name="tutorials">
                <area shape="rect" coords="142,284,185,308" href="#" alt="JE" onclick="local('J.E')">
                <area shape="rect" coords="209,284,249,308" href="#" alt="JE" onclick="local('J.D')">
                </map>    
</div>

</body>
</html>
  • I appreciate the help Valdeir, could help me with some solution too?

  • Change to document.myform.post_localp.value += name

  • dvd, worked out the way you said, the problem is that if you click more than once in the coordinate it repeats the result. Is there any way to prevent that from happening?

  • Yes... But it is good to always put in the question everything you want, for example, "do not repeat etc"...

  • I got it, it’s because I had no idea that this could happen, you would happen to know how to do it so that it doesn’t happen again?

1 answer

1

It is possible to concatenate with what is already in the input, and preventing it from being inserted (in the image below, each half, left and right, is a link map):

<html>
<head>

<script type="text/javascript">
        function local(name){
           
           var valor = document.myform.post_localp.value;
           
           if(valor.indexOf(name) == -1){
              document.myform.post_localp.value += name+" ";
           }
        }
    </script>

</head>

<body>
<form name="myform" action="" method="POST">
    <input type="text" name="post_localp" size="20">

<div id="anterior" style="xdisplay:none" class="imgAnterior">
    <img src="https://www.cleverfiles.com/howto/wp-content/uploads/2016/08/mini.jpg" alt="anterior" usemap="#tutorials">  &nbsp;                           
            <map name="tutorials">
                <area shape="rect" coords="0,354,315,0" href="#" alt="JE" onclick="local('J.E')">
                <area shape="rect" coords="316,354,630,0" href="#" alt="JE" onclick="local('J.D')">
                </map>    
</div>

</body>
</html>

  • good, thank you very much. Just one more thing, how do I concatenate a blank space between JD and JE?

  • Reply updated. : D Abs!

  • opaa, gave right brother. Thank you very much!!

  • Nice friend! If you can it is important to mark the answer with to finish

  • dvd, is around?

  • Yes, I am......

  • opa, good afternoon friend all right? a new problem has arisen, will you help me?

  • say there, if I can help

  • is the following, I made a radio form so that the user can answer the questions and then all the answers are presented on a report page, so so far so good, what I want to do is present a different image for each selected answer. How can I do that?

  • Create the images based on the values of the answers: img_1.png, img_2.png etc... and load them on the page along with the answer

  • and what code do you use to call the images on the report page? To call the answers I am using the following: <tr class="table-Row"> <td> <center> <?? > </center> </td> <td> <center> <??php echo $Row["name"];? ></center> </td> <td> <center> <?php echo $Row["post_pos"]; ? > </center> </td> <td> <center> <?php echo $Row["post_percepcao"]; ? > </center> </td> </tr>

  • Use <img src="img_1.png" />

  • and how to relate this to the answer id? you need to save the image in the BD and make the call?

  • Relating to the id I don’t think... If you have no way to relate some answer information to the image you want, you need to create a column in the BD, in the same table of answers, to save the image name and then pull in the report

Show 9 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.