curiouswebster
asked on
How do I use the aspx page to load a JavaScript function on a button click
I need to load a JavaScript function upon a button click. I forgot how do I relate the asp control inside the aspx page with the JavaScript and the OnClick event.
Could someone please send me this?
thans,
newbieweb
Could someone please send me this?
thans,
newbieweb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ahh, forget about line 3 and 4 (i copied it from my other solution and forget to take it off)
JINN
JINN
ASKER
I was thinking more like this. Except this does not work. Is it the javaScript
of the ASP.NET that's at fault?
thanks,
newbieweb
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function DODataLookup(){
window.location = "../DataLookup.aspx";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="submitBtn" runat="server" script="DODataLookup()" Style="z-index: 100;
left: 118px; position: absolute; top: 140px" Text="Submit" />
</div>
</form>
</body>
of the ASP.NET that's at fault?
thanks,
newbieweb
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function DODataLookup(){
window.location = "../DataLookup.aspx";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="submitBtn" runat="server" script="DODataLookup()" Style="z-index: 100;
left: 118px; position: absolute; top: 140px" Text="Submit" />
</div>
</form>
</body>
Oke then it should be:
<asp:Button ID="submitBtn" runat="server" OnClientClick="DODataLooku p()" Style="z-index: 100; left: 118px; position: absolute; top: 140px" Text="Submit" />
Check this link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
JINN
^^
<asp:Button ID="submitBtn" runat="server" OnClientClick="DODataLooku
Check this link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
JINN
^^
anyway you can set style like that for your button I guess, you will have to set the CssClass which refers to the predefine CSS class. If you want to simplify that:
<div style="z-index: 100; left: 118px; position: absolute; top: 140px">
<asp:Button ID="submitBtn" runat="server" OnClientClick="DODataLooku p()" Text="Submit" />
</div>
or <span>
It is not possible to use normal html property for server control like you do with <input > <select ..> normal html element
JINN
<div style="z-index: 100; left: 118px; position: absolute; top: 140px">
<asp:Button ID="submitBtn" runat="server" OnClientClick="DODataLooku
</div>
or <span>
It is not possible to use normal html property for server control like you do with <input > <select ..> normal html element
JINN
ASKER
This is not working. Could it be the path name in the JavaScript?
how do I find the error?
newbieweb
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function DODataLookup(){
window.location = "../DataLookup.aspx";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="z-index: 100; left: 118px; position: absolute; top: 140px">
<asp:Button ID="submitBtn" runat="server" OnClientClick="DODataLooku p()" Text="Submit" />
</div>
</form>
</body>
how do I find the error?
newbieweb
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function DODataLookup(){
window.location = "../DataLookup.aspx";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="z-index: 100; left: 118px; position: absolute; top: 140px">
<asp:Button ID="submitBtn" runat="server" OnClientClick="DODataLooku
</div>
</form>
</body>
you can test if your button call the javascript by:
function DODataLookup(){
alert(' hey ');
window.location = "../DataLookup.aspx";
}
you see hey, then the next line is the problem, appear to me it will navigate to the parent folder of this page and lookfor datalookup.aspx ? is what you want? What you are doing is redirecting the current page to that page.
Play around with the path
Jinn
function DODataLookup(){
alert(' hey ');
window.location = "../DataLookup.aspx";
}
you see hey, then the next line is the problem, appear to me it will navigate to the parent folder of this page and lookfor datalookup.aspx ? is what you want? What you are doing is redirecting the current page to that page.
Play around with the path
Jinn
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm having trouble with a null test in JavaScript for a var type:
alert('OK1');
var elem = document.getElementByID("r ecordLocat orTextBox" );
if (elem != 'undefined')
{
alert('OK2');
}
what is the correct way to test if elem is null? I never get OK2.
newbieweb
alert('OK1');
var elem = document.getElementByID("r
if (elem != 'undefined')
{
alert('OK2');
}
what is the correct way to test if elem is null? I never get OK2.
newbieweb
if(elem!=undefined)
There are major different between undefined and null,
If you check
if (elem != null)
{
alert('OK2');
}
it's the same as
if(!elem),
and they are good enough
btw if you want to check if the property is set or not:
if (elem.style != 'undefined') is the correct way (with quote)
Keep in mind, javascript is case sensitive:
var elem = document.getElementById("r ecordLocat orTextBox" );
(instead of ID it's Id)
JINN
If you check
if (elem != null)
{
alert('OK2');
}
it's the same as
if(!elem),
and they are good enough
btw if you want to check if the property is set or not:
if (elem.style != 'undefined') is the correct way (with quote)
Keep in mind, javascript is case sensitive:
var elem = document.getElementById("r
(instead of ID it's Id)
JINN
Hope this helps
JINN
Open in new window