-1

I am having an ASP Page.

In that I have Form Element with the action specified

Now in this form I have element where I am calling JS func on click of one button.

It is calling javascript function and later calling the default form action.

Why is it so?

How can i execute just the function..?

Code:

<FORM METHOD="post" action="Update.asp" id=form name=form1 >

    <td align=center width=10%><INPUT id=button1 type=submit ONCLICK="Gs_test()" 
onmouseover="style.backgroundColor='blue'" onmouseout="style.backgroundColor='blue'" value=ABC name=submit1 
style="width: 80%; height: 20px;background:blue; color:white; font-family:serif; font-size=medium; border-
color:black; border-width:1px"  ></td>

<SCRIPT LANGUAGE="javascript">

function Gs_test()

{

alert("GSS");

}

</script>

'

Codelearner
  • 241
  • 2
  • 3
  • 16

2 Answers2

0

Change type="submit" to type="button". Read the <input> reference on MDN.

And for the sake of all, be consistent in your HTML... don't mix uppercase, lowercase, " and nothing around attributes, etc... Also, don't mix CSS and Javascript into your HTML, put them into different files. Later you will be grateful you did.

kapa
  • 77,694
  • 21
  • 158
  • 175
  • thnx it worked.I appreciate your suggestions... i am aware of the imp of JS,CSS and HTML but the code that i copied above is very OLD(2000 era)...so it is nt in proper format... – Codelearner May 08 '13 at 15:51
  • @Codelearner If you are satisfied with my answer, you can accept it with the tickmark on the left. – kapa May 08 '13 at 19:01
0

Your gs_test() function needs to return false and you need to call it like so:

onclick="return gs_test()"

DannyB
  • 12,810
  • 5
  • 55
  • 65