Solved

Can Javascript make activate/inactive button?

Posted on 1998-10-01
8
1,430 Views
Last Modified: 2008-02-01
I have 2 buttons, one should be pressed before the second. The second button should process the result from the first one. Can I make the second one inactive until the first button pressed and then activate it. Or is there a solution to this problem. Thanks
0
Comment
Question by:nawaf
  • 4
  • 4
8 Comments
 
LVL 8

Accepted Solution

by:
jbirk earned 70 total points
Comment Utility
Sure this can be done.  It will depend on you application of the buttons as to how the code should be written though.

The basic process is to set a variable in the javascript in the header to 0.  Then when the first button is clicked, set that variable to 1.  Then whenever the second button is clicked, you first check to see that value is 1, if it isn't you quit, if it is you continue.  Now if the second button is a submit button (and not a user defined button), then you need to do your check in the onSubmit event of the form, and be sure to return false when the value is 0 and if the value is 1, do your calculation or whatever and then return true.

Heop this helps.
If you need specific code, please post your code or at least a similar demo of your code and I will code this up for you.
-Josh
0
 

Author Comment

by:nawaf
Comment Utility
Her is the full code:
<HTML>

<HEAD>
<TITLE>slope</TITLE>
</HEAD>

<BODY BGCOLOR="#99ccff">

<FORM method=post ACTION="http://server/cgi-bin/slope.pl" >

<table cellpadding=0 cellspacing=0 border=0 width=750 bgcolor="#6666ff">

<tr><td>
<font face="GillSans, Ventana, Arial, Helv" size=4 align=center>Slop/Aspect finctions</font>
</tr></td>
<tr><td colspan=2>&nbsp;</td></tr>

   
<tr><td>
<font face="GillSans, Ventana, Arial, Helv">
<I>Input File  </I>
</font>

<SELECT NAME="inputs">
<OPTION value="affaosol">affaosol
<OPTION value="brazil2">brazil2
<OPTION value="brazil4">brazil4
<OPTION value="nrain">nrain
<OPTION value="water">water
<OPTION value="relief">relief
<OPTION value="prwater">prwater
<OPTION value="massland">massland
</SELECT>

</tr></td>

<tr><td colspan=2>&nbsp;</td></tr>


<tr><td>
<font face="GillSans, Ventana, Arial, Helv">
<I>Output File</I>
</font>

<INPUT TYPE="text" NAME="outputs" SIZE="10" MAXLENGTH="10">

</tr></td>

<tr><td colspan=2>&nbsp;</td></tr>


<tr><td>
<font face="GillSans, Ventana, Arial, Helv">
<I>functions:</I>
</font>

<INPUT NAME="slas" TYPE="radio" VALUE="slope" CHECKED> Slope
<INPUT NAME="slas" TYPE="radio" VALUE="aspect">Aspect

</font>
</tr></td>
<tr><td colspan=2>&nbsp;</td></tr>

<tr><td>
<!---         button 1 ----->
<input type="submit" value="Generate">
</tr></td>


<tr><td>
<!---         button 2----->
<input type="submit" value="Display">
</tr></td>




</table>
</form>
<dir>
<A HREF="javascript:history.back()"><img src="snowfl.gif" height=32 width=32 alt="Back" border=0></A>
</dir>

</BODY>

</HTML>

0
 
LVL 8

Expert Comment

by:jbirk
Comment Utility
OK, I am unsure what the generate button is supposed to do.  Is it performing some calculation on the input fields, or is it supposed to call a cgi program?  And either way, it should be possible with only one button.

If generate is just calling a cgi program, you should be able to make the cgi program return the results to the page for you (it creates a new page).
If you're using javascript to make the calculations, then you can simply use one button and when it's clicked perform the calculations and then continue with the displaying of the data either via CGI or via javascript to a new window or something.

-Josh
0
 

Author Comment

by:nawaf
Comment Utility
The generate button run a cgi program that generate an image. Once the image is produced by an external program, the display button should display it. I know that we can't put 2 submit button but do you have a solution. Thanks
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 8

Expert Comment

by:jbirk
Comment Utility
OK, this is somewhat more complicated, but here comes some brainstorming:

Basically the only way for the cgi program to communicate with your web page is to have it return directly to your page it's results (you could use a hidden frame), or you could write the results to a pre-known file on the server and then access that file from the display button.  The second easier method would work ok in this situation as long as you didn't expect two people to be performing this operation at the same time (which is highly unlikely).  SO, you will probably need to communicate with a hidden frame.  This can get kind of complex.  Also it will probably be easier if you are able to create a new file and put your generated image into that file on your server.  Then send to the hidden frame a web page which includes that image.  Then when the user clicks on display it shows the image however it is that you want it shown.

I just thought of another method that would be simpler if you wouldn't mind a new window popping up to show the image.  Simply using one button, you can target the form to "_blank" causing it to display into a new browser window, and simply return the image in image format directly to that window.  Then when the user is done looking at it, they just close the window.

My only other question is if you know how to do this cgi image generating, because truthfully I don't know how (although I'm interested to learn if I ever get the time).

Well, tell me what you think about the different methods I mentioned in my brainstorming and what would be feasable.
-Josh
0
 

Author Comment

by:nawaf
Comment Utility
can you give a simple example please. Thanks
0
 
LVL 8

Expert Comment

by:jbirk
Comment Utility
A simple example of which method?
What will the cgi program be doing?  Do you have control over the output of the cgi program?

I can make a short example with one of these methods, but it will just be calling a counter program which I wrote (and produces the new image each time).

I don't want to do examples of all of the methods I described, since I don't have the time, but if you pick one I can do it.

-Josh
0
 

Author Comment

by:nawaf
Comment Utility
Yes I understand that you can't give an examples of all  possible methods but I need a solution to try not words. Can you code my posted example ( as you proposed earlier)so I can grade you and finish this . I don't like keeping the evaluation open for so long. Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now