Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 10th, 2007, 07:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , NY, USA.
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default onChange Event

Hi All,

I am using the "onChange" event in <SELECT> tag.

When I pick the first item in the drop down list, the "onChange" event fires. But if I pick the same item again, it doesn't fire.

I believe this is the normal process.

But, how I can make it work?

Thanks for your help,:)

<HTML>
<HEAD>
    <script language=javascript>
    function ShowValue()
    {
   alert(form1.DD1.value);
    }

    </script>
</HEAD>

<BODY>

<form name=form1>
    <select name=DD1 onChange="javascript:ShowValue()">
        <option value=1>Item 1</option>
        <option value=2>Item 2</option>
        <option value=3>Item 3</option>
    </select>
</form>

</BODY>
</HTML>

MCinar

Love all the creatures because of the creator.
__________________
MCinar

Love all the creatures because of the creator.
Reply With Quote
  #2 (permalink)  
Old May 10th, 2007, 11:28 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well what do you expect, onchange fires when there's a selection change? Perhaps you can use onclick and see which is the selectedIndex and then show the value. (Using DD1.value directly is IE only.)

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old May 10th, 2007, 04:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , NY, USA.
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Joe.
I have already tried "onClick" event. It didn't work. Everytime I click on the dropdown list, it calls the function. It doesn't give you chance to change the options.

MCinar

Love all the creatures because of the creator.
Reply With Quote
  #4 (permalink)  
Old May 10th, 2007, 04:24 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think you need to explain what exactly you're trying to achieve.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old May 10th, 2007, 08:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , NY, USA.
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Joe,

What I am trying to allow the users to be able to pick the same option on the drop down list without selecting the other options in order to call the JavaScript function.

Let's say;
A user picks ITEM 1 which calls a function.
Then, the user picks ITEM 1 again which should call the same function.

Thanks for your help.

MCinar

Love all the creatures because of the creator.
Reply With Quote
  #6 (permalink)  
Old May 10th, 2007, 10:29 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok. I understand what you WANT to do but your current throught process isn't going to get you there.

The web is a stateless medium and the only way we know when to do "something" is when the user does something that we can detect (an event). When I select an option from a dropdown the onChange event is fired and, until i change my selection, that event is never going to get fired again for that dropdown. This is your short coming.

What I think your best approach would be is something like this:

User selects item 1 --> This raises a JavaScript Function --> Write the value to a div, store the value in a variable, create text boxes on the fly whatever --> Reset the index of the select list back to 0 --> Repeat.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #7 (permalink)  
Old May 11th, 2007, 02:18 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show why the onclick doesn't work? When the user clicks on an option you run the function associated with that option. Alternatively don't use a select, use a column of buttons.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #8 (permalink)  
Old May 11th, 2007, 08:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , NY, USA.
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Doug. It is a helpful Information. I will try it.

MCinar

Love all the creatures because of the creator.
Reply With Quote
  #9 (permalink)  
Old May 11th, 2007, 08:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , NY, USA.
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Joe. Because of the <SELECT> tag, onClick works for the first item.
I need to use <SELECT> tag.

MCinar

Love all the creatures because of the creator.
Reply With Quote
  #10 (permalink)  
Old May 11th, 2007, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , NY, USA.
Posts: 141
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Doug, if you don't mind of sending me a sample code. Thanks.

MCinar

Love all the creatures because of the creator.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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
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
OnChange Event Doesn't Execute JLJones13 Javascript How-To 1 August 22nd, 2003 02:15 PM



All times are GMT -4. The time now is 02:13 AM.


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