/    Sign up×
Community /Pin to ProfileBookmark

Simple function

I feel really, dumb. However, can anybody see why this isn’t working?

[CODE]
<html>
<head>
<title>Test</title>
<script type=”text/javascript”>
function tester(obj) {
var obj2 = obj.value;
document.write(obj2);
}
</script>
</head>
<body>
<select name=”test” id=”test” onChange=”javascript:tester(this);”>
<option></option>
<option value=”test1″>test1</option>
<option value=”test2″>test2</option>
</select>
</body>
</html>
[/CODE]

I’ve been looking at code all day, and I’m sure I’m missing something stupid. Thanks for any help!

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@dfowlerauthorJun 04.2009 — It's fixed, and I don't even want to say why.
Copy linkTweet thisAlerts:
@mataichiJun 04.2009 — There is no "value" property for the Select object.

You would need to do something like this....
[CODE]obj.options[obj..selectedIndex].value;[/CODE]

or

and don't ask why this works, but if all you need is the value from the select object, I believe you can do this from your onchange call.... [CODE]tester(this.value)[/CODE]and it will pass the selected value. I'm 99% sure I've done that before, but not sure why it is any different.
Copy linkTweet thisAlerts:
@mataichiJun 04.2009 — It's fixed, and I don't even want to say why.[/QUOTE]

Come on, share. In case someone else has a similar problem.
Copy linkTweet thisAlerts:
@Angry_Black_ManJun 04.2009 — it works perfectly and without errors. what was it you were expecting it to do?

There is no "value" property for the Select object.[/QUOTE]

not according to the w3
Copy linkTweet thisAlerts:
@Declan1991Jun 04.2009 — [url=http://www.quirksmode.org/js/forms.html#sselect]Quirksmode on Select[/url].

Older browsers (very old) didn't have a value property.
Copy linkTweet thisAlerts:
@astupidnameJun 04.2009 — I wonder if it was the document.write in the head.......
Copy linkTweet thisAlerts:
@Angry_Black_ManJun 04.2009 — Older browsers (very old) didn't have a value property.[/QUOTE]

(extremely highly) unlikely this has any bearing on the OPs situation
Copy linkTweet thisAlerts:
@Declan1991Jun 05.2009 — (extremely highly) unlikely this has any bearing on the OPs situation[/QUOTE]

I agree.
Copy linkTweet thisAlerts:
@axlerick_daathJun 05.2009 — could someone help me?

I m from brazilin....rsss

I have a code, and I need capture first file.....anyone file and send other folder

using one scrpit

here is:

<SCRIPT LANGUAGE="JavaScript">

<!--

myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");

file = myActiveXObject.GetFile("c:source*.*");

file.move("c:out", true);

// -->

</SCRIPT>

I don't know this is correct

Help me...

please
×

Success!

Help @dfowler 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.17,
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,
)...