tags:

views:

36

answers:

2

Hello,

I am facing the problem to post the value of form when using while or for loop.

Here is my code.

<form name="frm1" id="frm1" method="post" enctype="multipart/form-data">
<?php
for($i=0;$i<5;$i++)
{
?>
    <a href="#" onclick="return test1();">Test<?php echo $i;?></a>
    <input type="hidden" value="<?php echo $i;?>" name="var" />
<?php 
}
?>
</form>

And i have used this javascript

<script type="text/javascript">
function test1()
{
    document.frmviewer.method="post";
    document.frmviewer.action="page2.php";
    document.frmviewer.submit();
}   

</script>

Now i want to get the value of tag means "Test1" in page2.php page with hidden variable.

I am able to do it with passing value in javascript but i do not want to pass any variable in javascript and also do not want to pass any variable in url.

Thanks in advance.

Kanji

+1  A: 

Just give the hidden value as parameter to the js function

<form name="frm1" id="frm1" method="post" enctype="multipart/form-data">
<?php
for($i=0;$i<5;$i++)
{
?>
    <a href="#" onclick="return test1(<?php echo $i;?>);">Test<?php echo $i;?></a>
<?php 
}
?>
</form>
Martin Holzhauer
Thanks dear but i want without passing any variable in url or javascript function test1().
Kanji
+1  A: 

You can do it simply using this:

<form name="frm1" id="frm1" method="post" acti0n="page2.php">
<input type="hidden" name="topostvalue"/>
<?php
for($i=0;$i<5;$i++)
{
?>
    <a href="#" onclick="return test1($i);">Test<?php echo $i;?></a>
<?php 
}
?>
</form>

and in js

<script type="text/javascript">
function test1(val)
{
    document.frm1.topostvalue.value = val;
    document.frm1.submit();
}   
</script>
nik