By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,797 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,797 IT Pros & Developers. It's quick & easy.

Change input field w/o page refresh

P: n/a

I've been unsuccessfully attempting to write a method in Javascript to
change an input field from TEXT to SELECT when a user selects (or
unselects) a radio button. In my frustration I have been searching the
web but have also come up empty handed on any documentation that
discribes how to do this. Is what I'm trying to do just not possible??
Thanks,
Chris S.
--
Chris S
------------------------------------------------------------------------
Chris S's Profile: http://www.highdots.com/forums/m1368
View this thread: http://www.highdots.com/forums/t3073037

Nov 6 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Chris S wrote:
I've been unsuccessfully attempting to write a method in Javascript to
change an input field from TEXT to SELECT when a user selects (or
unselects) a radio button. In my frustration I have been searching the
web but have also come up empty handed on any documentation that
discribes how to do this. Is what I'm trying to do just not possible??


Put both elements into the source HTML and have one enabled and visible
by default and the other not visible and disabled. Then if a checkbox
is selected, swap which is hidden & disabled and shown & enabled.
<script type="text/javascript">

function toggleControls()
{
var cont;
for (var i=0, len=arguments.length; i<len; ++i){
cont = arguments[i];
if (cont.style){
if ('none' == cont.style.display){
cont.style.display = '';
cont.disabled = false;
} else {
cont.style.display = 'none';
cont.disabled = true;
}
}
}
}
</script>

<form action="">
<input type="checkbox" onclick="
toggleControls(this.form.textA, this.form.selA);
">Check to toggle input/select<br>
<input type="text" name="textA">
<select name="selA" style="display: none;" disabled>
<option>option A
<option>option B
<option>option C
</select>
</form>
--
Rob
Nov 6 '05 #2

P: n/a
Chris S said the following on 11/6/2005 1:12 PM:
I've been unsuccessfully attempting to write a method in Javascript to
change an input field from TEXT to SELECT when a user selects (or
unselects) a radio button. In my frustration I have been searching the
web but have also come up empty handed on any documentation that
discribes how to do this. Is what I'm trying to do just not possible??


No, it's not possible. But you can emulate it. Search the archives for
dynamically creating form elements. Basically you remove the current
input, create a new input, append it to the form.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 6 '05 #3

P: n/a

Thanks for the tips!

Chris S.
--
Chris S
------------------------------------------------------------------------
Chris S's Profile: http://www.highdots.com/forums/m1368
View this thread: http://www.highdots.com/forums/t3073037

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.