Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I need to write code that will, for example, clear a textbox but not reload the page. It is my understanding that you need to use Javascript for this. If so, how?
Go Beavs!!!
  • *Experts*
Posted

I'd reccomend scanning through some info about Javascript, but the property you're looking for can be found here.

 

This will go inside your <head> tag. This simply makes a function ClearTextBox() that you can call from any <script> block following it.

 

<script type="text/javascript">
function ClearTextbox() {
 myTextBox.value = ""; // Clear the textbox, where myTextBox is the name
}
</script>

 

And here is an example of the textbox control you'd use, and the button which would clear it.

<input type="text" name="myTextBox" />
<input type="button" value="Clear" onClick="javascript:ClearTextBox()" />

 

This is untested code, but you should not have any issues. It is pretty straightforward. Just remember to replace myTextBox with the actual name of the input field.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

or simply:

<input type="text" name="myTextBox" />
<input type="button" value="Clear" 
onClick="javascript:document.all.myTextBox.value=''" />

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • *Experts*
Posted
As far as JavaScript is concerned, after the ASP.NET server renders the web page, the controls actually become standard HTML input controls. Since JavaScript is run on the client side, and the only thing the client receives are HTML controls, this code will work.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...