【发布时间】:2012-09-19 06:08:36
【问题描述】:
我正在为我的网站制作上传部分。 当用户想要上传新的应用程序时,他们需要填写一个表格,其中放置版本号等。
可以上传 27 种不同的应用程序。为此我做了一个while循环
示例:
<select id="type">
<option value="choose" selected>choose here</option>
<?php
require("Function/applist.php");
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
echo "<option value=".$showtablerow[0].">".$showtablerow[0]."</option>";
}
?>
</select>
</div>
<div id="choose" class="add" style="display:none;"></div>
<?php
require("Function/applist.php");
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
echo "<div class='add' id=".$showtablerow[0]." style='display:none;'><h2 id='amx-label'>".$showtablerow[0]."</h2>
<div id='formadd' style='opacity:1;'>
<form name='addamx' id='addamx' method='post'>
<div id='version' class='uploadform' style='opacity:1;'>
Version: <input style='opacity:1;' required type='text' name='versie' id='versie' width='3' onchange='process1()' ><br>
</div>
<div id='date' class='uploadform' style='opacity:1;'>
Release Date(yyyy-mm-dd): <input required type='date' style='opacity:1;' size='10' maxlength='10' name='date' id='date'>
</div>
<div id='build' style='opacity:1;'>
Build By: <input required type='text' style='opacity:1;' size='5' maxlength='25' name='build' id='build' >
</div>
<div id='platform' style='opacity:1;'>
Platform: <span>32 Bit:</span><input required type='radio' style='opacity:1;' id='platform' name='platform' value='32bit'>
<span>64 Bit:</span><input required type='radio' style='opacity:1;' id='platform' name='platform' value='63bit'>
</div>
<div id='application'>
<input type='hidden' name='app' value=".$showtablerow[0]." />
</div>
<div id='notes' style='opacity:1;'>
Release Notes: <textarea id='notess' name='test' onblur='process1()'></textarea>
</div>
<div id='uploadfooter' style='opacity:1;'>
<button type='submit' id='uploadamx' name='uploadamx'>Upload
</div>
</form>
</div>
</div>";
}
?>
在选择框中,他们选择要上传的应用程序,并根据该选择获得一个表单。
他们在文本区域写下他们的发行说明。
我希望他们在填写版本号时自动将该版本号归档在文本区域中。
我用下面的 javascript 搞定了:
function process1() {
var appname = document.getElementById('type').value;
var version = document.getElementById('versie').value;
var textvalue = "changes for " + appname + " version " + version;
document.getElementById("notess").value = textvalue;
}
该函数仅适用于第一个表单 div 当我在第二个 div 上尝试它时,textarea 保持为空,并且第二个 div 的版本号从第一个 div 插入到 textarea 中
我怎样才能使函数只填充来自该表单的版本号? 有什么想法吗?
编辑***
AboQutiesh 是一家不错的初创公司,它唯一需要的调整是 他写了: onblur='process1(".$showtablerow[0].")' 结果是 onblur='process1(argument)' 这不起作用,因为参数需要 onblur='process1('argument')' 因为它在一个while循环中我不能只放''因为它会破坏整个onblure 感谢我的一个学院,他把我指向了 ascii 表 解决方案:
我把它改成了 onblur=process1('".$showtablerow[0]."')
(删除 ; 在 asccii 的末尾,否则它不会在此处正确显示) 感谢启动 AboQutiesh
【问题讨论】:
-
您正在复制表单(带有循环)和所有输入字段。由于您在表单和输入字段中使用 id,并使用 getElementById 来检索它们,因此无法确定是什么。
标签: javascript forms html input textarea