Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT menus

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I have a form containing 2 select menus. I need to be able to clear the value of "id" when the "report" select menu is changed.

Code:
<form method="GET" name="form">
  <select name="report" onchange="this.form.submit();"></select>
  <select name="id" onchange="this.form.submit();"></select>
</form>

I've tried:

Code:
<select name="report" onchange="this.form.submit(); document.GetElementByName('id').value = '';")

but it doesn't seem to work. Any ideas on how I can achieve this would be greatly appreciated.

 
1. there is no such function as GetElementByName
2. you shouldn't name an element "id" as that will potentially cause problems since id is a valid html attribute for just about every tag
3. you shouldn't name your form "form" as that will also potentially cause problems considering form is a valid html element
3. you need to set the selectedIndex of the dropdown to -1, that will deselect everything

something like this:

Code:
document.forms["someNameOtherThanForm"].elements["someNameOtherThanId"].selectedIndex = -1

-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
Thanks for the quick reply Kaht.

First off, your suggestions regarding form & select names is a good one, however, I only gave them those names in my post. Those are not the actual names on the page I am working on.

Changing the selected index doesn't quite do what I need. My initail description of the problem probably isn't the best. When the page loads only the "report" menu is visible. Once a selection is made, the "id" menu is revealed and the list is dynamic, containing items depending on what is selected in "report". When a selection is made in the "id" menu results are displayed.

Code:
<form method="GET" name="form">
  <select name="report" onchange="this.form.submit()";></select>
<!--php code to follow-->  
<? if (isset($report)) { ?>
  <select name ="id" onchange="this.form.submit()";></select> 
<? } ?> 
</form>

However, as it stands right now, when you change the value of the "report" menu, the value of "id" does not clear.
For example, say you select "User" from the report menu, the a list of IDs is returned in the id menu. If you select ID 13 then that user is returned. However, if you then select "Jobs" from the report menu, it automatically returns jobs with id of 13. That is why I nead to clear the value of the "id" select menu.

 
Sounds like to me you need a two-step process.... when the report menu is CHANGED, you need to CLEAR the "ID" then submit... then when the ID is changed, submit the entire form.

You probably need to do that as a function instead of an inline "onchange"... something like....

<form method="GET" name="form">
<select name="report" onchange="clearid()";></select>
</form>

<script language="javascript">
function clearid(){
document.forms["formname"].elements["id"].value='';
this.form.submit();
}

... this would clear the ID when you change the form ("fooling" the browser into rebuilding your screen, but clearing the ID field, so that it doesn't go ahead and submit with the OLD id when you just change the form)

... hope that makes sense.



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top