Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asptoday_discuss thread: Refering to a listbox


Message #1 by "Tan Chye Ting" <chyeting18@h...> on Sun, 17 Feb 2002 15:24:09
i have a form with listbox in it.i want to use the OnSubmit event on this 

form . something like OnSubmit=<%if Request.form("ListboxName")= 0 then 

call verify end if%>..why does this line of code does not seem to 

execute..is there anything wrong...can i refer to the listbox as 

Request.form("ListBoxName")?
Message #2 by "Maff Wyde" <hydecore@h...> on Mon, 18 Feb 2002 03:05:59
I do not think you have grasped the ASP page life cycle. 

1) OnSubmit is a client side JavaScript event

2) if Request.form("ListboxName... is Server Side VBScript.



Request.form("ListboxName") is obviously empty when the page is first 

processed.



the client side code that renders will be somthing like:



OnSubmit=""



your "verify" function will never get called.. (I hope you didn't spend 

too much time writing that one ;) )



which will cause nothing to happen. 



You must access the drop downlist contents using the DOM (document object 

model) through client side javascript not through server side code (I 

wonder if you have been programming ASP.NET and are now getting confused 

with old fashioned ASP..?).



Anyway the code you need is somthing along the lines of:



<... onSubmit="return(CheckList(document.all.myForm))"



Then write a function to check the contents client side:



function CheckList(oForm){

	

	var errMsg = 'Fill it all in!';

	if (oForm.yourDropDownListName....





If the DOM is new to you then check out the very useful DOM viewer which 

can be found on http://www.brainjar.com/ this will conceptually help you 

understand the properties etc. Also check out the MSDN DHTML ref. 



In the mean time having read some of your other questions  on this 

newsgroup I would highly recommend, the WROX Beginning Active ServerPages 

and perhaps the Professional JavaScript book as well.



Happy coding bro.





> i have a form with listbox in it.i want to use the OnSubmit event on 

this 

> form . something like OnSubmit=<%if Request.form("ListboxName")= 0 then 

> call verify end if%>..why does this line of code does not seem to 

> execute..is there anything wrong...can i refer to the listbox as 

> Request.form("ListBoxName")?

  Return to Index