/    Sign up×
Community /Pin to ProfileBookmark

Javascript Error when I have two submits within one form

I have two submit buttons within one form. One is an input type=submit and the other is an input type=button that calls a javascript function to do some processing and then it is suppose to submit the form using the document.myform.submit() call but I get an error that says, “Object doesn’t support this property or method”

Is there someway around this? If I remove my other input type=submit tag from the HTML page then everything works fine, but I have to give the user the option to either submit the one that doesn’t require javascipt and just submits the form along with the other button that calls the javascript function which will do some processing and then submit my form data to the next pages

Any help is greatly appreciated.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@sunitadApr 01.2004 — Post your code
Copy linkTweet thisAlerts:
@chambomanauthorApr 01.2004 — Example

<form name="myform" method="post" action="whatever.html">

...

...

...

'End of Form fields

<input type="submit" name="submit" value="submit">

<br />

<br />

<input type="button" onclick="javascript: getInfo();">

</form>

JAVASCIPT FUNCTION

<script language="JavaScript">

<!--

function getInfo() {

agree = confirm("Are you sure you want to unsubscribe to all e-mail notifications?");

if (agree == true) {

changeValue();

document.myform.submit();

};

else

if (agree == false)
history.go(-1);

function changeValue() {

<%=strJavascript%>
}
}

//-->

</script>

I get the error on document.myform.submit. I'm sure that it is conflicting with the other input tag so I need a way to get around that.

Thanks
Copy linkTweet thisAlerts:
@ai3rulesApr 02.2004 — I am not sure what <%=strJavascript%> is, but I think your problem is in the getInfo() function - you have document.myform.submit() after you call the changeValue() function.

Try putting the document.myform.submit() in the changeValue() function.

The 2 input tags will not conflict then, and shouldnt conflict to begin with..

I am pretty much a beginner at this myself, so I hope this has helped you out.
Copy linkTweet thisAlerts:
@ai3rulesApr 02.2004 — I decided to actually copy the code to frontpage, and was playing around with it - it seems to have a problem submitting the form to "whatever.html" - like I said I am a beginner - but I think submitting forms to a page requires the page to be php, asp etc...
Copy linkTweet thisAlerts:
@chambomanauthorApr 05.2004 — I was able to solve my own problem. The problem was that my first input tag had the name of submit which is a violation in javascript to have an input tag named submit when you have another button that calls a javascript function which submits the function for you. I simply named the input tags name to something else and it worked great in IE, Netscape and Safari.
×

Success!

Help @chamboman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...