简体   繁体   中英

form submission in struts1 using javascript

I am trying to submit using javascript . Since I was not able to find using "document.forms" so i used "document.getElementById" but now i am not able to assign action class to it .Can someone help me on this .

My code :

<html>

<head>
just to check javascript form submission
</head>

<body>

<script>

function formsubmission(value){
alert("i am here just before the form submission"+value);
document.forms["ashutosh"].submit();
alert("i am just after the form submission");
}

</script>

<form id="ashutosh" action="http://www.gmail.com">
<select onchange="javascript:formsubmission(this.formName)">
<option value="1">ashutosh</option>
<option value="2">ashutosh1</option>
<option value="3">ashutosh2</option>
</select>
</form>
</body>


</html>

Error :

Object #<HTMLElement> has no method 'submit'

Much simpler:

<html>
    <head></head>
    <body>
        <form action="http://www.example.com">
            <select onchange="this.form.submit()">
                <option value="1">ashutosh</option>
                <option value="2">ashutosh1</option>
                <option value="3">ashutosh2</option>
            </select>
        </form>
    </body>
</html>

Demo: http://jsfiddle.net/mattball/N4fxn/

first error , this does not exist :

this.formName

"this" refers to select tag rather than the form, this.form refers to the form.

It seems like you are trying to get the form's name,

you get that by form's object .name property, but only when you have name attribute defined

<form id="something" name="something"> 

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