onKeyUp event calls reset function

typing in a text field resets select box

Page 1 of 1

2 Replies - 3286 Views - Last Post: 26 February 2009 - 12:57 PM

#1 midasxl   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 212
  • Joined: 03-December 08

onKeyUp event calls reset function

Post icon  Posted 26 February 2009 - 12:04 PM

Hello and thanks for your time. I need to have a select menu reset to its default option (the one with a value of "0") when a user types in a text field. Check out the code...

the html:
<INPUT type="text" name="search_vuln" value="" size="30" onkeydown="clear()">



the java script:
<script type="text/javascript">
function clear(){
	document.name_of_form.name_of_select_menu.selectedIndex = 0;
	}
	</script>



I've also tried it this way...
<script type="text/javascript">
function clear(){
	getElementById("id_of_select_menu").selectedIndex = 0;
	}
	</script>



No luck with either one. Does anyone see my mistake? Thanks for your help!

Cheers!

Is This A Good Question/Topic? 0
  • +

Replies To: onKeyUp event calls reset function

#2 midasxl   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 212
  • Joined: 03-December 08

Re: onKeyUp event calls reset function

Posted 26 February 2009 - 12:55 PM

Hello friends,
I figured this one out; at least one method.

<INPUT onfocus="document.form_name.form_field_name.value='';" type="text" name="search_vuln" value="" size="30">



Does what I need it to do. Not sure if there are better ways, but I am sure there are other ways.

Cheers!
Was This Post Helpful? 0
  • +
  • -

#3 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: onKeyUp event calls reset function

Posted 26 February 2009 - 12:57 PM

you should be able to use value=''; without searching the DOM. Javascript in all browsers should assume its own object if you do not give it one.
If you have any issues, there's always this.value='';
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1