开发者

Submitting an HTML form that has no name

开发者 https://www.devze.com 2023-02-11 22:57 出处:网络
I\'m wondering how I can automatically submit an html form that has no name or no id values. I don\'t want to use any scripts to do so.I want to be able to do it from within a hyperlink.I have seen an

I'm wondering how I can automatically submit an html form that has no name or no id values. I don't want to use any scripts to do so. I want to be able to do it from within a hyperlink. I have seen an example that appends the following onto a hyperlink:

&onClick="document.forms[0].submit()"

However this doesn't seem to be working. Does 开发者_JAVA百科anyone have any ideas?

Thanks!


I don't want to use any scripts to do so.

That's impossible without help of JavaScript. I'd just use a regular submit button which is styled like a link with help of CSS.

E.g.

<form action="http://stackoverflow.com">
    <input type="submit" value="Go to Stackoverflow.com" class="link" />
</form>

with

input[type=submit].link {
    margin: 0;
    border: 0;
    background: none;
    overflow: visible;
    color: blue;
    cursor: pointer;
}

Demo here.


Make sure that either you have just one form in the HTML or change the 0 to whatever is the index of that form in the forms collection. The first form has index of 0.

<a href="#" onclick="document.forms[0].submit();return false;">Click here</a>
0

精彩评论

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