开发者

Collect form variables in a function and send them as a single variable

I have a form with check boxes. When the form is submitted, I want to collect all the checked values form the check boxes in a single variable and send it to a different page along with another variable. Please help.

<form nam开发者_JAVA技巧e="form1" method="get" onsubmit="sendThis()">
<input type=checkbox name="checkbux" value=<from database/>"
<input type=checkbox name="checkbux" value=<from database/>"
<input type=checkbox name="checkbux" value=<from database/>"
<input type=checkbox name="checkbux" value=<from database/>"
<input type="submit" value="Submit">
</form>

function sendThis()
{
var tableName = "<?= $p ?>"; //obtaining the value from another php file
var allVar = a,c,d; //checked values from check boxes
window.location = 'http://localhost/fourthpage.php?q=' + allVar + '&p=' + tableName'
}


You can achieve this without doing the javascript function. Like this

<form name="form1" action="/fourthpage.php" method="get">
<input type=checkbox name="q" value=<from database/>
<input type=checkbox name="q" value=<from database/>
<input type=checkbox name="q" value=<from database/>
<input type=checkbox name="q" value=<from database/>
<input type=hidden name="p" value="<?= $p ?>" />
<input type="submit" value="Submit">
</form>


Send it inside an array, for example:

<input type=checkbox name="checkbux[]" value=<from database/>"
<input type=checkbox name="checkbux[]" value=<from database/>"
<input type=checkbox name="checkbux[]" value=<from database/>"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜