473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to change one element to another?

I would like to have an element, a text string, change into a select
when a mouseover occurs and then change back to text when a selection is
made or when a mouse out occurs. I looked a t using dojo for this,
http://dojotoolkit.org, but this will end up on a production server,
where dojo is not installed and cannot be installed. So, I need another
solution. Can someone give some pointers on how this might be done?
TIA
Aug 21 '06 #1
2 2528
Lorenzo Thurman wrote:
I would like to have an element, a text string, change into a select
when a mouseover occurs and then change back to text when a selection is
made or when a mouse out occurs. I looked a t using dojo for this,
http://dojotoolkit.org, but this will end up on a production server,
where dojo is not installed and cannot be installed. So, I need another
solution. Can someone give some pointers on how this might be done?
TIA
Do you know the contents of the select list ahead of time? If so, there's no call for AJAX here.

Something like this should do the trick:

<div onmouseover="ShowSelect(this);">
<span>The Original Text</span>
<select name="PostbackName" onchange="ChangeText(this)" style="display: none;">
<option value="The Original Text">The Original Text</option>
<option value="Some Other Text">Some Other Text</option>
<option value="Yet Another Option">Yet Another Option</option>
</select>
</div>

And the script:

function ShowSelect(div)
{
//hide the span and show the select box
div.getElementsByTagName("span")[0].style.display = "none";
div.getElementsByTagName("select")[0].style.display = "";
}

function ChangeText(select)
{

var span = select.parentNode.getElementsByTagName("span")[0];

//remove text from the span
while(span.childNodes.length 0)
span.removeChild(span.childNodes[0]);

//add the select box's text to the span
span.appendChild(document.createTextNode(select.op tions[select.selectedIndex].value));

//show the span and hide the select box
select.style.display = "none";
span.style.display = "";
}
Note that you MUST include the value attribute of the option tags, or (in IE) you will be unable to get the value of the option without a big fat hassle.

Jeremy

Aug 21 '06 #2
Jeremy wrote:
Lorenzo Thurman wrote:
>I would like to have an element, a text string, change into a select
when a mouseover occurs and then change back to text when a selection
is made or when a mouse out occurs. I looked a t using dojo for this,
http://dojotoolkit.org, but this will end up on a production server,
where dojo is not installed and cannot be installed. So, I need
another solution. Can someone give some pointers on how this might be
done?
TIA

Do you know the contents of the select list ahead of time? If so,
there's no call for AJAX here.

Something like this should do the trick:

<div onmouseover="ShowSelect(this);">
<span>The Original Text</span>
<select name="PostbackName" onchange="ChangeText(this)"
style="display: none;">
<option value="The Original Text">The Original Text</option>
<option value="Some Other Text">Some Other Text</option>
<option value="Yet Another Option">Yet Another Option</option>
</select>
</div>

And the script:

function ShowSelect(div)
{
//hide the span and show the select box
div.getElementsByTagName("span")[0].style.display = "none";
div.getElementsByTagName("select")[0].style.display = "";
}

function ChangeText(select)
{

var span = select.parentNode.getElementsByTagName("span")[0];

//remove text from the span
while(span.childNodes.length 0)
span.removeChild(span.childNodes[0]);

//add the select box's text to the span
span.appendChild(document.createTextNode(select.op tions[select.selectedIndex].value));
//show the span and hide the select box
select.style.display = "none";
span.style.display = "";
}
Note that you MUST include the value attribute of the option tags, or
(in IE) you will be unable to get the value of the option without a big
fat hassle.

Jeremy
Thanks, this almost seems easy!
Aug 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
6
by: Csaba2000 | last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text Size)? This is just for use on IE 5.5+, but it would be great if there was a...
4
by: Richard Trahan | last post by:
(This is a repost -- the original got tucked away into an old thread because I used the same Subject name.) I'm trying to change the document title to add an asterisk when the document becomes...
7
by: User | last post by:
Hi, A page I have shows a different background colour depending on the hash portion of the url as it is first loaded. For example a link to mysite/mypage#0000FF would result in a page with a blue...
19
by: chee.k.cheng | last post by:
Hi, I'm wondering if it is possible to change the starting address of a structure element. For example, I have the following structure: struct demo { char digit; char alpha; } an;
8
by: patrizio.trinchini | last post by:
Hi All, I'would like to write an XSL transformation that changes the value of the atribute of a given element according to the value of another atttribute of the same element. For instance,...
6
by: Jakob Bieling | last post by:
Hi, I want to move an element from a std::list to the end of the same list. To get this done, I thought I'd just do something like: std::list <intlst; lst.push_back (0); lst.push_back (1);...
5
by: yhlove | last post by:
Hi I'm trying to change element in xml file as described below: the xml file: ---------------- <MyProg> <Path>test1</Path> </MyProg>
2
by: Stephen Durkin | last post by:
I have some javascript to rearrange a list of elements... 1) Each element (div) is initially given a unique id, the same id of the database record the element represents. 2) User "moves" element...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.