user3355795
user3355795

Reputation: 1

append is not working in jquery

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<body >


   <button onclick="me('${message}');">hello</button>
<div id="play">

</div>
<div id="p">

</div>

</body>
<script type="text/javascript">

   function me(mes)
   {

       switch(mes){
       case 'Knowing our Numbers':



        $("#p").append("<object id='objViewer' name='f'  classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='550' height='400' id='intro to elianas website' align='middle'>"+
                "<param name='allowScriptAccess' value='sameDomain' />"+
                "<param name='movie' width=400px height=400px value='test1.swf' />"+
                "<param name='quality' value='high' />"+
                "<param name='bgcolor' value='#1C140D' />"+
                "<EMBED  src='test1.swf' WIDTH='400px' HEIGHT='400px' quality='high' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' NAME='intro' id='player' autostart='false'  allowScriptAccess='sameDomain' ShowControls='1' ShowStatusBar='0' ShowDisplay='0' ></EMBED><br/></object>"
                );
          alert(mes);     

       break;
       case 'Whole Numbers':
           alert(mes);
        break;      

           }

}


</script>

</html>

in the above code i am trying to append the html code in case statement but it is not working .how can i use the html code inside the case statement and based on that i need play the video

Thanks in advance

Upvotes: 0

Views: 125

Answers (5)

Krish R
Krish R

Reputation: 22741

You have passed ${message} as string, but in your switch statement there is no case string related to that. That is the reason,

<button onclick="me('${message}');">hello</button>
                    ^^^^^^^^^^^^^

Try this,

 <button onclick="me('Knowing our Numbers');">hello</button>

Also, You need to load jquery library in this page.

Upvotes: 1

Chetan Gawai
Chetan Gawai

Reputation: 2401

Try this

<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.9.1.min.js "></script><!--added-->

</head>

<body >


   <button onclick="me('Knowing our Numbers');">hello</button><!--edited-->
<div id="play">

</div>
<div id="p">

</div>

</body>
<script type="text/javascript">

   function me(mes)
   {

       switch(mes){
       case 'Knowing our Numbers':


// 
        // $("#p").append("<object id='objViewer' name='f'  classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='550' height='400' id='intro to elianas website' align='middle'>"+
                // "<param name='allowScriptAccess' value='sameDomain' />"+
                // "<param name='movie' width=400px height=400px value='test1.swf' />"+
                // "<param name='quality' value='high' />"+
                // "<param name='bgcolor' value='#1C140D' />"+
                // "<EMBED  src='test1.swf' WIDTH='400px' HEIGHT='400px' quality='high' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' NAME='intro' id='player' autostart='false'  allowScriptAccess='sameDomain' ShowControls='1' ShowStatusBar='0' ShowDisplay='0' ></EMBED><br/></object>"
                // );
               $("#p").append("hiii");
          alert(mes);     

       break;
       case 'Whole Numbers':
           alert(mes);
        break;      

           }

}


</script>

</html>

Upvotes: 0

Govind Singh
Govind Singh

Reputation: 15490

its seems you didn't include any jquery libary so either include a jquery library to use .append() you can download it from http://jquery.com/download/ or you can also do the same thing with simple javascript .

document.getElementById('p').innerHTML+="<object id='objViewer' name='f'  classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='550' height='400' id='intro to elianas website' align='middle'>"+
                    "<param name='allowScriptAccess' value='sameDomain' />"+
                    "<param name='movie' width=400px height=400px value='test1.swf' />"+
                    "<param name='quality' value='high' />"+
                    "<param name='bgcolor' value='#1C140D' />"+
                    "<EMBED  src='test1.swf' WIDTH='400px' HEIGHT='400px' quality='high' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' NAME='intro' id='player' autostart='false'  allowScriptAccess='sameDomain' ShowControls='1' ShowStatusBar='0' ShowDisplay='0' ></EMBED><br/></object>";

Upvotes: 0

CJ Ramki
CJ Ramki

Reputation: 2630

append() is the method of jquery library. To use this method you need to load jQuery library in your html page. If you want to use without jQuery library try this below code.

var div = document.getElementById('p');
div.innerHTML = div.innerHTML + "<object id='objViewer' name='f'  classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='550' height='400' id='intro to elianas website' align='middle'>"+
                "<param name='allowScriptAccess' value='sameDomain' />"+
                "<param name='movie' width=400px height=400px value='test1.swf' />"+
                "<param name='quality' value='high' />"+
                "<param name='bgcolor' value='#1C140D' />"+
                "<EMBED  src='test1.swf' WIDTH='400px' HEIGHT='400px' quality='high' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' NAME='intro' id='player' autostart='false'  allowScriptAccess='sameDomain' ShowControls='1' ShowStatusBar='0' ShowDisplay='0' ></EMBED><br/></object>";

or you can use like this also,

document.getElementById('p').innerHTML+="<object id='objViewer' name='f'  classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='550' height='400' id='intro to elianas website' align='middle'>"+
                    "<param name='allowScriptAccess' value='sameDomain' />"+
                    "<param name='movie' width=400px height=400px value='test1.swf' />"+
                    "<param name='quality' value='high' />"+
                    "<param name='bgcolor' value='#1C140D' />"+
                    "<EMBED  src='test1.swf' WIDTH='400px' HEIGHT='400px' quality='high' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' NAME='intro' id='player' autostart='false'  allowScriptAccess='sameDomain' ShowControls='1' ShowStatusBar='0' ShowDisplay='0' ></EMBED><br/></object>";

Upvotes: 2

Rahul Desai
Rahul Desai

Reputation: 15501

.append() is a function from the jQuery library. So, you need to include jQuery in your code. Also, make sure to include the .append() function inside $(document).ready() function.

Make sure to read this for a quick overview on jQuery.

Upvotes: 0

Related Questions