Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old October 12th, 2006, 01:49 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>

  #2 (permalink)  
Old October 12th, 2006, 03:18 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
  #3 (permalink)  
Old October 13th, 2006, 02:26 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

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
  #4 (permalink)  
Old October 13th, 2006, 06:56 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
  #5 (permalink)  
Old October 13th, 2006, 07:02 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
  #6 (permalink)  
Old October 13th, 2006, 07:03 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #7 (permalink)  
Old October 13th, 2006, 07:36 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling and disabling Required field Validators mrufus General .NET 0 June 27th, 2006 03:44 AM
Enabling and Disabling form elements socoolbrewster Javascript How-To 4 February 21st, 2006 04:45 PM
Disabling/enabling the textbox of EditCommandColu ninel ASP.NET 1.0 and 1.1 Professional 1 February 20th, 2006 04:39 PM
MS-Outlook, enabling/disabling rules shamigc VBScript 0 August 4th, 2004 08:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.