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!

undefined message on form loading

Status
Not open for further replies.

anveshan

Programmer
Dec 20, 2005
15
US
There is selection box in this form in asp page having table with multiple rows .In one of the columns depending on its value another text box is shown or hidden. The values (fieldname,lineNumbe,textboxid) are passed to a javascript function onChange event.
How best to force this function and pass on parameters (on each loop) whenever the data is loaded from the database without getting the javascript undefined message.
 
You cannot do this directly.
Your ASP code will ALL execute before any client-side code is executed. At the time the ASP code is running the javascript and HTML page have not yet been rendered and therefore do not exist.

You should read in your data, generate the web page plugging in the values and then execute an onload event to have javascript test the values in the fields and make alterations as you go.

Alternatively, while reading the values in ASP use logic there to determine what fields to display rather than trying to react to it afterwards.



Paranoid? ME?? Who wants to know????
 
thanks for your reply.
how to match the value of the field with the line number
 
If you could provide some relevant code, it may be easier to help you.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Here is the relevant part of the code. Array has been declared. We need to force showAlt(orig, arraypos, alt) when data is loaded from databse,without the undefined message, to show alt field if required. The code is otherwise working fine:
Code:
<%	dim d
	d=1
	do while not RS.eof
		............ 
		country(d) = RS("country")
		altCountry(d) = RS("altCountry")
		............
		d = d + 1
		RS.movenext
	loop
	RS.close%>
 .....
<html>
function showAlt(orig, arraypos, alt)
	 
	{   
		if org[arraypos].value == "None")
		{
			document.getElementById(alt).style.display = "block";
		}
		else
		{
			document.getElementById(alt).style.display = "none";
		}
	}
  .......  
<body> <form> <table>
					 
		<tr>	<td align=middle>.....</td>
			<td align=middle>Country</td>
			<td align=middle>......</td></tr>
	  	     
	<%dim rn
	 For rn = 1 to rowNum
	%>
       <tr> <td>...........</td>
       	<td align="middle"> 
	<select name="country" onchange="showAlt(form.Country,<%=rn-1%>,'altCountry<%=rn%>');">
	<option> ......</option></select>
        <div id=altCountry<%=rn%>>Alternate Country Name:<input type=text name ="altCountry" value=<%=altCountry(rn)%>>
        </div></td>
        <td>...........</td></tr>
         next </table>
 ..........</form>...</body></html>


 
You cannot expose js functions bare like that. Enclose them inside <script> tag.
 
As theniteowl mentioned, this is first and formost a client-side error. The message is shown by the browser, the JavaScript executes on the browser, the onChange event is a browser event, and so on...

The only way that ASP is even relevant is that the ASP logic modifies the HTML & JavaScript text sent to the brower client. So the problem boils down to the fact that the browser client is not satisfied with this text.

When presented with this type of problem, I find it very helpfult to "work backwards"... Before I change the ASP logic, I first identify the exact portion of the text which the browser finds unsatisfactory.

The following method works for me:

1. Use "View Source" in the browser to get the plain text output of your ASP script, save this to the desktop changing its name to Test.HTM

2. Open Test.HTM in a new browser, it should have the same browser errors as when you viewed the ASP. The line numbers for the errors are now directly related to the line numbers in your Test.HTM file.

3. Debug the JavaScript, or if stumped, ask in the JavaScript forum: forum216

4. Once the Test.HTM file behaves as expected, work backwars to your ASP by altering it reflect the changes made to the Test.HTM file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top