开发者

javascript form submission to modify action

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> 
</tabl开发者_如何学Ce> 
</form> 


"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>


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜