Jump to content

[SOLVED] text box without form?


Yeodan

Recommended Posts

Ya know never thought of doing that before.

But it does work :)

a simple example

<?php
$tp=$_SERVER['PHP_SELF'];
if(isset($_GET['data']))
$data=htmlspecialchars($_GET['data'])
?>
<a href="<?php echo $tp; ?>?data=<?php echo urlencode("The quick fox jumped over the lazy dog"); ?>">Lazy Dog</a><br />
<a href="<?php echo $tp; ?>?data=<?php echo urlencode("I'm a little teapot short and stout"); ?>">Tea Pot</a><br />
<textarea name='data'><?php if(isset($data)) echo $data; ?></textarea>

 

Note the use of urlencode, to encode my data for usage in a url.

 

Hi there :-)

 

You don't actually need any PHP to do this. There's a couple of ways you could do it.

 

Firstly, you could just add an onclick handler to a text link that takes the value from the textarea, like so:

 

<textarea id="myData">This is the data</textarea>
<a href="#" id="nextPageLink">Go to next page</a>

<script type="text/javascript">
  document.getElementById('nextPageLink').onclick = function(){
    document.location = 'page.php?myData='
                      + document.getElementById('myData').value
                      + '&someOtherValue=whatever';
  };
</script>

 

Or you could do the same thing in a form and add a handler to a text link to submit the form, like so:

 

<form name="myForm" action="page.php" method="GET">
  <textarea name="myData">This is the data</textarea>
  <input type="hidden" name="someOtherValue" value="whatever"/>
  <a href="#" id="nextPageLink">Go to next page</a>
</form>

<script type="text/javascript">
  document.getElementById('nextPageLink').onclick = function(){
    document.myForm.submit();
  };
</script>

 

Personally I prefer the second method. If you add anything to the form later on: you don't have to change the JavaScript to make the value be carried to the next page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.