我想上传一个文本文件,但我可以根据选择选择哪个php进程。我试图结合一些代码,但它不起作用。这是我的HTML代码:
<h3>Upload Time Logs</h3>
<fieldset>
<legend><strong>Select type of machine model</strong></legend>
<select id="cmbmachine" name="machine" class="field" onChange="this.form.action=this.option[this.selectedIndex].value;">
<option value="machine1.php">Machine 1</option>
<option value="machine2.php">Machine 2</option>
</select>
</fieldset>
<fieldset>
<legend><strong>Select a file to upload</strong></legend>
<form id="form1" action="" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" size="40" multiple="multiple" />
<br />
<p></p>
<input type="submit" value="Upload File" />
<br />
<br />
</form>
<div id="information"></div>
</fieldset>
<fieldset>
<legend><strong>Uploaded Files</strong></legend>
<div id="uploaded"></div>
</fieldset>
我尝试了这些建议Change Form "action" on selection,javascript - change form action based on selection?但似乎没有帮助..我做错了什么?...
答案 0 :(得分:0)
我终于做到了。我发现每个代码都有文字,并逐渐将其应用到我的问题中。这是我修改后的代码:
<fieldset>
<legend><strong>Select type of machine model</strong></legend>
<form id="form1" name="form1" method="post" action="/" enctype="multipart/form-data">
<select id="machine" name="machine" class="field" onChange='chgAction()'>
<option value="" selected="selected">Choose..</option>
<option value="machine1">Machine 1</option>
<option value="machine2">Machine 2</option>
</select>
</fieldset>
<fieldset>
<legend><strong>Select a file to upload</strong></legend>
<input type="file" id="files" name="files[]" size="40" multiple="multiple" />
<br />
<p></p>
<input type="submit" value="Upload File" id="upload" />
<br />
<br />
</form>
<div id="information"></div>
</fieldset>
<fieldset>
<legend><strong>Uploaded Files</strong></legend>
<div id="uploaded"></div>
</fieldset>
<script typ="text/javascript">
function chgAction(){
var form = document.form1;
console.log('chgAction()');
console.log(form.machine.selectedIndex);
switch(form.machine.selectedIndex){
case 1:
form.action = "/hrtms/machine1.php";
break;
case 2:
form.action = "/hrtms/machine2.php";
break;
}
}
</script>
答案 1 :(得分:0)
<select id="cmbmachine" name="machine" class="field" onChange="addaction(this.value)">
<option value="machine1.php">Machine 1</option>
<option value="machine2.php">Machine 2</option>
</select>
<script>
function addaction(actionvalue)
{
$("#form1").attr("action", actionvalue);
};
</script>