JavaScript funtion not run

J

Jack

Hello,
<%@ Language=VBScript %>
<%
Response.Write "<INPUT type=""button"" value=""Button"" id=button1
name=button1"">"
Response.Write "<INPUT type=""button"" value=""Button"" id=button2
name=button2"">"
%>
<Script language="VBScript">
function button1_onclick()
document.Write "ab"
end function
</script>
<Script language=JavaScript>
function button2_onclick()
{
document.write("ac");
}
</script>
When clicks button1,shows "ab".But clicks button2 cannot show "ac".How can
run function button2_onclick()?
Thank you
 
D

DevSonner

Dear Jack..

I can't speak English...So very simply...

<script language="javascript">
<!--
function btnClick()
{
document.all.gogo.innerHTML = "ac";
}
//-->
</script>

<input type="button" value="Click" name="btnTest" onClick="btnClick();">
<p id="gogo"></p>

It's not recommend what use VBScript and Javascript in one ASP page because
Two ScriptEngine reloaded in memory
 
C

Chris Barber

VBScript allows events to be automagically linked to HTML elements via a
naming convention (same as in VB).
However, JavaScript requires that events are assigned either in the HTML
itself or dynamically at runtime.

1. Static
<INPUT ....... onclick="myfunction();" .... value="Test" />

function myfunction(){
alert('Input was clicked and has a value of ' + this.value);
}

2. Dynamic
//No requirement to specify parameters - we are in fact just assigning an
object reference.
document.getElementById('mybutton').onclick = myfunction;

function myfunction(){
alert('Input was clicked and has a value of ' + this.value);
}

NB: 'this' is a very specific JavaScript thing that refers to the object
that called the function - in actual fact it refers to the parent object of
the function - in this case it's the HTML input that the function is
assigned to.

Hope this helps.

Chris.

Hello,
<%@ Language=VBScript %>
<%
Response.Write "<INPUT type=""button"" value=""Button"" id=button1
name=button1"">"
Response.Write "<INPUT type=""button"" value=""Button"" id=button2
name=button2"">"
%>
<Script language="VBScript">
function button1_onclick()
document.Write "ab"
end function
</script>
<Script language=JavaScript>
function button2_onclick()
{
document.write("ac");
}
</script>
When clicks button1,shows "ab".But clicks button2 cannot show "ac".How can
run function button2_onclick()?
Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top