Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2011, 07:48 AM   PM User | #1
victor.gatto
New to the CF scene

 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
victor.gatto is an unknown quantity at this point
Thumbs up Text Field Depending on Radio Options.

PHP Code:

this is php with javascript running
<br /><br />


<
script type="text/javascript">
function 
makeChoice()
{
var 
val 0;
for( 
0document.form1.accno.lengthi++ )
{
if( 
document.form1.accno[i].checked == true )
{
val document.form1.accno[i].value;
if(
val=='cedu')
{
document.form1.otherChoice.disabled=false;
document.form1.otherChoice.focus();
}
else
{
document.form1.otherChoice.disabled=true;
}
}
}
}
</script>


<body onload="document.form1.otherChoice.disabled=true">
<form name="form1" action="#" method="post">
<tr>

<td>
<input type="radio" name="accno" value="1" onclick="makeChoice();" />
Yes<input type="radio" name="accno" value="cedu" onclick="makeChoice();"/>
No</td>
</tr>
<tr
<td><br />Global Account Number:</td>
<td><input type="text" name="otherChoice" />
</td>
</tr>
</form> 
victor.gatto is offline   Reply With Quote
Old 09-28-2011, 07:35 PM   PM User | #2
hyperionXS
New to the CF scene

 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
hyperionXS is an unknown quantity at this point
And your question is?
Anyway, here is an optimised version of your code
PHP Code:
<script type="text/javascript"
function 
makeChoice(select)
{
    if(
select)
    { 
        
document.form1.otherChoice.disabled=true
    }
    else
    { 
        
document.form1.otherChoice.disabled=false
        
document.form1.otherChoice.focus(); 
    }

</script>

<body onload="makeChoice(0)"> 
<form name="form1" action="#" method="post"> 
    <tr> 
        <td> 
            <input type="radio" name="accno" value="1" onclick="makeChoice(1)" /> Yes
            <input type="radio" checked="checked" name="accno" value="cedu" onclick="makeChoice(0)"/> No
        </td> 
    </tr>
    <tr>
        <td>
            <br />Global Account Number:
        </td> 
        <td>
            <input type="text" name="otherChoice" /> 
        </td>
    </tr>
</form> 
hyperionXS is offline   Reply With Quote
Old 09-29-2011, 04:39 AM   PM User | #3
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,427
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
Actually, hyperionXS, this forum is for people to post working snippets of code, not code they need help with specifically.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary
https://alexvincent.us/blog
Alex Vincent is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:25 PM.


Advertisement
Log in to turn off these ads.