Avatar of pranjallad
pranjallad

asked on 

Pass the list box selected value in onchange event

I have to pass the two select box selected value in the functions which are called on onchange method.
The this. is passing the value.But how to pass other select box selected value in first select box function?
I am having two list boc as below
<SELECT NAME="sport_type" id="sport_type" onClick="xajax_processForm(this.options[this.selectedIndex].value,'3');return false;">
<option>-----Sports------</option>
<option value="/V2/index.php?sport_type=1">NFL</option>
<option value="/V2/index.php?sport_type=13">CFB</option>
<option value="/V2/index.php?sport_type=18">CFL</option>
<option value="/V2/index.php?sport_type=3">NBA</option>
<option value="/V2/index.php?sport_type=4">CBB</option>
<option value="/V2/index.php?sport_type=8">WNBA</option>
<option value="/V2/index.php?sport_type=5">MLB</option>
<option value="/V2/index.php?sport_type=7">NHL</option>
<option value="/V2/index.php?sport_type=all">All Sports</option>
</SELECT></td><td>&nbsp;</td>
<td><SELECT NAME="pick_type" id="pick_type" onClick="xajax_processForm('MLB',this.options[this.selectedIndex].value);return false;">
<option>-----Select------</option>
<option value="/V2/index.php?pick_type=3">3-Teamers</option>
<option value="/V2/index.php?pick_type=4">4-Teamers</option>
<option value="/V2/index.php?pick_type=5">5-Teamers</option>
<option value="/V2/index.php?pick_type=6">6-Teamers</option>
<option value="/V2/index.php?pick_type=7">7-Teamers</option>
<option value="/V2/index.php?pick_type=8">8-Teamers</option>
<option value="/V2/index.php?pick_type=9">9-Teamers</option>
<option value="/V2/index.php?pick_type=10">10-Teamers</option>
</SELECT>

Open in new window

PHPJavaScriptScripting Languages

Avatar of undefined
Last Comment
Michel Plungjan
Avatar of margajet24
margajet24
Flag of Singapore image

have you tried this?..

document.getElementById("sport_type").Value

document.getElementById("pick_type").Value
Avatar of pranjallad
pranjallad

ASKER

yes I tried doing this...but its not working...
Avatar of Michel Plungjan
.Value is incorrect - .value is better
onClick is wrong, it is as you said onChange you want

So is this what you want?

 onChange="xajax_processForm(this.options[this.selectedIndex].value,this.form.pick_type.options[this.form.pick_type.selectedIndex].value,3)"

and I do not see why you want to return false, unless you copied the code from a link or a button click
and on the other

onChange="xajax_processForm(this.form.sports_type.options[this.form.sports_type.selectedIndex].value,this.options[this.selectedIndex].value,3)"
Avatar of hielo
hielo
Flag of Wallis and Futuna image

copy and paste this:
<SELECT NAME="sport_type" id="sport_type" onchange="xajax_processForm(this.value, document.getElementById('pick_type').value);return false;">
<option value="">-----Sports------</option>
<option value="/V2/index.php?sport_type=1">NFL</option>
<option value="/V2/index.php?sport_type=13">CFB</option>
<option value="/V2/index.php?sport_type=18">CFL</option>
<option value="/V2/index.php?sport_type=3">NBA</option>
<option value="/V2/index.php?sport_type=4">CBB</option>
<option value="/V2/index.php?sport_type=8">WNBA</option>
<option value="/V2/index.php?sport_type=5">MLB</option>
<option value="/V2/index.php?sport_type=7">NHL</option>
<option value="/V2/index.php?sport_type=all">All Sports</option>
</SELECT></td><td> </td>
<td><SELECT NAME="pick_type" id="pick_type" onchange="xajax_processForm(document.getElementById('sport_type').value, this.value);return false;">
<option value="">-----Select------</option>
<option value="/V2/index.php?pick_type=3">3-Teamers</option>
<option value="/V2/index.php?pick_type=4">4-Teamers</option>
<option value="/V2/index.php?pick_type=5">5-Teamers</option>
<option value="/V2/index.php?pick_type=6">6-Teamers</option>
<option value="/V2/index.php?pick_type=7">7-Teamers</option>
<option value="/V2/index.php?pick_type=8">8-Teamers</option>
<option value="/V2/index.php?pick_type=9">9-Teamers</option>
<option value="/V2/index.php?pick_type=10">10-Teamers</option>
</SELECT>

Open in new window

Sorry Hielo.
My suggestion will work in more browsers
Why use DOM access inside the form???

And why return false.

It looks like point poaching now.
Avatar of pranjallad
pranjallad

ASKER

Hi,
Now what is happening .
If i do like this

<option value="">-----Sports------</option>
<option value="/V2/index.php?sport_type=1">NFL</option>
<option value="/V2/index.php?sport_type=13">CFB</option>
<option value="/V2/index.php?sport_type=18">CFL</option>
<option value="/V2/index.php?sport_type=3">NBA</option>
<option value="/V2/index.php?sport_type=4">CBB</option>
<option value="/V2/index.php?sport_type=8">WNBA</option>
<option value="/V2/index.php?sport_type=5">MLB</option>
<option value="/V2/index.php?sport_type=7">NHL</option>
<option value="/V2/index.php?sport_type=all">All Sports</option>
 

<option value="">-----Select------</option>
<option value="/V2/index.php?pick_type=3">3-Teamers</option>
<option value="/V2/index.php?pick_type=4">4-Teamers</option>
<option value="/V2/index.php?pick_type=5">5-Teamers</option>
<option value="/V2/index.php?pick_type=6">6-Teamers</option>
<option value="/V2/index.php?pick_type=7">7-Teamers</option>
<option value="/V2/index.php?pick_type=8">8-Teamers</option>
<option value="/V2/index.php?pick_type=9">9-Teamers</option>
<option value="/V2/index.php?pick_type=10">10-Teamers</option>

Means passing hard coded value it runs very fine.
You can check below link
http://www.parlaycalculator.com/V2/index_ajax.php.
But if i am passing runtime values by this.value or document... it doesnt work.
Can you suggest where i am going wrong.
If the parms you pass are numbers, then you need the values of the select to also be numbers
<SELECT NAME="sport_type" id="sport_type"
onchange="xajax_processForm(this.options[this.selectedIndex].value,this.form.pick_type.options[this.form.pick_type.selectedIndex].value)">
<option value="">-----Sports------</option>
<option value="1">NFL</option>
<option value="13">CFB</option>
<option value="18">CFL</option>
<option value="3">NBA</option>
<option value="4">CBB</option>
<option value="8">WNBA</option>
<option value="5">MLB</option>
<option value="7">NHL</option>
<option value="all">All Sports</option>
</SELECT></td><td> </td>
<td><SELECT NAME="pick_type" id="pick_type" 
onchange="xajax_processForm(this.form.sports_type.options[this.form.sports_type.selectedIndex].value,this.options[this.selectedIndex].value)">
<option value="">-----Select------</option>
<option value="3">3-Teamers</option>
<option value="4">4-Teamers</option>
<option value="5">5-Teamers</option>
<option value="6">6-Teamers</option>
<option value="7">7-Teamers</option>
<option value="8">8-Teamers</option>
<option value="9">9-Teamers</option>
<option value="10">10-Teamers</option>
</SELECT>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of pranjallad
pranjallad

ASKER

Thanks a lot
I have applied the above code and now its working fine.
Thanks
Avatar of hielo
hielo
Flag of Wallis and Futuna image

>>Sorry Hielo. My suggestion will work in more browsers
Agree

>>Why use DOM access inside the form???
1. There's absolutely nothing wrong with using DOM
2. "have you tried this?...yes I tried doing this...but its not working..." Just "fixed" the Value to value

>>And why return false.
Because I'm not perfect - oversight.

>>It looks like point poaching now.
The problem was opened, I began and aswering and had to leave for an extended period of time. Did not see your post. So, No, that was not the case.
Ok, Understood

@pranjallad: Did http:#22048393 work for you? If so, please accept as solution
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo