Jump to content

[SOLVED] Using a radio button to set focus for text area


realjumper

Recommended Posts

Hi,

 

My form has several radio buttons and text area's. The user is only able to enter text into one area, which is determined by which radio button is clicked. I have this sorted out and working just fine. However, it would be very nice to set the focus on the appropriate text area as well, to help the user. I can't seem to get this working. Here is a sample of my code....

 


<table class="fbt" border="0">
   <tr>
        <td><b>Cash: </b></td>
        <td> <input type="radio" name="finance_type" value="Cash" onclick="document.requisition.order_num.disabled = true;document.requisition.payable_to.disabled = true"></td>
    </tr>
    <tr>
        <td><b>Order Form: </b></td>
        <td> <input type="radio" name="finance_type" value="Order Form" onclick="document.requisition.order_num.disabled = false;document.requisition.payable_to.disabled = true">    Order Number (if known): <span style="margin-left:10px;"><input type="text" class="input-box" size="40" name="order_num" disabled="disabled"></span></td>
    </tr>
    <tr>
        <td><b>Cheque: </b></td>
        <td> <input type="radio" name="finance_type" value="Cheque"  onclick="document.requisition.order_num.disabled = true;document.requisition.payable_to.disabled = false">    Payable to: <span style="margin-left:89px;"><input type="text" class="input-box" size="40" name="payable_to" disabled="disabled"></span></td>
    </tr>
</table>

 

So what's happening here is this: If the user clicks the 'Cheque' radio button, then he may enter data into the 'payable_to' field. If the user clicks the  'Order Form' radio button, then he may enter data into the 'order_num' field.

 

You can see that I have disabled the fields so that a user cannot (for example) enter data into the 'order_num' field unless they have clicked the 'Order Form' radio button. The same goes for the 'Cheque' radio button and the 'apyable_to' field.

 

What I want to do is to go a step further and set the focus on the appropriate field. So if the user clicks the 'Cheque' field radio button, the focus is set to the 'payable_to' field. If the user clicks the 'Order Form' radio button, the focus is set to the 'order_num' field.

 

I am on the brink of solving this ( I think) but I need some help for this last step please.

 

Many thanks  :)

Link to comment
Share on other sites

Never mind.....I got it! Always seem to get the answer after I ask lol!!

 


<td><b>Order Form: </b></td>
<td> <input type="radio" name="finance_type" value="Order Form" onclick="document.requisition.order_num.disabled = false;document.requisition.order_num.focus();document.requisition.payable_to.disabled = true">    Order Number (if known): <span style="margin-left:10px;"><input type="text" class="input-box" size="40" name="order_num" disabled="disabled"></span></td>
  </tr>
   <tr>
<td><b>Cheque: </b></td>
<td> <input type="radio" name="finance_type" value="Cheque"  onclick="document.requisition.order_num.disabled = true;document.requisition.payable_to.disabled = false;document.requisition.payable_to.focus()">    Payable to: <span style="margin-left:89px;"><input type="text" class="input-box" size="40" name="payable_to" disabled="disabled"></span></td>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.