/    Sign up×
Community /Pin to ProfileBookmark

simple javascript variable in function

function select(exID)
{
document.inputform.select.value=exID;
show(‘select_’.exID.”);
}

Here is my simple function. On line 3, I’m trying to pass a variable along with a little text into the function, but I’m having little luck. In PHP, I would accomplish this by saying:

show(‘select_’.$exID.”);

For some reason, this isn’t working (probably because I know crap about JS). Halp?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERNov 23.2007 — [code=php]
show('select_'.exID.'');
[/code]

This is not a syntax I recognize:

Try this:
[code=php]
alert('exID = '+exID);
[/code]

or
[code=php]
alert(document.getElementById('exID').value);
[/code]

to see what's going on.

Might also want to post a little more of the calling HTML code

to see how the element 'select_???' has been defined.

If it's a select box, you will need to reference differently.
[code=php]
var obj = document.getElementById('exID');
alert('Show: '+obj.option[obj.selectedIndex].value)
[/code]
Copy linkTweet thisAlerts:
@ifm1989authorNov 23.2007 — edit:

this worked:

show('select_' + exID);
Copy linkTweet thisAlerts:
@JMRKERNov 24.2007 — Glad I could help.

Good Luck!
×

Success!

Help @ifm1989 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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