Reputation: 901
form method="POST" action="myprofile.php" id='myformid<?=$userid?>' name="myprof">
<input type="hidden" value="<?=$userid?>" name="id">
<a onClick="document.getElementById('myformid<?=$userid?>').submit();" style="cursor:pointer"><?=ucfirst($fname)." ".ucfirst($lname)?>
</a>
</form>
I am using form and from current page I want to get redirected to myprofile.php but its not working. To cross check the code when I use alert in anchor tag as below
<a onClick="alert(document.getElementById('myformid<?=$userid?>'))" style="cursor:pointer"><?=ucfirst($fname)." ".ucfirst($lname)?>
</a>
it returns null value... Can anyone suggest me any solution or what is going wrong ?
Upvotes: 0
Views: 79
Reputation: 2642
You can replace the code with this if you want to submit the form without anchor tag
<form method="POST" action="myprofile.php" id='myformid<?=$userid?>' name="myprof">
<input type="hidden" value="<?=$userid?>" name="id">
<input type="submit" value= "<?=ucfirst($fname).' '.ucfirst($lname)?>">
</form>
Upvotes: 1
Reputation: 17617
I tried following code and it also works fine on my machine:
<?php $userid=12; $fname="hans"; $lname="meier"; ?>
<form method="POST" action="myprofile.php" id='myformid<?=$userid?>' name="myprof">
<input type="hidden" value="<?=$userid?>" name="id">
<a onClick="document.getElementById('myformid<?=$userid?>').submit();" style="cursor:pointer"><?=ucfirst($fname)." ".ucfirst($lname)?></a>
<br>
<a onClick="alert(document.getElementById('myformid<?=$userid?>'))" style="cursor:pointer"><?=ucfirst($fname)." ".ucfirst($lname)?></a>
</form>
First link redirects as you wanted, and the second posts object HTMLFormElement
just as expected.
Maybe you want to take this code and try it out on your machine, maybe the error is somewhere else than the supplied code.
(sry this was obviously to long for a comment)
Upvotes: 0