javascript - How to take the value of a clicked event on another page or div in PHP? -


i want echo value of clicked event in div, don't know logic should use in function changecolor().

<fieldset class="step">                 <legend>roti</legend>                 <?php                 $qu = mysql_query("select * submenu menu_id=33") or die(mysql_error());                 while($f = mysql_fetch_array($qu)){                 ?>                 <p>                     <label for="name" onclick="changecolor(this)"><?php echo $f['submenu']; ?></label>                     <script>                         function changecolor(obj){                             obj.style.color = "red";                         }                      </script>                     </p>                 <?php } ?> </fieldset> 

you can use javascript's innerhtml method this.

<p>     <label for="name" onclick="changecolor(this)"><?php echo 'somename'; ?></label> </p>     <div id="target_div"></div>     <script>     function changecolor(obj){         obj.style.color = "red";         var selected_val = obj.innerhtml;         document.getelementbyid('target_div').innerhtml= selected_val;     }     </script> 

edit: show selected labels' text in div, append below

<p> <label for="name" onclick="changecolor(this)"><?php echo 'somename 1'; ?></label> <label for="name" onclick="changecolor(this)"><?php echo 'somename 2'; ?></label> <label for="name" onclick="changecolor(this)"><?php echo 'somename 3'; ?></label> <label for="name" onclick="changecolor(this)"><?php echo 'somename 4'; ?></label> </p> <div id="target_div"></div> <script> function changecolor(obj){     obj.style.color = "red";     var selected_val = obj.innerhtml;     document.getelementbyid('target_div').innerhtml=document.getelementbyid('target_div').innerhtml+" "+selected_val; } </script> 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -