Jump to content

$_get value to be passed to a text box


art15

Recommended Posts

Hi All,

 

I have a list of products with a <a href ?pid bla bla >which has a product id being passed. so if i do echo $_get for pid I get that product id.

my question is if I have 3 text box with <input type = "text" name="name1"> and another with name2  & name3 in a different form. if I click on the link which has list of products, if I want to pass the $_get value to the text box name1 and another $_get value i.e when I click on a different product to text box name2  and so on. How can i do this?

 

thanks

 

Link to comment
https://forums.phpfreaks.com/topic/105372-_get-value-to-be-passed-to-a-text-box/
Share on other sites

Well.... To set the value of a text box, you simply add the tag value="<some value>"

 

Example to make a box that says "Corbin" in it by default:

<input type="text" name="first_name" value="Corbin" />

 

So, by logic, you would simply echo out the $_GET value in the value tag.

 

Example:

 

<input type="text" name="name1" value="<?php echo $_GET['id1']; ?>" />

Hi

 

Thanks for your reply.

 

I already did that, but if the value of $_get is passed to first text box, the second and third text box has the same value and in my case I want to have a different value of $_get when the user clicks on the product list for different product id.(for eg if $_get has a value of 'A', this value is passed to text box 1, but If i click on a different product named 'B', I want this value to be passed to text box 2' and so on)

seems quite tricky?

 

Thanks

 

 

Well.... To set the value of a text box, you simply add the tag value="<some value>"

 

Example to make a box that says "Corbin" in it by default:

<input type="text" name="first_name" value="Corbin" />

 

So, by logic, you would simply echo out the $_GET value in the value tag.

 

Example:

 

<input type="text" name="name1" value="<?php echo $_GET['id1']; ?>" />

<input type="text" name="name1" value="<?php if($_GET['id1'] == 'A') echo $_GET['id1']; ?>" />
<input type="text" name="name2" value="<?php if($_GET['id1'] == 'B') echo $_GET['id1']; ?>" />
<input type="text" name="name3" value="<?php if($_GET['id1'] == 'C') echo $_GET['id1']; ?>" />

Hi,

 

I think you mis interpreted it. If there are 100 of products with its product id, the id which is clicked needs to be inserted in the text area. if the first link is clicked the product id which is clicked is to be inserted. I have 100' s of product. I can't do if for each product.

 

Thanks

 

What you will need to do is set each variable in a cookie (or session variable) as it is set, so that when you come back to the page it will be remembered. For example, if you have $_GET['id1'] = 'A', then you set $_COOKIE['1'] = 'A'. Do the same with values as you add them. So the next value would be entered into cookie 2, and then cookie 3.

 

Then, you write your html like this:

 

<input type="text" name="name1" value="<?php if(isset($_COOKIE['1'])) echo $_COOKIE['1']; ?>" />

<input type="text" name="name1" value="<?php if(isset($_COOKIE['2'])) echo $_COOKIE['2']; ?>" />

<input type="text" name="name1" value="<?php if(isset($_COOKIE['3'])) echo $_COOKIE['3']; ?>" />

Hi Haku,

 

Thanks for your reply.

In my case I dont know what Product the user clicks, so i can't pass that value for $_COOKIES['1']='A'. Say for instance if the user clicks on product test, it is inserted into the first text box as i have specified <input type="text" value="$_COOKIES['1']"> but at the same time the second text box takes the same value. I want to restrict that. in a way if a user clicks on the first product it gets into the first text box only, the second click on any other product will insert that product into the next text box.

 

Thanks

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.