views:

318

answers:

2

Hello:

I am automating a document with html and javascript through MS Notepad. So far, I have lots of text, a few textboxes, and a button, which will execute a javascript function after a number is entered into one of the textboxes. This document is only partially completed; however, I noticed that after I add entries into my textboxes and then press the button, all of my entries erase. I believe this is a postback issue of some sort; however, I thought using an onlick event with javascript would not execute a server-side command. Also, my document is all client-side code. Basically, it is just text, html, and, currently, one JS function.

As a reiteration, would anyone know why my textbox entries erase after a button's onclick event executes, and how to stop this from happening? Additionally, the onclick event executes the JS function, which is an if statement that adds more text to the document.

Thank you,

DFM

A: 

Could you please post your current full HTML code for review?

It will help others to provide you a better answer than without.

aherrick
Thanks for the reply - Unfortunately, I cannot - I wrote the code at work on my workstation. I'll have to wait until tomorrow. I do remember a little of what I wrote (it's real basic): <input type="Submit" id="entry" onCLick="Projects()" value="Enter"/>The rest is just textboxes (i.e. input type="text") and text. Maybe my button type is wrong? My input type is submit. Should I make this input type="button"? - Thanks
A: 

If you have an <input type="submit"> button in your form then when you press the button the form will get submitted, even if you have an onclick handler. There are several ways to solve this*, but the easiest way is to change the button to type="button", which is identical except clicking it does not submit anything.

<input type="button" onclick="checkEntries()" />

*Other solutions include adding return false to your onclick handler, as in onclick="checkEntries(); return false", or adding onsubmit="return false" to the <form> element.

John Kugelman
Wow - I actually responded above with a question that you answered before I pressed "add comment". You must have been reading my mind or seen this sophomoric problem many times before. Nonetheless, thank you for your reply. I will try this tomorrow.
I also have your bank account numbers now.
John Kugelman