Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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>

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:06 PM.


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