/    Sign up×
Community /Pin to ProfileBookmark

onclick Vs onsubmit

Hi

Can anybody explain the difference and usage of onsubmit and onclick

rgds

shabar

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameOct 29.2009 — onsubmit is an event which is fired to submit a form, either via a submit type input button or input of type="image". onsubmit may also be triggered via script by invoking form.submit() where form is a reference to a form object. onclick is more generally an event which is fired any time the left mouse button is clicked. You could say I guess that submit buttons have by default an onclick event attached to them which fires the form's onsubmit event.

For more info on events see:

[URL]http://www.w3schools.com/jsref/dom_obj_event.asp[/URL]
Copy linkTweet thisAlerts:
@shabarauthorOct 29.2009 — Hi astupidname

Thax for ur quick response.

Can all these events use for load a new page?

What occasions we use onsubmit instead of onclick


rgds


shabar
Copy linkTweet thisAlerts:
@drhart4000Oct 29.2009 — Hi astupidname

Thax for ur quick response.

Can all these events use for load a new page?

What occasions we use onsubmit instead of onclick


rgds


shabar[/QUOTE]


If your looking to load up new pages, you want to use the onClick event. Such as

[code=html]<!--This loads a new page in the current window.-->
<a href="#" onclick="window.location='http://someplace.com';">New page</a>[/code]


Or if your looking for a popup window, you want somthing like.
[code=html]
<!--This creates a popup window with a size of 400px width and 600px height-->
<a href="#" onclick="window.open ('http://someplace.com','MyWindow',width='400',height='600');">New page</a>[/code]


You could of course always link to a function like this.
[CODE]
<script type="text/javascript">
// This is in your header

// function for new page
function newpage(url){
window.location=url;
}

//function for popup window
function newpopup(url,name){
window.open (url,name,width='400',height='600');
return false;
</script>
[/CODE]


And your html code to use those.
[code=html]
<!--This is for a new page-->
<a href="#" onClick="newpage('http://somewhere.com');">New Page</a>

<!--This is for a popup window-->
<a href="#" onClick="newpopup('http://somewhere.com','myWindow');">New Page</a>
[/code]


Note: When I write my scripts I use double quotes " for HTML, and single quote ' for javascript so it doesn't get messy ?

There's a handful of arguments you can use with with popup windows. Heres a quick list.
[CODE]status The status bar at the bottom of the window.
toolbar The standard browser toolbar, with buttons such as Back and Forward.
location The Location entry field where you enter the URL.
menubar The menu bar of the window
directories The standard browser directory buttons, such as What's New and What's Cool
resizable Allow/Disallow the user to resize the window.
scrollbars Enable the scrollbars if the document is bigger than the window
height Specifies the height of the window in pixels. (example: height='350')
width Specifies the width of the window in pixels.[/CODE]
Copy linkTweet thisAlerts:
@shabarauthorOct 29.2009 — Hi drhart4000

Great reply thanks a lot ?

One small clarification........

What occasions we use onsubmit() instead of onclick()


rgds


shabar
×

Success!

Help @shabar 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 5.21,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...