Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling javascript function from jsp

Status
Not open for further replies.

valaparla123

Programmer
Jan 22, 2013
1
0
0
IN
Hi

I have a jsp page. In this, the body tag has onLoad method. this is all ready existing one and this onload is calling from abc.js .

if i want to add another onload function in same body tag and we have to call second onload from another javascript file. for this what i have to do?

please help out me?

Existing code: <body onload=javascript:"function1();return false;">?
</body>

the above code is already existing code. i want to call another function2() from above body tag. for that what i have to do?

fuction1() implemented in abc.js
function2() implemented in def.js


please help out me?




Thanks
hanu
 
Hi

hanu said:
if i want to add another onload function in same body tag and we have to call second onload from another javascript file. for this what i have to do?
Specifying event handlers in the [tt]body[/tt] tags [tt]onload[/tt] is deprecated practice. You should prefer
JavaScript:
window[teal].[/teal][COLOR=darkgoldenrod]addEventListener[/color][teal]([/teal][green][i]'load'[/i][/green][teal],[/teal]function1[teal],[/teal][b]false[/b][teal])[/teal]
window[teal].[/teal][COLOR=darkgoldenrod]addEventListener[/color][teal]([/teal][green][i]'load'[/i][/green][teal],[/teal]function2[teal],[/teal][b]false[/b][teal])[/teal]

Note that Explorer handles [tt]addEventListener()[/tt] since version 9. If you need to support older versions too, you will also need
JavaScript:
window[teal].[/teal][COLOR=darkgoldenrod]attachEvent[/color][teal]([/teal][green][i]'onload'[/i][/green][teal],[/teal]function1[teal])[/teal]
window[teal].[/teal][COLOR=darkgoldenrod]attachEvent[/color][teal]([/teal][green][i]'onload'[/i][/green][teal],[/teal]function2[teal])[/teal]

hanu said:
Existing code: <body onload=javascript:"function1();return false;">?
[ul]
[li]The [tt]javascript:[/tt] pseudo-protocol is needed only in attributes where the value is expected to be an URI.[/li]
[li]The [tt]return false[/tt] statement is needed only if you want to stop the triggered event's default behavior.[/li]
[/ul]
But if you want to continue with your old code, you can just call both functions :
HTML:
[b]<body[/b] [maroon]onload[/maroon][teal]=[/teal][green][i]"function1();function2()"[/i][/green][b]>[/b]


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top