Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disable submit button if some variable > 0 2

Status
Not open for further replies.

CMcC

Programmer
Feb 5, 2002
196
US
Hello all.


I have two asp pages:
Calculation.asp
Result.asp

Result.asp is included in Calculation.asp by:
%>
<!--#INCLUDE FILE="results.asp"-->
<%

How can I have the submit button on Results.asp disabled by default, and enable (activate / unhide) it only if a specific asp variable (from Calculation.asp) > 0 ?

As it is now, my form and submit button is like this:

Code:
<form id="NameForm" name="NameForm" action="dqSearch.asp" onsubmit = 'return check_form("<%= amountdue %>")'>
      <input type="submit" value="Click to Pay" name="submit1" style ="LEFT: 203px; WIDTH: 350px; TOP: 1px; HEIGHT: 24px" size="21" />
      <input hidefocus="hidefocus" name="DataSearch"  value ="<%  =ordernum %>" style="VISIBILITY: hidden" />
    </form>
There is another variable called <% =Amountdue %> ( as is <% =ordernum )% that is passed to Results.asp from Calculation.asp. This is the variable that I need to check to see if it is greater than 0.

I created a couple of scripts:
Code:
<SCRIPT language=javascript>

function window_onload() {
     document.NameForm.Submit1.disabled = true; 
</SCRIPT>

<body onload="window_onload();">

Code:
<script language="JavaScript">

function check_form() {
var amount2pay    

// everything is ok 

if (amount2pay > 0) {
alert ("Nothing Due") ;
 return false;
 }
else {
 return true ;
 }   
}
</script>
This doesnt appear to work, just allows users to go to DQsearch.asp. I dont want users to be albe to click this submit button if
Code:
<%= amountdue %> > 0

Any suggestions would be strongly appreciated! thanks so much.
 
If you have all the values to be able to know that the submit button should not be displayed, then dont even write the HTML for the button to the Response.

[tt]
<%
If ShowButton = True Then
%>
<input type="submit" name="btnSubmit" value="Click Me!">
<%
End If
%>
[/tt]
 
Hi Sheco.

The button is predermined and placed on the page in a specific spot and is there before any data is passed to this asp page.


Would it be better to not show the entire form instead of trying to disable the submit?

Cmcc
 
Ok - Im getting confused.

So should I put something like:

<script language="javascript" type="text/javascript">
function Check_data()
{
if {
(<%=amountdue %> <= 0) // variable known at onload of
// asp page
{
document.Nameform.submit1.disabled=true; // disable the submit button

}
else
{
document.Nameform.submit1.enabled=true; // enable the submit button
}
}
</script>

Then call something like

window.onload = check_data()

Thanks again.
Cmcc
 
cmc,
wherever the button's place is on the html code, just wrap this around it:
Code:
<% if some_number > 0 then %>
<input type="submit" name="btnSubmit" value="Click Me!">
<% end if %>
actually you don't need to check for show-button to be true.
i have done this many times.

 
Hi jfDabiri -

so given the variable as above (<%=amountdue%>)

the code would be something like this?
Code:
<% if '<%=amountdue%>' > 0 then %>
<input type="submit" name="btnSubmit" value="Click Me!">
<% end if %>
 
I dont understand why something so simple is giving me such a hard time.

Ive done this and get an error:
Code:
 <% if "<%=amountdue%>" > 0 then %>

<input type="submit" value="Click to Pay" name="submit1" style ="LEFT: 203px; WIDTH: 350px; TOP: 1px; HEIGHT: 24px" size="21" />

<% end if %>


I get this error:
Microsoft VBScript compilation error '800a0409'

Unterminated string constant

/dev/results.asp, line 383

if "<%=amountdue
----------------^

What is the syntax for this?? I cannot find it anywhere.

thanks again.
Cmcc
 
All variables called and used in this asp page ( results.asp
) must be referenced with <%= varname%> - and this is throwing errors when trying to wrap that around the input tag.
Not sure quite how to proceed.
Cmcc
 
Why are you using ASP tags inside of ASP tags?
Code:
<% if "[red][b]<%=[/b][/red]amountdue[red][b]%>[/b][/red]" > 0 then %>

Lee
 
Why are you using ASP tags inside of ASP tags?
Code:
<% if "<%=amountdue%>" > 0 then %>
I might ask the same question about the quotes. Also unnecessary....

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
Hi guys...Thanks to both. See, I guess I got confuesed, as I have several pages included within each other and wasnt quite sure what the syntax was from one to the other.
I tried and it worked:

<% if amountdue > 0 then %>

<input type="submit" value="Click to Pay" name="submit1" style ="LEFT: 203px; WIDTH: 350px; TOP: 1px; HEIGHT: 24px" size="21" />

<% end if %>

Thanks a bunch. I will start with the core variable first and work out form there.
Cmcc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top