/    Sign up×
Community /Pin to ProfileBookmark

Onclick is not working inside the document.write in javascript

getvalue function is not calling when executing onclick .

Below i have pasted my code. can any one help me what is the problem for my code.

<html>
<head>

<script type=”text/javascript”>

function getvalue()
{
alert(“done”)
}

function fun()
{

document.write(‘<select>’);
document.write(‘<option value=”SELECT COMPONENT”>–SELECT COMPONENT–</option>’)
document.write(‘<option value=”SELECT PACKAGE”>SELECT PACKAGE</option>’)
document.write(‘<option value=”CHECK_DETAILS”>CHECK DETAILS</option>’)
document.write(‘<option value=”INDEX_PACKAGE”>INDEX_PACKAGE</option>’)
document.write(‘<option value=”INDEX_INDEXER”>INDEX_INDEXER</option>’)
document.write(‘</select>’)
document.write(‘<input type=”submit” value=”submit” onClick=”getvalue()”/>’)
}
</script>
</head>

<body>

<input type=”submit” value=”GO” onClick=”fun()”;

</body>
</html>

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 02.2009 — 1) That's neither a valid HTML nor XHTML document.

2) You seem to be mixing HTML with XHTML. Stick to HTML and omit those trailing "/" things in your empty tags.

3) In SCRIPT, and STYLE, elements the stopping point of the element is defined to be the ETAGO, "</". You need to write that as "</".

4) JavaScript follows the Java naming conventions. See http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html .

5) document.write is depricated--and doesn't work in XHTML. Better to use DOM methods.

6) document.write, when first called after the page loads, clears the document ad starts with a clean slate. Your "fun" function is overwriting your "getvalue" function when executed. Better to use DOM methods.
×

Success!

Help @sundarsece 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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