Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

php change text on tag

Posted on 2012-08-15
5
Medium Priority
?
583 Views
Last Modified: 2012-08-16
by the command and function that I use to change the text on the control

When I click on the button "Edit2"  I want to run a function (it does not matter Is PHP or Java, etc.) and later to change the text on the button   "clicked"


<?php
print("<TABLE id=alternatecolor border=1 cellpadding=9 cellspacing=1 class=hovertable>\n");
print("<TR><TH>ID Klijenta</TH><th>Naziv</th><th>Program</th><th>Size</th><th>Zadnji pristup</th><th>Razmjena podataka</th><th>Baza</th><th>Neplaceno/Deaktiviraj</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
        if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
            print("<tr onmouseover=this.style.backgroundColor='#ffff66'; onmouseout=this.style.backgroundColor='white';><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
            print("<td>");
            print(getkli_db($dirArray[$index]));
            print("</td>");
                print("<td>");
            print("CashPRO");
            print("</td>");
            print("<td>");
            print(filesize("$dire/$dirArray[$index]"));
            print("</td>");
                print("<td>");
               $zadvr = new DirectoryIterator("$dire/$dirArray[$index]");
               $vr=date ("d.m.Y H:i:s.",$zadvr->getATime()) ;
            print($vr);
            print("</td>");
                $idd="idom$index";
               
                print("<td ><button  id=.$dirArray[$index]. name=..$dirArray[$index]. align=right style=\"display:show\">Edit2</button></td>");
                 print("<td><a href=onlincli.php?idbr=$dirArray[$index]>");
            print(baza($dirArray[$index],0));
            print("</td>");
                 print("<td><a href=\"$dirArray[$index]\">");
            print(gasi("$dire/$dirArray[$index]",0));
            print("</td>");
            print("</TR>\n");
      }
}
print("</TABLE>\n");
 
?>
0
Comment
Question by:cnermin
5 Comments
 
LVL 8

Expert Comment

by:Barry62
ID: 38298872
OK, here you go:

<script type="text/javascript">
function runThisFunction(buttonid){
  document.getElementById(buttonid).value = "clicked";
}
</script>
<?php
print("<TABLE id=alternatecolor border=1 cellpadding=9 cellspacing=1 class=hovertable>\n");
print("<TR><TH>ID Klijenta</TH><th>Naziv</th><th>Program</th><th>Size</th><th>Zadnji pristup</th><th>Razmjena podataka</th><th>Baza</th><th>Neplaceno/Deaktiviraj</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
        if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
            print("<tr onmouseover=this.style.backgroundColor='#ffff66'; onmouseout=this.style.backgroundColor='white';><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
            print("<td>");
            print(getkli_db($dirArray[$index]));
            print("</td>");
                print("<td>");
            print("CashPRO");
            print("</td>");
            print("<td>");
            print(filesize("$dire/$dirArray[$index]"));
            print("</td>");
                print("<td>");
               $zadvr = new DirectoryIterator("$dire/$dirArray[$index]");
               $vr=date ("d.m.Y H:i:s.",$zadvr->getATime()) ;
            print($vr);
            print("</td>");
                $idd="idom$index";
               
                print("<td ><button  id=.$dirArray[$index]. name=..$dirArray[$index]. align=right style=\"display:show\" onclick=\"runThisFunction($dirArray[$index])\">Edit2</button></td>");
                 print("<td><a href=onlincli.php?idbr=$dirArray[$index]>");
            print(baza($dirArray[$index],0));
            print("</td>");
                 print("<td><a href=\"$dirArray[$index]\">");
            print(gasi("$dire/$dirArray[$index]",0));
            print("</td>");
            print("</TR>\n");
      }
}
print("</TABLE>\n");
 
?> 

Open in new window

0
 

Author Comment

by:cnermin
ID: 38298931
Thanks for the attempt


I already tried but it does not work when the table.
This is PHPcod that you can immediately try to copy / paste


<script type="text/javascript">
function runThisFunction(buttonid){
  document.getElementById(buttonid).value = "clicked";
}
</script>
<?php
$indexCount=4;
print("<TABLE id=alternatecolor border=1 cellpadding=9 cellspacing=1 class=hovertable>\n");
print("<TR><TH>ID Klijenta</TH><th>Naziv</th><th>Program</th><th>Size</th><th>Zadnji pristup</th><th>Razmjena podataka</th><th>Baza</th><th>Neplaceno/Deaktiviraj</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
          // don't list hidden files
            print("<tr onmouseover=this.style.backgroundColor='#ffff66'; onmouseout=this.style.backgroundColor='white';><TD><a href=''>test</a></td>");
            print("<td>");
            print('bla');
            print("</td>");
            print("<td>");
            print("CashPRO");
            print("</td>");
            print("<td>");
            print('ble');
            print("</td>");
            $idd1="idom$index";
            print("<td ><button id=$idd1 name=$idd1 align=right><a href=javascript:runThisFunction($idd1)>Edit</button></td>");
            $idd="idom$index";
            print("<td ><button id=$idd name=$idd align=right onclick=runThisFunction($idd)>Edit2</button></td>");
            print("<td><a href=onlincli.php?idbr=e>");
            print('fg');
            print("</td>");
            print("<td><a href=\"\">");
            print('ff');
            print("</td>");
            print("</TR>\n");
     
}
print("</TABLE>\n");
 
?>
0
 
LVL 45

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 38299681
You can't use:

document.getElementById(buttonid).value = "clicked";

because you're button doesn't have a 'value' attribute. You need to change the text using innerHTML:

document.getElementById(buttonid).innerHTML = "clicked";
0
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38299690
Also, in the code above, your first button has an <A> inside it. Remove that, and set the onClick on the button

print("<td ><button id=$idd1 name=$idd1 align=right onclick=runThisFunction($idd1)>Edit</button></td>");
print("<td ><button id=$idd name=$idd align=right onclick=runThisFunction($idd)>Edit2</button></td>");

Open in new window

0
 
LVL 49

Expert Comment

by:Roonaan
ID: 38299828
First, try to get rid off all the print statements. Rather go out of php mode, and only wrap your vars in php:

<?php 

?>
<table id="alternatecolor" border="1" cellpadding="9" cellspacing="1" class="hovertable">
<tr>
	<TH>ID Klijenta</TH>
	<th>Naziv</th>
	<th>Program</th>
	<th>Size</th>
	<th>Zadnji pristup</th>
	<th>Razmjena podataka</th>
	<th>Baza</th>
	<th>Neplaceno/Deaktiviraj</th>
</tr>

<?php
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
	if (substr($dirArray[$index], 0, 1) == ".") {
		// don't list hidden files
		continue;
	}
	?>
	<tr onmouseover=this.style.backgroundColor='#ffff66'; onmouseout=this.style.backgroundColor='white';>
		<td><a href="<?=htmlspecialchars($dirArray[$index])?>"><?=htmlspecialchars($dirArray[$index])?></a></td>
		<td><?=getkli_db($dirArray[$index]))?></td>
		<td>CashPRO</td>
		<td><?=filesize($dire . DIRECTORY_SEPARATOR . $dirArray[$index]))?></td>
                <td><?php
			$zadvr = new DirectoryIterator($dire . DIRECTORY_SEPARATOR . $dirArray[$index]);
			$vr=date ("d.m.Y H:i:s.",$zadvr->getATime()) ; 
			echo $vr;
		?></td>
		<td >
			<button
				id=".<?=htmlspecialchars($dirArray[$index])?>."
				name="..<?=htmlspecialchars($dirArray[$index])?>."
				align="right"
				style="display:show"
				onclick="this.innerHTML='clicked';"
				>Edit2
			</button>
		</td>
		<td>
			<a href=onlincli.php?idbr=<?=htmlspecialchars($dirArray[$index])?>">
				<?=baza($dirArray[$index],0))?>
			</a>
		</td>
		<td>
			<a href="<?=htmlspecialcahrs($dirArray[$index])?>">
            			<?=gasi("$dire/$dirArray[$index]",0))?>
			</a>
		</td>
	</tr>
	<?php
      }
}
print("</TABLE>\n");
 
?>

Open in new window


The either use a direct onclick handler in your html output, or leverage a framework like jquery (http://www.jquery.com)

Regards

-r-
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question