Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Simple Javascript question

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

user-7256

VIP Member
Impact
111
Hi all,

Quick JS question: how can I get a submit button to be DISABLED as the <body> loads, then ENABLE it when a function in a script.js file is called by another event?

I have something sort of laid out, but it just doesn't work... can anyone offer me an example? Internet searches have yielded little help :(

Thanks!
-Matt
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I think following code will help

-----------------------------------------------------
<HTML>
<HEAD>

<script type="text/javascript">
<!--

function ChangeStatus(val) {
frm=document.forms[0]
if(val=="enable")
{frm.Button1.disabled=false}
if(val=="disable")
{frm.Button1.disabled=true}
}
// -->
</script>


</HEAD>
<BODY TEXT="000000" BGCOLOR="FFFFFF">

<form>
<div align="center">
<select name="select" onChange="ChangeStatus(this.value)">
<option value="disable">Disable Button 1</option>
<option value="enable">Enable Button 1</option>
</select>
</div>
<p align="center">
<input type=button onClick="alert('Button 1 pressed!')" value="Button 1" name="Button1">

<script type="text/javascript">
<!--
ChangeStatus("disable");
// -->
</script>
</form>
</BODY>
</HTML>
--------------------------------------------

Here how it works, first you define a function with the javascript that enables and disables a button, which I named as ChangeStatus, later in the html part after your form part there comes a smal javascript code which calls ChangeStatus and says disable this button, this allows you to start page with a disabled button.

And the dropdown usage, calls ChangeStatus with enable and disable values to activate and disactivate the button. Instead of a dropdown, simply you can integrate it to another event, depends on your usage.

Hope it helps :)
 
Last edited:
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back