简体   繁体   中英

How do i change the Action attribute in a form field? HTML

Im currently working on a web application, where i need to be able to take a picture in a browser using a mobile device. I'am currently able to upload this picture to my storage on googlecloud, but i am having some troubles with the URL of said picture. The URL of the picture is defined in an action(HTML attribute). And im struggling to see how this action field can be dynamic. It seems i cant put in the variable name for my URL in the action field.

Is there any other way to do this? Im sorry in advance for my bad english.

<form id="BilleddeUpload" action="url" method="POST" enctype="multipart/form-data">
    <input type="file" accept="/*" name="file">
    <button>Submit</button>
</form>
<script>
    function gogogoogle(){
        var billedenavn = document.getElementById("BilledeUpload");
        var url = "https://storage.googleapis.com/notgonnaputreallinkhere/"
        + prompt("Insert picture name here.");

        billedenavn.action=url;
}
</script>

<p>Billede på google cloud </p>
<button onclick="gogogoogle()">
    Hvad skal den hedde????
</button>

You already have defined a variable to hold a reference to the form billedenavn .

This line

 var billedenavn = document.getElementById("BilledeUpload")

and a few lines later you wrote

  document.getElementById("BilledeUpload").action = url;

which contains a typo in the form ID. But why not directly write:

  billedenavn.action = url;

their is some syntax error.
put function [and it's body] into script tag,
and change form id from BilleddeUpload to BilledeUpload .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM