Question

As stated in the title...for some reason I can't get the form to submit on click however it seems to be working fine for the other form I'm submitting on the same page. Am I missing something??

Here's my code on that portion

<form id = ".$i." name='edit_staff'  class='form-inline' enctype='multipart/form-data' action = '/DTS/index.php/Index/editInfoStaff' method = 'POST'>";
    echo "<input type = 'hidden' name = 'surname' value = ".$surname." />";
    echo "<input type = 'hidden' name = 'firstName' value = ".$firstName." />";
    echo "<input type = 'hidden' name = 'middleInitial' value = ".$middleInitial." />";
    echo "<input type = 'hidden' name = 'division' value = ".$division." />";
    echo "<input type = 'hidden' name = 'email' value = ".$email." />";
    echo "<input type = 'hidden' name = 'id' value = ".$id." />";
    echo "<a href = '#' onclick='document.getElementById(".$i.").submit()'/>Edit</a>";
    echo "</form>";

    echo "<form id = 'delStaff".$i."' name='delete_staff'  class='form-inline' enctype='multipart/form-data' action = '/DTS/index.php/delete_info/deleteInfoStaff' method = 'POST'>";
    echo "<input type = 'hidden' name = 'surname' value = ".$surname." />";
    echo "<input type = 'hidden' name = 'firstName' value = ".$firstName." />";
    echo "<input type = 'hidden' name = 'middleInitial' value = ".$middleInitial." />";
    echo "<input type = 'hidden' name = 'division' value = ".$division." />";
    echo "<input type = 'hidden' name = 'email' value = ".$email." />";
    echo "<input type = 'hidden' name = 'id' value = ".$id." />";
    echo "<a href = '#' onclick='document.getElementById(delStaff".$i.").submit()'/>Delete</a>";
    echo "</div>";
    echo "</div>";
    echo "</form>";
    $i++;
Was it helpful?

Solution

Update as below: In first form:

echo "<a href = '#' onclick='document.getElementById(\"".$i."\").submit()'/>Edit</a>";

In second form:

echo "<a href = '#' onclick='document.getElementById(\"delStaff".$i."\").submit()'/>Delete</a>";

And try. Hope this helps..

OTHER TIPS

You're missing quotes around your id in

document.getElementById(delStaff".$i.").submit()

But the root problem is that you're abusing echo which makes it hard to deal with quotes. Supposing you want to insert quotes here, you would have to escape them :

echo "<a href = '#' onclick='document.getElementById(\"delStaff".$i."\").submit()'/>Delete</a>";

Instead of

echo "<a href = '#' onclick='document.getElementById(delStaff".$i.").submit()'/>Delete</a>";
echo "</div>";

you should have

<a href='#' onclick="document.getElementById('delStaff<?php echo $i;?>').submit()"/>Delete</a>
</div>

And of course, proper separation of the javascript and the html would be even better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top