473,785 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change input field w/o page refresh


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
3 5257
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.l ength; i<len; ++i){
cont = arguments[i];
if (cont.style){
if ('none' == cont.style.disp lay){
cont.style.disp lay = '';
cont.disabled = false;
} else {
cont.style.disp lay = '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>optio n A
<option>optio n B
<option>optio n C
</select>
</form>
--
Rob
Nov 6 '05 #2
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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 6 '05 #3

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
21029
by: JohnSouth104 | last post by:
Hi I want to warn the user that changing the selected item in a pull-down will clear some data he has already entered in a file download box. I've tried using confirm() to return true or false with a line such as: onchange="return(confirm('proceed Yes or No')))" but it always stops the change.
3
2628
by: coffee_man | last post by:
Hi, I have a page with a form. This form has an input field <textarea>. I use it to have my users enter text and on form submit it gets inserted into a db. Initially there is some standard text shown in the <textarea> ("please type comments here"). The user types some text, _doesn't_ do a submit, continues to work. Only when he's finished working, he does a submit. It's a time-tracking system so it also keeps track of start and endtimes....
2
4397
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a separate unbound form with all the fields, which are on the subform. The fields are filled in with data programmatically. User edits. Edited fields are copied into fields on the subform programmatically as well. I need to catch change in one of...
4
26203
by: N. Graves | last post by:
Hello... thank you for your time. I have a form that has a List box of equipotent records and a sub form that will show the data of the equipment select from the list box. Is it possible to make a change in the name field in the details, then refresh the list box with new name? Please help and thanks!
15
4779
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
4
22571
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for the table at the top of the table but the field names currently are 'field1' etc, so how do I rename the field names to the fields on the top row of the table. Cheers,
2
3388
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given field(s). The popping-up seems to work just fine; it's the tearing down that's giving me grief. If I stick a onmouseout event on the same input field that caused the onmouseover/pop-up, it starts to flicker 'cos the <divis placed for esthetically...
3
4323
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in the text field remains empty. The page containing this problem is at the following location: http://www.skicow.com/component/option,com_skicow/act,shop/Itemid,51/debug_enabled,true The last parameter enables debug which results in alerts...
2
2257
by: malcster2 | last post by:
hello, i am a beginner to ajax. i have created a mysql database, which i would like to access from a web page. i have created 3 files, a html to display the data, a php file to extract the data, and a javascript file to to the clever stuff. when i access the html page, all the data is displayed correcty, but if i add or delete any records, and press the button i have created to refresh the data(without reloading), the data doesn't change....
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.