Yeodan Posted June 2, 2009 Share Posted June 2, 2009 Is it possible to add a text box on a page and send the value with GET together with another value to the next page? I could easily do it with a form and add a send button, but I prefer a text link, or can I just use a text link in a form? Link to comment https://forums.phpfreaks.com/topic/160676-solved-text-box-without-form/ Share on other sites More sharing options...
xcoderx Posted June 2, 2009 Share Posted June 2, 2009 In wml sure u can do not know in html never tried or saw. Link to comment https://forums.phpfreaks.com/topic/160676-solved-text-box-without-form/#findComment-847966 Share on other sites More sharing options...
laffin Posted June 2, 2009 Share Posted June 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/160676-solved-text-box-without-form/#findComment-847971 Share on other sites More sharing options...
rv20 Posted June 2, 2009 Share Posted June 2, 2009 I think sessions would work fine. Link to comment https://forums.phpfreaks.com/topic/160676-solved-text-box-without-form/#findComment-847975 Share on other sites More sharing options...
TomNomNom Posted June 2, 2009 Share Posted June 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/160676-solved-text-box-without-form/#findComment-847990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.