/    Sign up×
Community /Pin to ProfileBookmark

Problem with OnChange on form select ?

Hi

I’m having a bit of a problem.

I have a form select that triggers a Ajax function like this:

[CODE]<select name=”SongName” onchange=”
if (this.value==’new songname’)
{UpdateTracklist(‘put in a new song’);}
ELSE
{UpdateTracklist(‘an already existing song’);}”>

<option value=”new songname”>new song</option>
<option value=”some title”></option>
<option value=”another title”></option>
and so on[/CODE]

What I need it to do is to do something when the option new songname is selected and something else then an already existing title from the list is selected.

If I just write <select name=”SongName” onchange=”
UpdateTracklist(‘an already existing song’);”>
Then it works fine and the song is put in the database.

But when I put in the IF ELSE codes the thing about ‘new songname’ works but the thing about an already existing song suddently doesn’t work.

So it works seperately but when put together it is only the codes before the ELSE statement that works ?

is there anyone who can see what I’m doing wrong ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@toicontienMar 14.2008 — This doesn't work?
[CODE]<select name="SongName" onchange="
if (this.value=='new songname')
{UpdateTracklist('put in a new song');}
[B]else if (this.value == 'another title')[/B]
{UpdateTracklist('an already existing song');}">

<option value="new songname">new song</option>
<option value="some title"></option>
<option value="another title"></option>
and so on[/CODE]
Copy linkTweet thisAlerts:
@MichaelHeauthorMar 15.2008 — No.. that doesn't work either..

But if I remoave the first IF so I just write:
[CODE]<select name="SongName" onchange="
if (this.value == 'another title')
{UpdateTracklist('an already existing song');}">

<option value="new songname">new song</option>
<option value="some title"></option>
<option value="another title"></option>
and so on[/CODE]


Then it works...

It's like it doesn't get past the first IF statement.
×

Success!

Help @MichaelHe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...