Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 November 12th, 2004, 02:47 PM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default .onchange Event Handling Help GRRR!

Ok, I started a new job with a computer sales company. This company uses flashecom for its web service (no idea why they just didnt have the programmer they had develop their site). Anyway, this web template hosting does not give complete access through coding.

When I started I had to sift through the old programmers code, because he left NOOOO documentation AHH!

This is the question, does the .onchange event handling have to be triggered in some way to work?

SCENARIO:
Web page with a bunch of select objects, none of which have onchange events already built.
<select name="asdasd">
  <option value="1">option1</option>
  <option value="2">option2</option>
</select>

These are all over the page.

The old programmer decided to over-ride this so he can add dynamic images depending on the value, by doing this.
<script language="javascript">
  var SelectItems = document.body.getElementsByTagName('select');

  for (var i=0; i < SelectItems.length; i++)
  {
    SelectItems[i].onchange = "javascript:optionSelected(this)";
  }
</script>

Later in the code is the optionSelected(elmnt) function that does the obvious image swapping code. I can create that image swapping stuff, but my problem is, when writing my own code, I practically used the same code, but it does not work for me. I changed the for loop inner code to just a simple:
  alert(SelectItems[i].name);
Now this does present me with the names of the select objects, but the onchange event does not work for me, although it does for his code. I have also tried .onChange, and nothing happens still. There is no error, but nothing happens.

I was wondering if there was some sort of trigger that must be activated. What I mean by this, is like, if you wanted to return the value of an items left position.
  var obj = getElementById('item_chosen');
  alert(obj.style.left);
This will not work unless when you created the object you used:
  <table style="position:absolute;left=1px;top:1px;">

I hope someone can understand my problem will all the junk i've typed lol, please help! THis is frustrating me (><)
 
Old November 12th, 2004, 04:32 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Perhaps replace the onchange assignement line with this?

SelectItems[i].onchange = function() { openSelected(this); };

-Snib
Where will you be in 100 years?
Try new FreshView 0.2!
 
Old November 12th, 2004, 04:42 PM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok... It works just how I want it using the method you suggested, so I'm half happy now lol.

I can continue with what I was going to do now, the only thing thats bugging me now is how the old programmer was able to do it the way that I stated and I couldnt. "Anything you can do..." concept ;p

Anyway, that you so much Snib you're a life saver! XD






Similar Threads
Thread Thread Starter Forum Replies Last Post
SqlDependency OnChange Event ghari ASP.NET 2.0 Professional 1 July 30th, 2008 03:01 PM
onChange event mcinar HTML Code Clinic 3 May 24th, 2007 08:46 PM
onChange Event mcinar Javascript 11 May 11th, 2007 09:38 AM
how to use onchange event of dropdownlist check_007 ASP.NET 2.0 Professional 2 February 16th, 2007 02:57 AM
Event:OnChange catchrohith Classic ASP Basics 0 November 3rd, 2006 12:52 AM





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