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

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min