Solved

button type updates textarea?

Posted on 2012-03-12
6
324 Views
Last Modified: 2012-03-19
I need to use a button to update a textarea.

I can update textboxes using javascript called on a button click:

html: <input type='button' id='submit' value='submit' onclick='ex()'>

javascript: document.getElementById("field").value="<?php  echo $_SESSION['value']; ?>";

However, the textarea can only be updated by using a submit and embedded php:

 <textarea name="test1" rows="20" cols="80" >
     <?php if (isset($_FILES['files']))    
     $rawoutput=passthru($program);} ?>
</textarea>

How can I have the textarea updated by the button click event?
0
Comment
Question by:pillmill
6 Comments
 
LVL 7

Accepted Solution

by:
micropc1 earned 500 total points
ID: 37713064
You need to assign an id to the textarea...

 <textarea name="test1" id="test1" rows="20" cols="80" >
     <?php if (isset($_FILES['files']))    
     $rawoutput=passthru($program);} ?>
</textarea>

then you can do it the same way..

javascript: document.getElementById("test1").value="<?php  echo $_SESSION['value']; ?>";
0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 37713938
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
 
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
 
<script type='text/javascript'>//<![CDATA[
$(function(){
$("#stash").hide();

$("#submit").click(function() {

    $("textarea[name=test1]").val($("#stash").val());

});
});//]]>  

</script>

</head>
<body>
  <input type='button' id='submit' value='submit' />

<textarea name="test1" rows="20" cols="80" >
</textarea>

<textarea id="stash">
     <?php if (isset($_FILES['files']))    
     $rawoutput=passthru($program);} ?>
</textarea>

</body>
</html>
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37714112
www.laprbass.com/RAY_temp_pillmill.php
<?php // RAY_temp_pillmill.php
error_reporting(E_ALL);
var_dump($_GET);
?>
<form name="foo">
<textarea name="wilma" id="bar"></textarea>
<input type="button" id="loader" value="load" onClick="javascript:document.getElementById('bar').value='Loaded'; return TRUE;" />
<input type="button" id="dumper" value="dump" onClick="javascript:document.getElementById('bar').value='Dumped'; return TRUE;" />
<input type="submit" value="Send Textarea" />
</form>

Open in new window

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:pillmill
ID: 37727025
Thanks for the suggestions, but none work.

Ray, I modified your program. Why doesn't the php to return
the $_GET values - "dumpget" - work ?

<?php // RAY_temp_pillmill.php
error_reporting(E_ALL);
var_dump($_GET);
?>
<form name="foo">
<textarea name="wilma" id="bar"></textarea>
<input type="button" id="loader" value="load" onClick="javascript:document.getElementById('bar').value='Loaded'; return TRUE;" />
<input type="button" id="dumper" value="dump" onClick="javascript:document.getElementById('bar').value='Dumped'; return TRUE;" />
<input type="button" id="dumper" value="dumpget" onClick="javascript:document.getElementById('bar').value='<?php var_dump($_GET);?>'; return TRUE;" />
<input type="submit" value="Send Textarea" />
</form>[/code]

Open in new window

0
 
LVL 7

Expert Comment

by:micropc1
ID: 37727109
You may want to try doing a search and replace on var_dump to remove any special java characters....single and double quotes especially.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37727320
I looks OK to me, in that it does exactly what the HTTP specifications call for.  It may be somewhat confused by the use of unescaped quotes and apostrophes, but that is the sort of output you have to expect from PHP diagnostic functions like var_dump().  They are not designed to produce a JSON string or HTML-safe form controls.  

This may not be exactly what you want, but I do not see anything that is wrong.  You may want to change the duplicate id attribute.  You can only have one of those on each document.

What are you trying to achieve?  If you can describe it in non-technical terms we may be able to help.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 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