0
#!/bin/sh

echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '</head>'
echo '<body><center><br><h3 align='center'>STATUS</h3></br></center>'
list=$(ls -l /tmp | grep "^d" | awk -F" " '{print $9}')
list1=$(echo $list | wc -w)
i=1
while [ $i -le $list1 ]
do
    bhai=$(echo $list | cut -d' ' -f$i)
    echo '<a href="#" onclick="myFunction(); return false;" id="movie" style="font-size: 30px; text-decoration: none; margin-left: 1cm">'$bhai'</a></font><br>'
    i=$((i+1))
done
echo '
    <script type="text/javascript">
        function myFunction () {
            var mtype = document.getElementById("movie").text;
        alert("Hi");
        alert(mtype);
        }
    </script>'
echo '</body></html>'
exit 0

This code basically displays the folders list in the directory and because of href attribute all directories becomes a link. If I click on that link it should open that directory and display folders of selected directory.
This code displays the only first directory, if I click on any link, alert gives me name of first directory only.

 var mtype = document.getElementById("movie").text;

I am new in this, please help me in this.
Thanks in advance

Vishal Rabadiya
  • 495
  • 5
  • 24

2 Answers2

1

Try document.getElementById("movie").text;

or if you want to print your variable try

 echo '<a href="#" onclick="myFunction(); return false;" id="movie" style="font-size: 30px; text-decoration: none; margin-left: 1cm">$bhi</a><br>';

skip the single quotes before and after $bhai

function myFunction () {
    var mtype = document.getElementById("movie").text;  
    alert("Hi");
    alert(mtype);
}
<a href="#" onclick="myFunction(); return false;" id="movie" style="font-size: 30px; text-decoration: none; margin-left: 1cm">'$bhai'</a></font>
Aravindh Gopi
  • 2,083
  • 28
  • 36
0

Please use innerHTML. see code snippet below

function myFunction () {
    var mtype = document.getElementById("movie");
    alert("Hi");
    alert(mtype.innerHTML);
}
<a href="#" onclick="myFunction(); return false;" id="movie" style="font-size: 30px; text-decoration: none; margin-left: 1cm">'$xyz'</a></font>
Kannan J
  • 508
  • 5
  • 12