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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an ASP Value to javascript for Conditional Functions

Status
Not open for further replies.

hodgesp

Programmer
Apr 21, 2004
32
US
I have an ASP form that end-users will be useing to update a SQL 2000 database. It is an upgrade to an MS-Access dtabase frontednd that I built using VBA.

The problem I have is that I need to get users to fill out specific data elements based on values within other data elements. For example if an end-user chooses a 'CAR' action then I need a pop-up window to appear with additional fields that required entry. If the user chooses 'QA Audit' I do not need the pop-up window to appear.

In other words I need to get similar functionality that I had with an onUpdate event where If a field equals a certain value another fileds visiblity is set to True else it was False.

I already have the javascript for the pop-up window included and I call it from the onChange attribute of the <Select> tag. I just need to figure out how to conditionalize the pop-up box based on the value chosen? and How do I pass the value into the function?

Here is the Code for the Script and the Select Opject.


Code:
 <script language="JavaScript">
   Function goNewWin() {
	var NewWinHeight=200;
	var NewWinWidth=500;
	
	var NewWinPutX=20;
	var NewWinPutY=20;
 
 TheNewWin TheNewWin =window.open("Attribute.htm",'TheNewpop','fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no'

 TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
 TheNewWin.moveTo(NewWinPutX,NewWinPutY);
}
</script>
Code:
<!-----ASP Code-->
<TABLE cellspacing="1" width="100%" style="BORDER-RIGHT: blue 4px groove; BORDER-TOP: blue 2px groove; FONT-WEIGHT: normal; FONT-SIZE: 10px; BORDER-LEFT: blue 2px groove; COLOR: blue; BORDER-BOTTOM: blue 4px groove; BACKGROUND-COLOR: #cccccc" ID="Table9">
 <tr>
 <td width="35%">
	<%	'FlagType
	   FlagType=Request.Form("FlagType")
		If Err.number <> 0 Then
                  Response.Write "<br>ASP Err.Number: "& Err.Number &"<br>"
		Else						           SQLStr="SELECT  * FROM dbo.tblComFlag order by FlagType"
		   Set RS1 = dbConn.Execute(SQLStr)	

Response.Write "Commitment Type: "&"<SELECT NAME=""FlagType"" onChange=""goNewWin(FlagType)"" Size=1>"
		Response.Write "<option></option>"
		WHILE NOT RS1.EOF
		 RESPONSE.Write"<option value='"&RS1("FlagType")&"'>" & RS1("FlagType")
		RS1.MoveNext	      WEND                        						Response.Write "</SELECT>" 	
	End if						
	%>
    </td>
  </tr>
</TABLE>


 
Sounds like it'd be easiest to just code 2 different popup windows. These are the changes I'd make:
Code:
Response.Write "Commitment Type: "&"<SELECT NAME=""FlagType"" onChange=""goNewWin([b]this.options(this.selectedIndex).value[/b])"" Size=1>"
Code:
[b]f[/b]unction goNewWin([b]selection[/b]) {
  var NewWinHeight=200;
  var NewWinWidth=500;

  var NewWinPutX=20;
  var NewWinPutY=20;
  
  [b]myURL = (selection == "something") ? "URLifTrue.html" : "URLifFalse.html";[/b]
  //"something" would obviously be one of the values from the pulldown menu
  TheNewWin TheNewWin =window.open([b]myURL[/b],'TheNewpop','fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no'

  TheNewWin.resizeTo(NewWinHeight,NewWinWidth);
  TheNewWin.moveTo(NewWinPutX,NewWinPutY);
}


-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top