javascript表单提交修改动作

发布于 2024-09-30 21:23:38 字数 683 浏览 0 评论 0原文

我正在尝试根据要发布的文件的名称修改表单的发布网址。非常感谢任何建议。这是代码(不起作用):

<script type="text/javascript">  
    function submit_form()  
    {
        document.uploadform.action = "upload?name=" + document.uploadform.codejar.value;
        return 1;
    }
</script>
<form name="uploadform" method="post" onsubmit="return submit_form();"> 
<table> 
<tr><td>Select your jar to upload</td></tr> 
<tr><td> <input type="file" name="codejar" style="width: 400"></td></tr> 
<tr><td><input type="submit" name="send" value="Upload jar"></td></tr> 
</table> 
</form> 

I'm trying to modify the post url of a form depending on the name of the file being posted. Any suggestions very much appreciated. Here is the code (which doesn't work):

<script type="text/javascript">  
    function submit_form()  
    {
        document.uploadform.action = "upload?name=" + document.uploadform.codejar.value;
        return 1;
    }
</script>
<form name="uploadform" method="post" onsubmit="return submit_form();"> 
<table> 
<tr><td>Select your jar to upload</td></tr> 
<tr><td> <input type="file" name="codejar" style="width: 400"></td></tr> 
<tr><td><input type="submit" name="send" value="Upload jar"></td></tr> 
</table> 
</form> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别在捏我脸啦 2024-10-07 21:23:38

“我正在尝试让它对文件进行简单的 http post,以文件名作为参数的 url”

然后执行此操作:

function submit_form()  {
    document.uploadform.action = document.uploadform.codejar.value;
    document.uploadform.submit();
}

...并考虑将“发送”按钮更改为

<button type="button" onclick='submit_form()'>Upload jar</button>

"I'm trying to get it to do a plain http post of the file, to a url with the filename as a parameter"

Just do this then:

function submit_form()  {
    document.uploadform.action = document.uploadform.codejar.value;
    document.uploadform.submit();
}

...and think about changing your "send" button to

<button type="button" onclick='submit_form()'>Upload jar</button>
寄离 2024-10-07 21:23:38

为什么你需要这样做?

表单发布后,您应该能够访问该信息。

此外,浏览器在从文件输入获取值时可以发送不同的内容。

Why would you need to do that?

You should be able to access that once the form is POSTed.

Also, browsers can send different things when getting the value from file inputs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文