Find services - Property in Bulgaria - Find jobs - Credit Card - Debt Consolidation

PDA

View Full Version : If input type text not null must check radio button


Fracisc
Feb 26th 2009, 8:37 am
I have a text box where people enter the title of a book.
If a title is entered the MUST choose if they are the author or not.

I don`t know how to do the MUST part.

If the "title" box is empty they have nothing to do with the radio buttons.

If "title" is there, they must choose if they are "author" or "not author".

It would be great if we could also show the radio buttons only if a title is entered.

siothach
Feb 26th 2009, 8:45 am
I think the script you want is similiar to Toggle Additional Info (http://javascriptbank.com/javascript/form/checkbox-radio/toggle-additional-info/detail/en/)

Fracisc
Feb 26th 2009, 9:22 am
I checked that but dunno how to use it....

camjohnson95
Feb 26th 2009, 2:47 pm
Below is a simple example of how this is done, other validation can be done during the server-side processing.


<input type="text" id="txtTitle" onkeyup="textChange();"/><br />
<table id="buttons" style="visibility: hidden;">
<tr><td>
<input type="radio" name="isAuthor" value="is" />Author<br />
<input type="radio" name="isAuthor" value="isnt" checked />Not Author<br />
</td></tr>
</table>
<script type="text/javascript" >
function textChange() {
if (txtTitle.value == "")
buttons.style.visibility = "hidden";
else
buttons.style.visibility = "visible";
setTimeout("textChange()",2500);
}
</script>