JavaScript to submit form plus value from map area?

I am trying to create a simple search function when a user selects a parameter from the drop-down list and clicks on the map to see the results for these two parameters

I have this php at the top of my document:

<?php if ((isset($_POST["MM_search"])) && ($_POST["MM_search"] == "yes")){

 $lang = $_POST['lang'];
 $salerent = $_POST['salerent'];
 $zone = $_POST['zone'];

 $updateGoTo = '/'.$lang.'/'.$salerent.'/'.$zone.'/results.html';

  header("Location: $updateGoTo");


} ?>

then I have this javascript and form:

<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<select name="salerent" id="salerent">
<option value="forsale" selected="selected">For Sale</option>
<option value="forrent">For Rent</option>

</select>


<script type="text/javascript" language="javascript">

function submitMyForm(aForm, val)
{
 aForm.zone.value = val;
 aForm.submit()
}
</script>


<input type="hidden" name="lang" value="en" />
<p><img src="images/maps/island.gif" alt="Search" width="150" height="150" border="0" usemap="#Map" id="Image1" />
<map name="Map" id="Map">

<area shape="poly" coords="65,30,71,49,83,52,88,63,98,67,104,55,108,41,114,38,126,36,135,34,135,19,120,17,116,10,87,18" onclick="javascript:submitMyForm('document.form1','san-juan')" name="zone" id="zone" value="san-juan" alt="San Juan" onmouseover="MM_swapImage('Image1','','images/maps/juan.gif',1)" onmouseout="MM_swapImgRestore()" />

I get aForm.zone undefined in FireBug, but I suspect this won't work anyway ... can anyone help?

thank

+3
source share
1 answer

instead of assigning a value to the zone of the zone, create a hidden form field with a different name that will hold this value for you.

In your javascript code:

function submitMyForm(aForm, val) {
 aForm.aHiddenZone.value = val;
 aForm.submit()
}

html:

<input type="hidden" name="aHiddenZone" value="" />
+2

Source: https://habr.com/ru/post/1730393/


All Articles