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

Change list item text

P: 9
Hi

Forgive me if a stupid question but . . .

I have
[HTML]<ul>
<li id='menu1'>MENU ONE</li>
<li id='menu2'>MENU TWIO</li>
<li id='menu3'>MENU ONE</li>
....... etc....
</ul>[/HTML]

and some Javascript

Expand|Select|Wrap|Line Numbers
  1. function updateMenu(item) {
  2.     menuID="menu" + document.theform.which.value;
  3.     document.getElementById(menuID).value=item.value;
  4. }
I have checked menuID & it is correct( 'menu3' )

item.value is also good text

What is wrong ???
Oct 29 '07 #1
Share this Question
Share on Google+
6 Replies


epots9
Expert 100+
P: 1,351
where is the part of the code that calls the "updateMenu" function?
Oct 29 '07 #2

P: 9
Sorry - incomplete submission

the updateMenu is called from an onChange event in a form.

so <input type='text' id='shortform' value='' onChange='updateMenu(this)'>

Further reading seems to imply that the <li> element's value is actually its position in the list.
How can I change the associated text ?
Oct 29 '07 #3

acoder
Expert Mod 15k+
P: 16,027
You could use innerHTML instead.
Oct 29 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Changed the thread title to better describe the problem.
Oct 29 '07 #5

P: 9
Thanks - innerHTML - I just came back to say I had discovered this solution only to find the suggestion waiting here for me !

I embedded <span id='menu1'> ...pure text... </span>
since I have some other stuff within the <li> . . .</li>


Is this cross-browser safe ?
Oct 29 '07 #6

acoder
Expert Mod 15k+
P: 16,027
Yes, though it's not part of the standards, it should work in pretty much all modern browsers.
Oct 29 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.