按下按钮后,使用php函数创建一个选择并填充它

时间:2014-08-26 01:09:08

标签: javascript php html

我一直在尝试很多东西,但我没有得到解决方案。

我有一个具有这种结构的表格:

<form>
<input type="text" name="nombre">
<input type="submit" name="first submit">
<input type="text" name="address">
</form>

当我提交“第一次提交”时......我想把那个表格,一个选择,它将填充一个php函数的结果(将“name”作为函数变量传递)

php函数,接收写入的名称并返回一个需要循环的数组,以获取每个元素作为select的选项

最后的表格需要看起来像:

<form mode="post" action="somephp.php" >
<input type="hidden" name="nombre" value=(name inserted before)>
<input type="hidden" name="nombre" value=(address inserted before)>
<select>
    <option value="i">$function_return[i]</option>
    <option value="i">$function_return[i]</option>
    <option value="i">$function_return[i]</option>
</select>
<input type="submit" name="second submit">
<form>

我浪费了很多时间......但是我变得疯狂......有人可以挽救我的生命吗?

感谢

pd:添加我尝试过的代码:

<script>
function datos() {
var min = 0,
    max = <?php echo count(obtener("manuel")) ?>,
    select = document.getElementById('selectElementId');
for (var i = min; i<=max; i++){
    var opt = document.createElement('option');
    opt.value = i;
    opt.innerHTML = <?php echo obtener("manuel")[i][element] ?>;
    select.appendChild(opt);
}
}
</script>

</head>
<body>
<input type="button" value="Submit" onclick="datos()"/>;
</body>
</html>
<?php
function obtener($link) {
$buscar= (too large, simply it receives things, its only a practice exercise, i give to every name things like "color" "clothes" etc)
return $buscar;
}
?>

0 个答案:

没有答案