Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

button type updates textarea?

Posted on 2012-03-12
6
330 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

791 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