NameSilo

How to: Form functions

Spacemail by SpaceshipSpacemail by Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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
•••
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
•••
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
•••
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
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back