NameSilo

How to: Form functions

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

ynned

New Member
Impact
0
I was wondering if anybody here could tell me how to make a form where the submit button is inactive until the user selects a certain radio button. For example, a user agreement form that has yes and no radio buttons and a submit button that is inactive until the user selects yes. All help is appreciated. Thanks...
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Can easily be done in javascript.

Place the following code between your <head> and </head> tags:

HTML:
<script language="javascript">

function enableField()
{
document.nameofyourform.submit.disabled=false;
}
 
</script>

Example form:

HTML:
<form name="nameofyourform" method="POST" action="">
Yes: <input name="yes" type="radio" onClick=enableField();>
<br>
No: <input name="no" type="radio">
<br>
<input type="submit" value="Submit" name="submit" disabled="true">
</form>

B-)
 
Last edited:
0
Close
SWEET!!! Thanks a lot, man.

EDIT: Crap. I did something wrong, I think. It's not working. I pasted both codes into the page where you said, and it's still allowing them to continue on if they choose No. I should probably mention that I'm something of a newb when it comes to this stuff.
 
Last edited:
0
Close
Are you using the example form I gave you or your own?

If it's your own, check where it says:
HTML:
document.nameofyourform.submit.disabled=false;


In your form, whatever the name is you need to update the javascript code with that name where it says .nameofyourform.
If your form has no name.. give it a name by adding name="form1" to the <form> tag.

So then, if you name the form "form1"
The Javascript would need to be...

HTML:
<script language="javascript"> 

function enableField() 
{ 
document.form1.submit.disabled=false; 
} 

</script>

Understand? :)
 
0
Close
Yeah, I had that part entered correctly. I copy/pasted the form name into your code where it said "nameofyourform" but it still gave me the error. I'm still not sure why it didn't work. I ended up Googling it and found the answer on a German forum. Here is what I did to fix it:

Code:
<script language="javascript">

function enableField(submit)
{
document.getElementById('submit').disabled=false;
}
 
</script>
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back