HTML help (button with <area> and <input>)

Asked

Viewed 44 times

0

Good evening, folks. That’s the code:

<form action="/teste.php" method="get">

    <map name="image-map">
        <area target="" alt="" title="" coords="210,233,541,508" shape="rect">
    </map>

    <div>
        <font face="verdana" color="white">Player: </font>
        <input type="text" name="nome_player" maxlength="15"><br>
    </div>

    <div>
        <img src="imagens/img_inicial.png" alt="circulo_" class="circulo" usemap="#image-map"/>
    </div>

</form>

This area inside the map would work like a button, only I can only put a href, but I needed it to work as an input (Submit) anyway, to do the form action... Someone would know to help me?

1 answer

0


Try it this way, on href you call the function

href="javascript:document.getElementById('formID').submit();"

<form action="/teste.php" method="get" id="formID">

        <map name="image-map">
            <area target="" alt="" title="" coords="210,233,541,508" shape="rect" href="javascript:document.getElementById('formID').submit();">
        </map>
    
        <div>
            <font face="verdana" color="white">Player: </font>
            <input type="text" name="nome_player" maxlength="15"><br>
        </div>
    
        <div>
            <img src="http://unsplash.it/600/600" alt="circulo_" class="circulo" usemap="#image-map"/>
        </div>
    
    </form>


Another way to do without the href making a onClick="myform.submit();"

<form name="myform" action="/teste.php" method="post>
    ... campos do form ....
    <area onClick="myform.submit();" nohref target="" alt="" title="" coords="210,233,541,508" shape="rect">
</form>
  • It worked, buddy! Thank you so much! You saved me :D

  • A question, friend. Is there any way to put a value within this area too? If I have 4 different areas and want to differentiate

  • @Flasher12 vc can use the attribute "name", but it is obsolete in HTML5 according to the Mozilla documentation. Or you can use an attribute custom guy data-value for example or you can try to put a ID or Classe to call by jQuery for example. But I’m glad you’ve helped, if your question has already been answered consider marking an answer as accepted in this icon the side of the answer you used, so the question is not pending on the site as Question without Answer Accepted. Good luck with the project.

Browser other questions tagged

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