Current location: Hot Scripts Forums » Programming Languages » PHP » How can I put a button value automatically in a text box?


How can I put a button value automatically in a text box?

Reply
  #1 (permalink)  
Old 08-05-09, 02:23 AM
u192973 u192973 is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy How can I put a button value automatically in a text box?

Hello ALL! I need help!

I have a send message section on my website. The users name will be a button, and if the user wants to send a message to that user they click the button and it brings them to the message page where the "To:" textbox is already filled with the buttons value which is the user.

How do I do that? Right now its like this:

Button:
HTML Code:
<input type="submit" onClick="document.location.href='http://revideolution.com/senduser.php'" name="tousercommunity" value="conrad" />
message board:
HTML Code:
<label>To:<input type="text" id="tousercommunity" value="<?php print($_SESSION['tousercommunity']); ?>"/>

Last edited by wirehopper; 08-05-09 at 06:52 AM. Reason: HTML tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-05-09, 06:53 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Please post the HTML for the form, and the PHP that receives it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-05-09, 09:12 AM
olddocks olddocks is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
you mean you want to move the button value to text box on clicking it? For that you have to use javascript. it should be like

Code:
document.getElementbyID("txtbox").value = document.getElementbyID("submit").value
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-06-09, 03:04 PM
krishardy krishardy is offline
Newbie Coder
 
Join Date: Aug 2009
Location: Columbus, OH
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
Here's the easy way to do it via an HTTP GET request:

HTML Code:
<form action="http://revideolution.com/senduser.php" method="get">
<input type="submit" name="tousercommunity" value="conrad" />
</form>
Now, in senduser.php, make this change in your view script:

PHP Code:

<input type="text" id="tousercommunity" name="tousercommunity" value="<?php echo $_GET['tousercommunity']; ?>" />
(There are about 100 different ways I can think of to do this, but the example above is the easiest. In every case, you need to pass the "tousercommunity" value to your senduser.php script somehow, and then show it in the view when the senduser.php request loads. I used GET parameters, but you could do it via POST as well. SESSION won't work unless you pass the "tousercommunity" back to the server and it is stored in the session variables, which is usually a less-than-ideal practice for a request like this.)

The only way I can think of to make it work the way you want without tacking the "tousercommunity" parameter to the request is to store the session in the user's cookie on the first page using javascript, then pull the name from the cookie when loading senduser.php. However, this is not really the best way, and passing the parameter via GET is, in my experience, the best way to go.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-07-09, 12:21 AM
u192973 u192973 is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
thank you so much! it works likr a charm! Thank you for the easy way, I'm trying to make things as simple as possible
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
automatic, button, php, textbox


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
text box with scroll bar silvermane CSS 7 01-16-09 04:03 AM
div css theighost CSS 11 09-14-08 03:30 AM
Draggable Tables Ares JavaScript 10 08-03-06 07:55 AM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 04:27 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM


All times are GMT -5. The time now is 01:47 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.