mitochondria
Ventrilo
Follow via Facebook Follow via Twitter Follow via YouTube Follow via RSS Steam Group

Author Topic: Selecting Option Values  (Read 622 times)

Utopi

  • Admin
  • Posts: 971
  • Reputation: +9/-1
    • LD50
Selecting Option Values
« on: Oct 03, 2013, 04:20 PM »
Code: [Select]
<form>
<div data-role="fieldcontain">
    <label for="select-native-1">Scores</label>
    <select name="select-native-1" id="select-native-1">
        <option value="1">Week 1</option>
        <option value="2">Week 2</option>
        <option value="3">Week 3</option>
        <option value="4">Week 4</option>
        <option value="5">Week 5</option>
    </select>
</div>
</form>

Code: [Select]
var weekOne = "You: 43 - Opp: 45";
var weekTwo = "You: 55 - Opp: 52";
$("#select_native_1").click(function(){
var nativeVal = $("#select_native_1 option:selected").val()
if(nativeVal==1){
$("#result").html(weekOne);
}else if(nativeVal==2){
$("#result").html(weekTwo);
}
});

I am trying to select a value like "week 1" and then list a score for that week. Any idea's ratio?
« Last Edit: Oct 03, 2013, 04:22 PM by Utopi »




"There is a fine line between success and failure. In order to succeed, one must learn how to be rid of that line."

Ratio

  • Admin
  • Posts: 1418
  • Reputation: +10/-0
Re: Selecting Option Values
« Reply #1 on: Oct 03, 2013, 04:30 PM »
I'm assuming you're using jQuery. So just glancing at it,

$("#select_native_1").click(function() <- won't work. You're capturing the click, what you want to capture is what it's changed to. In the event structure, clicking on the select box happens before the change, if that makes sense. It should work--sort of--the way it is, but it should update with the current value of the select box not the new value.

Try: $("#select_native_1").change(function()

and see if that de-complicates things.
Happiness is when you play a game so well that people call you a hacker.

There are two types of people in the world, those who can extrapolate from incomplete information.

Ratio

  • Admin
  • Posts: 1418
  • Reputation: +10/-0
Re: Selecting Option Values
« Reply #2 on: Oct 03, 2013, 04:34 PM »
It's probably better to use a switch than an ifelse chain as well.

switch (nativeVal)
{
case 1:
  x="You: 43 - Opp: 45";
  break;
case 1:
  x="You: 55 - Opp: 52";
  break;
case 2:
  x="You: 45 - Opp: 42";
  break;
case 3:
  x="You: 57 - Opp: 54";
  break;
case 4:
  x="You: 45 - Opp: 50";
  break;
case 5:
  x="You: 57 - Opp: 42";
  break;
default:
  x="No value selected.";
}

and then just stick x into the html wherever is appropriate. It's cleaner.
Happiness is when you play a game so well that people call you a hacker.

There are two types of people in the world, those who can extrapolate from incomplete information.

Utopi

  • Admin
  • Posts: 971
  • Reputation: +9/-1
    • LD50
Re: Selecting Option Values
« Reply #3 on: Oct 03, 2013, 04:43 PM »
Well it's for a mobile website using jquery ui. Check out the following link with your a smart phone or ipad then and then go to "Your Team Standings".

http://bitlamp.wctc.edu/~rmudge/js2/Multi-page.html

That is the type of scroll feature I have enabled and you will only see it on a mobile device. If that helps any.


"There is a fine line between success and failure. In order to succeed, one must learn how to be rid of that line."

Ratio

  • Admin
  • Posts: 1418
  • Reputation: +10/-0
Re: Selecting Option Values
« Reply #4 on: Oct 03, 2013, 11:06 PM »
Sorry I didn't get a chance to look at this sooner in a little more detail.

You have screwy names. select-native-1 is not the same as select_native_1. Also, if you just need indexed values, then this is much faster, just remember that the index starts with 0, not 1.

var i= this.selectedIndex

Here's a working fiddle with simplified names: http://jsfiddle.net/VSa2m/2/

/edit

Actually, you probably don't want to use a switch, I was looking at raw code and not how you're using it. The principle is the same, though. A switch is just a faster chain of if else's.
Happiness is when you play a game so well that people call you a hacker.

There are two types of people in the world, those who can extrapolate from incomplete information.

Utopi

  • Admin
  • Posts: 971
  • Reputation: +9/-1
    • LD50
Re: Selecting Option Values
« Reply #5 on: Oct 04, 2013, 04:01 PM »
Yeah, it still isn't working. I think it is somehow conflicting with jquery mobile ui. I am kind of at a loss on what to do.


"There is a fine line between success and failure. In order to succeed, one must learn how to be rid of that line."

Ratio

  • Admin
  • Posts: 1418
  • Reputation: +10/-0
Re: Selecting Option Values
« Reply #6 on: Oct 04, 2013, 05:34 PM »
Fiddle with mobile ui enabled:

http://jsfiddle.net/wQhpy/

Are you sure it isn't just the missing semi-colon?
Happiness is when you play a game so well that people call you a hacker.

There are two types of people in the world, those who can extrapolate from incomplete information.

Utopi

  • Admin
  • Posts: 971
  • Reputation: +9/-1
    • LD50
Re: Selecting Option Values
« Reply #7 on: Oct 05, 2013, 09:27 PM »
I figured out what it was. JSFiddle has a built in wrapper.

So I added:

Code: [Select]
$(document).ready(function()
and it worked like a charm.  ;D

Thanks for the help Ratio.


"There is a fine line between success and failure. In order to succeed, one must learn how to be rid of that line."

 

* Live Streams

Data retrieved in 0.13 seconds.

* Recent Posts

Canderous Ordo Trash Talk by Cates
[Apr 26, 2017, 04:49 PM]


New Voice Communicator...? by Cates
[Apr 26, 2017, 04:49 PM]


Star Citizen by Cates
[Nov 19, 2016, 05:21 AM]


Free Games by Crabbok
[Jul 29, 2016, 11:47 PM]


XCOM 2: LD50 at War! by Yuri
[Jul 14, 2016, 05:17 PM]


Overwatch by Crabbok
[Apr 30, 2016, 04:17 PM]


Disney buys Star Wars by Dargos
[Apr 14, 2016, 04:57 AM]


Free Division Clothing "Gear" Sets by Cates
[Mar 06, 2016, 08:23 PM]


Internet on the Island by Fixate
[Mar 03, 2016, 07:14 AM]


Division pvp by Surrena
[Mar 01, 2016, 01:55 PM]

* Gallery

.

Views: 2242
By: Acorns