Back to feed
Renewal·서른의 생활코딩

Sample source 3) JavaScript basic document structure (user-defined function _ parameter _ application)

NS
normalstory
cover image

Let's apply parameters once.
Applying it to the background-color-changing example we showed earlier might be even more helpful.

If you run the example you'll see —
whereas the previous example only changed the background, 
this revised code now shows a different value in the popup window every time.





<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />




<title> User-defined function 5. (parameter 2) </title>



<script type="text/javascript">


//<!CDATA[


//parameter / values placed in parentheses so the function can receive them




function bg_change(c,n)


{


document.bgColor=c;


alert(n);


}


//]]]]]]>


</script>




</head>






<body>




<form method="post" action="">


<p>


<input type="button" value="reset" onclick="bg_change('white',1)" />


<input type="button" value="red" onclick="bg_change('red',2)" />


<input type="button" value="yellow" onclick="bg_change('yellow',3)" />


<input type="button" value="green" onclick="bg_change('green',4)" />


</p>


</form>




</body>




</html>

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Why You Should Use .html Instead of .md Seeing Is Believing

Jul 25, 2026·1 min
Renewal

The Most Important Thing About AX

Jul 17, 2026·2 min
Renewal

디지털 기술과 혁신에 대한 논고(지탱하는 힘)

Jul 17, 2026·5 min