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!

Forms: grabbing data and trasfering to variable

Status
Not open for further replies.

MajorTechie

Programmer
Mar 20, 2002
30
CA
Hello,

I have a VERY simple piece of code that doesn't work. I am trying to "compare" the values of a drop down box (called DCOutput) and an input box (called CustomVDC) and give a value to a variable (called DCOutput) depending on the former two values.

Basically, if the user leaves the drop down unselected (thus a value of "") or chooses "CustomVDC", then I want the variable DCOutput to take on the CustomVDC value. Here's the code:

If (Session("DCOutput") = "CustomVDC" & Session("CustomVDC") = "") or (Session("DCOutput") = "" & Session("CustomVDC") = "") Then
DCOutput = " "
ElseIf Session("DCOutput") = "CustomVDC" Then
DCOutput = Session("CustomVDC")
Else
DCOutput = Session("DCOutput")
End If
 
Change the '&' characters in your logical expressions to 'and'.

ie.
If (Session("DCOutput") = "CustomVDC" AND Session("CustomVDC") = "") or (Session("DCOutput") = "" AND Session("CustomVDC") = "")

Does that fix it? Brett Birkett B.Comp
Systems Analyst
 
I just tried it and it still doesn't work. Thanks for the suggestion, though.
 
What is it doing wrong that you need to fix?? ie. Does DCOutput stay empty or ??

Brett Birkett B.Comp
Systems Analyst
 
If a value is entered into the textbox (ie: the CustomVDC) value, the DCOutput variable's value doesn't reflect that.
 
Try putting a CStr() function call around all your Session() calls. ie. CStr(Session("DCOutput")) = "CustomVDC"

Just to make sure we are comparing strings with strings.

Also, check for any spelling errors, because the logic seems ok to me. you haven't posted the code that fills the session variables, so I have to assume that they are being filled accurately. Remember the comparisons will be done case sensitively, so check you don't accidently have a Dcoutput, or CustomVdc, etc, in your unposted code. Brett Birkett B.Comp
Systems Analyst
 
Still no luck. Here's the code for the form:

<select name=&quot;DCOutput&quot; size=&quot;1&quot; onClick=&quot;DCOther();&quot;>
<option value=&quot;&quot; selected>-Please Select- </option>
<option value=&quot;12VDC&quot;>12 VDC </option>
<option value=&quot;24VDC&quot;>24 VDC</option>
<option value=&quot;36VDC&quot;>36 VDC</option>
<option value=&quot;48VDC&quot;>48 VDC</option>
<option value=&quot;-48VDC&quot;>-48 VDC</option>
<option value=&quot;72VDC&quot;>72 VDC</option>
<option value=&quot;125VDC&quot;>125 VDC</option>
<option value=&quot;250VDC&quot;>250 VDC</option>
<option value=&quot;300VDC&quot;>300 VDC </option>
<option value=&quot;600VDC&quot;>600 VDC</option>
<option value=&quot;CustomVDC&quot;>Other</option>
</select>
<input type=&quot;text&quot; name=&quot;CustomVDC&quot; size=&quot;10&quot; value=&quot;&quot;>


...and the rest of the VBScript:

Dim DCOutput

Session(&quot;DCOutput&quot;) = Request(&quot;DCOutput&quot;)
Session(&quot;CustomVDC&quot;) = Request(&quot;CustomVDC&quot;)

Ugh, this is frustrating
 
I just took your code and filled in the gaps on my machine. And it works no problems. I don't know what you are doing with your javascript code. Is it neccessary though?? I just put your form code inside a form that calls itself. Then at the top of the asp page, I put your Session and request code, then the logic part of the code. And it is working great. Also, is it necessary that you use Session variables? Can't you just use a local variable to store the requested values and compare these instead?
Here is the code I got working....

<%@ Language=&quot;VBScript&quot;%>
<%
Option Explicit
Response.Buffer = False
%>

<%

Dim DCOutput

Session(&quot;DCOutput&quot;) = Request(&quot;DCOutput&quot;)
Session(&quot;CustomVDC&quot;) = Request(&quot;CustomVDC&quot;)

Response.Write Session(&quot;DCOutput&quot;) & &quot;<BR>&quot;
Response.Write Session(&quot;CustomVDC&quot;) & &quot;<BR>&quot;

If (Session(&quot;DCOutput&quot;) = &quot;CustomVDC&quot; And Session(&quot;CustomVDC&quot;) = &quot;&quot;) or (Session(&quot;DCOutput&quot;) = &quot;&quot; And Session(&quot;CustomVDC&quot;) = &quot;&quot;) Then
DCOutput = &quot; &quot;
ElseIf Session(&quot;DCOutput&quot;) = &quot;CustomVDC&quot; Then
DCOutput = Session(&quot;CustomVDC&quot;)
Else
DCOutput = Session(&quot;DCOutput&quot;)
End If

Response.Write &quot;DCOutput is: &quot; & DCOutput

%>

<html>
<body>

<form action=&quot;help.asp&quot; method=&quot;post&quot;>
<select name=&quot;DCOutput&quot; size=&quot;1&quot;><BR>
<option value=&quot;&quot; selected>-Please Select- </option><BR>
<option value=&quot;12VDC&quot;>12 VDC </option><BR>
<option value=&quot;24VDC&quot;>24 VDC</option><BR>
<option value=&quot;36VDC&quot;>36 VDC</option><BR>
<option value=&quot;48VDC&quot;>48 VDC</option><BR>
<option value=&quot;CustomVDC&quot;>Other</option><BR>
</select><BR>

<input type=&quot;text&quot; name=&quot;CustomVDC&quot; size=&quot;10&quot; value=&quot;&quot;><BR><BR><BR>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</form>


</body>
</html>


Let me know how you go :)

Brett Birkett B.Comp
Systems Analyst
 
Brett,

What do these do?

Option Explicit
Response.Buffer = False

Response.Write

Thanks for your time!
 
Option Explicit is used to enforce variable declarations. ASP (and VB) allows you to use variables that haven't been declared with a Dim statement. It is bad to do this, and by putting Option Explicit at the top of your code, you will get error messages when you try to use undeclared variables.

Resonse.Buffer = False isn't strictly necessary, because Buffer is set to false by default. I put it here by habbit, because you can actualy set it to True, which will make the entire web page get rendered before it is displayed. (Have you seen how you can watch a page build in IE dynamically?) well response.buffer = true will stop this, so all you see is the completed page. This is usefull for do Response.Redirects (redirect to another url) anwhere in your code.

And finally Response.Write &quot;<BR>&quot; will output a <BR> tag to the current html/asp page.

Did my code posting work for you?

Cheers. Brett Birkett B.Comp
Systems Analyst
 
Brett,

Sorry for the delay. Wasn't in yesterday (sick) and didn't check the board.

I'm not &quot;Writing&quot; to the page, I'm e-mailing it. Here's some of the code:

strTableBegin = &quot;<table align=center width=94% border=1 cellspacing=0 cellpadding=4>&quot;
strRowBegin = &quot;<tr>&quot;
strRowEnd = &quot;</tr>&quot;
strCellBlue = &quot;<td colspan=2>&quot;
strCellBegin1 = &quot;<td width=25% align=right>&quot;
strCellBegin2 = &quot;<td>&quot;
strCellEnd = &quot;</td>&quot;
strText = &quot;<font face=Verdana size=2>&quot;
strTextEnd = &quot;</font>&quot;
strTableEnd = &quot;</table>&quot;


strRowBegin + strCellBegin1 + strText + &quot;<b>DC Output Voltage</b>&quot; + strTextEnd + strCellEnd + strCellBegin2 + strText + DCOutput + strTextEnd + strCellEnd + strRowEnd & vbCrLF &_

Mail.Body = &quot;<html><body bgcolor=#FFFFFF>&quot; &_
EmailBody &_
&quot;</body></html>&quot;
On Error Resume Next
Mail.Send

Secondly, I have my form posting to another page, but I don't think this makes a difference... Anyway, I've worked at this much longer than it deserves. Thanks for your help, I've found another method. Not as intelligent, but it works at least.

S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top