 |
Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

October 12th, 2006, 01:49 PM
|
Registered User
|
|
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Enabling/Disabling Form Controls
I have a form with three buttons on it, and by default I have disabled one of them by calling a function in the onLoad event of the form using a "document.form.control_name.disabled=true" statement. My problem exists when in the function I compare two variables for likeness using an "IF" statement and if the variables are equal, then I want to set the control's disabled property to false using the "document.form.control_name.disabled=false" statement.
The error I'm recieving is "Object expected" when the "IF" statement is processed. I have included the function and the form for review and if anyone can help solve this error I greatly appreciate.
LBY
function EnableDisable_Download()
{
document.snapshot.dwnldCube.disabled = true;
if (Session("sCTMSUser") == Session("sDwnldUser"))
{
document.snapshot.dwnldCube.disabled = false;
}
}
<HTML>
<HEAD>
<TITLE>Snapshot Selection</TITLE>
</HEAD>
<BODY bgColor="#99FFFF" onLoad='EnableDisable_Download();'>
<div class="snapheader">FINANACIAL ARCHIVE</div>
<FORM action="ProcessCube.asp" method=post name=snapshot>
<div class="snaptitle">Select One Snaphot:</div>
<div class="snapstyle">
<SELECT name=snapshot size=20>
<OPTION value="<%=snpRecordSet("SNAPSHOT_ID")%>" selected>
<%=snpRecordSet("NAME")%>
<%
snpRecordSet.MoveNext;
while(!snpRecordSet.EOF)
{
%>
<OPTION value="<%=snpRecordSet("SNAPSHOT_ID")%>">
<%=snpRecordSet("NAME")%>
</OPTION>
<%
snpRecordSet.MoveNext;
}
%>
</SELECT>
</div>
<INPUT id=btnBuild type=submit value="Create Cube" name=buildCube >
<INPUT id=btnDwnld type=submit value="Download Cube" name=dwnldCube onclick="this.form.action='DisplayMyCubes.asp'; return true;">
<INPUT id=btnClose type=button value="Return" name=closeSnapshot onclick="rtnHome()">
</div>
</FORM>
</BODY>
|

October 12th, 2006, 03:18 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
You can not call the ASP Session() clientside, it must be called server side and, as such, your JavaScript has no idea what Session() is.
What I might do is this
<%
If Session("sCTMSUser") = Session("sDwnldUser") then
%>
<INPUT id=btnDwnld type=submit value="Download Cube" name=dwnldCube onclick="this.form.action='DisplayMyCubes.asp'; return true;">
<%
else
%>
<INPUT id=btnDwnld type=submit value="Download Cube" name=dwnldCube onclick="this.form.action='DisplayMyCubes.asp'; return true;" DISABLED>
<%
end if
%>
Had you been using .NET you could of done:
if Session("sCTMSUser") = Session("sDwnldUser") then dwnldCube.Enabled = true
hth
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|

October 13th, 2006, 02:26 AM
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
HI Lbyii
function EnableDisable_Download()
{
document.snapshot.dwnldCube.disabled = true;
if ("<%=Session("sCTMSUser")%>"=="<%= Session("sDwnldUser")%>")
{
document.snapshot.dwnldCube.disabled = false;
}
}
Hope this will help you
Cheers :)
vinod
|

October 13th, 2006, 06:56 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
That simply will not work, vinod. Javascript, for the most part, is a client side technology and, as such, has no way of accessing values server side. Your code is syntactally incorrect as well.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|

October 13th, 2006, 07:02 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think vinod's solution *does* work and is syntactically correct. The server side ASP output is sent to the browser as plain text which ends up in the JavaScript like this:
function EnableDisable_Download()
{
document.snapshot.dwnldCube.disabled = true;
if ("SomeValue"=="SomeOtherValue")
{
document.snapshot.dwnldCube.disabled = false;
}
}
Of course the values used in the JavaScript function are determined at page load time; they don't represent the actual, server side, session variable values.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|

October 13th, 2006, 07:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
I think it will work, after running server-side the client-side script would be:
Code:
function EnableDisable_Download()
{
document.snapshot.dwnldCube.disabled = true;
if ("12a34b67d"=="98z76y54x")
{
document.snapshot.dwnldCube.disabled = false;
}
}
The downside is that the user can re-enable the control manually and ask for the download. This maybe a security risk.
--
Joe ( Microsoft MVP - XML)
|

October 13th, 2006, 07:36 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Would the names of the session variables in the client script change across different sessions? Joe also poses a good point, I can disable JavaScript in my browser all together.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|
 |