0

I am trying to set a value in javascript via ASP

foo('RequestMode', '<%=Request.Querystring("Mode")%>')

What I'd like to do is something like this

foo('RequestMode', '<%=if (Request.Querystring("Mode")="") then 
                            Session("RequestMode")=""
                       else
                            Request.Querystring("Mode")
                       end if%>')

If I use the opening tag

<%=

I get an error saying

'If' operator requires either two or three operands.

but if I use the opening tag

<&

I get an error saying

Property access must assign to the property or use its value.

Request.Querystring("Mode") <--- highlighted

Which makes me believe that there's no error with my code, per se. How can I accomplish my task?

1 Answer 1

2

your problem should be the <%= that you are using with your if statement. What you are writing is actually printing that if statement directly to the page and not running it in VBScript. remember

<%= %>

is equivalent to

<% Response.Write() %>

So your if is being written to the page. what you should write instead is:

foo('RequestMode', '<% if (Request.Querystring("Mode")="") then %> 
                        <%= Session("RequestMode")="" %>
                   <% else %>
                        <%= Request.Querystring("Mode") %>
                   <% end if%>')

also as a note I left in what should be an error as I have no clue how you wanted to correct it. Specifically the line

<%= Session("RequestMode")="" %>

Should either be

<%= Session("RequestMode") %>

or

<% Session("RequestMode")="" %>

or

<%= Session("RequestMode") %>
<% Session("RequestMode")="" %>

or

<% Session("RequestMode")="" %>
<%= Session("RequestMode") %>

Edit

Just wanted to clarify the other error you mentioned. the reason it says

Property access must assign to the property or use its value

is because as the error states you are accessing a variable and doing nothing with it when you change <%= to <%

<%=Request.Querystring("Mode")%>

works fine because it actually reads

<% Response.Write(Request.Querystring("Mode")) %>

which will print the line to the page. When you remove the equals sign you are no longer performing an action on Request.Querystring("Mode") because you are removing that response.write

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.