Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-05-2003, 02:11 AM   PM User | #1
loomer
New Coder

 
Join Date: May 2003
Location: Toronto
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
loomer is an unknown quantity at this point
Triggering onChange/Dropdown

Another problem...

I have a double combo box working fine with javascript. What I would like to do is to be able to select/change the first combo box from a menu or from somewhere besides actually choosing an item in the drop down menu.

The problem is that when I got to change it using the DOM the second combo box is NOT updating it's value the way it should be. The function for the combo box is originally called using the onChange="function(this)" command.

Is there a way to trigger the onChange somehow? Whenever I send a value into the function directly the second combo box never updates.

Here's the function:

function productselected(elem){
for (var i = document.f1.productLine.options.length; i >= 0; i--){
document.f1.productLine.options[i] = null;


Any help would be greatly appreciated. Thanks.
loomer is offline   Reply With Quote
Old 06-05-2003, 03:20 AM   PM User | #2
cheesebagpipe
Regular Coder

 
Join Date: Nov 2002
Posts: 596
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebagpipe is an unknown quantity at this point
You can call an HTML event handler explicitly:

ref_to_select.onchange();

Hard to tell if this is helpful.
cheesebagpipe is offline   Reply With Quote
Old 06-05-2003, 03:39 AM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
or after changing the select, call the onchange function manually.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 06-05-2003, 04:02 AM   PM User | #4
loomer
New Coder

 
Join Date: May 2003
Location: Toronto
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
loomer is an unknown quantity at this point
The problem I'm having is the form originally uses:

onChange="function(this)";

and I'm not sure exactly what value 'this' is sending to the function so I'm not sure what value to send. I'm trying all kinds of different combinations but with no success.
loomer is offline   Reply With Quote
Old 06-05-2003, 04:06 AM   PM User | #5
cheesebagpipe
Regular Coder

 
Join Date: Nov 2002
Posts: 596
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebagpipe is an unknown quantity at this point
http://www.codingforums.com/showthre...threadid=21118

It's not a value - it's the Select object. Did you try calling it explicitly (above)?
cheesebagpipe is offline   Reply With Quote
Old 06-05-2003, 04:47 AM   PM User | #6
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
functionToCall(document.formName.selectName)
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 06-05-2003, 04:55 AM   PM User | #7
loomer
New Coder

 
Join Date: May 2003
Location: Toronto
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
loomer is an unknown quantity at this point
I was able to grab some help and I think the problem is solved. I'll post the script so other people can use it if they run into the same problem.

I really do appreciate your help and patience though Cheesebagpipe and Glenngv.

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!--
function see(sel) {
alert(sel.value)
}
function activateOnChange() {
var s = document.forms["ff"].elements["ss"]
s.fireEvent("onchange")
}
// -->
</script>
</head>
<body>

<form action="" name="ff">
<select onchange="see(this)" name="ss">
<option value="111">aaaaa</option>
<option value="222">bbbbb</option>
</select>
<a href="#" onclick="activateOnChange()">Activate onChange</a>
</form>
</body>
</html>
loomer is offline   Reply With Quote
Old 06-05-2003, 03:44 PM   PM User | #8
cheesebagpipe
Regular Coder

 
Join Date: Nov 2002
Posts: 596
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebagpipe is an unknown quantity at this point
You're using IE-only DHTML behaviors. With so many ways to do this, why choose a proprietary one?
cheesebagpipe is offline   Reply With Quote
Old 06-05-2003, 04:33 PM   PM User | #9
loomer
New Coder

 
Join Date: May 2003
Location: Toronto
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
loomer is an unknown quantity at this point
Yikes.. I didn't realize that..

Okay.. I did try calling the function using your syntax above:

document.f1.alloy.onChange();

which came back with an error.

I also tried calling the function and passing in a value as Glenngv suggested but also had no luck:

alloyselected(document.f1.alloy);

I feel like a damn moron.. Obviously I'm looking for a non-browser specific answer. The way I got the previous IE only function to call was to put it in the onLoad handler so each time the page is refreshed it will automatically do it.. and that seemed to work fine.

I'm baffled and frustrated (as I'm sure you are with my babbling )..
loomer is offline   Reply With Quote
Old 06-05-2003, 05:29 PM   PM User | #10
cheesebagpipe
Regular Coder

 
Join Date: Nov 2002
Posts: 596
Thanks: 0
Thanked 0 Times in 0 Posts
cheesebagpipe is an unknown quantity at this point
Look, you babbling moron ( )

document.f1.alloy.onchange();

If that don't cut it, post some of the relevant code, along with some more moronic babbling...
cheesebagpipe is offline   Reply With Quote
Old 06-05-2003, 05:50 PM   PM User | #11
loomer
New Coder

 
Join Date: May 2003
Location: Toronto
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
loomer is an unknown quantity at this point
LOL..

[BABBLE]

a sense of humour is becoming the only thing keeping me going.

Okay.. I think what you just gave me is working.. I'm sure I tried that at some point during my 16 hours of coding yesterday.. But of course what actually happened past hour 12 is anybody's guess.

.EDIT.

Netscape = bad.. Now that IE works fine.. It's on to tackle Netscape which should be next to impossible . .. crap

[/BABBLE]

Last edited by loomer; 06-05-2003 at 07:33 PM..
loomer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:42 AM.


Advertisement
Log in to turn off these ads.