How to remove x and y on submit in HTML form with Image type button?

前端 未结 4 1712
无人及你
无人及你 2020-12-02 22:04

I have created a form in my application as follows:

相关标签:
4条回答
  • 2020-12-02 22:44

    You'll always get mouse co-ordinates for a submit button type="image"

    You can use a standard submit type button and just apply styles to it to change the look.

    <input type="submit" id="search-submit" value=""
        style="background-image: url(/images/search-button.gif); border: solid 0px #000000; width: WIDTHpx; height: HEIGHTpx;" />
    
    0 讨论(0)
  • 2020-12-02 22:47

    They are the mouse coordinates of the click. I don't believe there's any way to prevent them - if you use an <input type='image'> then you get them. Why is it a problem? Can't you just ignore them?

    Answering Prashant's comment: Digg are adding an onclick handler to the <input> (or possibly an onsubmit handler to the form) which builds the neat-looking search URL and redirects the browser to that URL, and then returns false to prevent the <input> from submitting the form itself. If you turn off JavaScript you'll see that you do get the x and y parameters in the URL. Clever!

    0 讨论(0)
  • 2020-12-02 22:57

    You can simply set a value, for an image button, this will override the regular coordinates behaviour. It worked for me.

    For example :

    <input type="image" value="submit" src="sup.png" name="supprimer" />
    

    will return the php variable $_POST['supprimer'] and not its coordinate as image button. Hope this trick will help you.

    0 讨论(0)
  • 2020-12-02 22:58
    document.getElementById("formid").submit = function() {
        location = "/search/?search=" + encodeURIComponent( document.getElementById("search-box").value );
        return false;
    };
    
    0 讨论(0)
提交回复
热议问题