Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2005, 01:04 PM
Authorized User
 
Join Date: Nov 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ophillip
Default abusing innerHTML

I am tring to write a function that can handle tasks for mutliple tables. I have a button's onlcick event calling the function and passing the name of the table to the function like so:

<BUTTON ID="LexmarkSelect" onclick=mySelect("Lexmark") style="font-size=8pt">

When I call the function I build a variable to address the button like this:

function mySelect(TableName)
{
var ButtonName = ("SubmitPO." + TableName + "Select")
.....

BUT when I try to use ButtonName with innerHTML it bombs:

   (ButtonName).innerHTML=("Select None");

I have tried several variations, including an alert box as troubleshooting, the following alert boxes return 'undefined':

alert(ButtonName.innerHTML);
alert((ButtonName).innerHTML);

Is this idea even close to something that will actually work? Or am I wasting my time?
 
Old July 20th, 2005, 02:10 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you have one, and only one, button named "SubmitPOLexmarkSelect" then to access it you need:
Code:
var oButton = document.getElementsByName("SubmitPOLexmarkSelect");
I believe getElementsByName returns a collection if there are more than one elements with that name or just an object if not but it's a long time since I used it. If it fails try:
Code:
var oButton = document.getElementsByName("SubmitPOLexmarkSelect")[0];
--

Joe (Microsoft MVP - XML)
 
Old July 20th, 2005, 06:58 AM
Authorized User
 
Join Date: Nov 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ophillip
Default

The problem is that I have more than one button on the page. That is why I was trying to make the code a little more dynamic. There are three buttons, refferencing three different tables. My alternative is to use three blocks of similar code; one function for each button, but i was trying to keep the code small since each button does a similar function.
 
Old July 21st, 2005, 02:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You appear to have misunderstood, what I meant was that as long as the names are unique you can do:
Code:
function getButtonFromTableName(TableName)
{
  var sButtonName = ("SubmitPO." + TableName + "Select");
  var oButton = document.getElementsByName(sButtonName)[0];
  //alert(oButton.value); //For testing
  return oButton
}

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using innerHTML adfranklin BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 0 April 13th, 2007 01:13 AM
Getting InnerHtml ghari Javascript 3 January 3rd, 2005 12:06 PM
innerHTML interrupt Javascript How-To 6 July 22nd, 2004 02:18 PM
innerHTML problem higgsy Javascript How-To 2 August 7th, 2003 07:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.