Jump to content

Archived

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

bettyatolive

Getting Hidden values

Recommended Posts

I have some hidden values.. How do i retrieve those hidden values?
Like I have code :

[code]<input type=hidden name=rc value=<?=$rcid;?> [/code]

Now how do i get that 'rc' value???

Share this post


Link to post
Share on other sites
Well that depends on how you are using the hidden field. Are you using the hidden field in a form to post?

If so its quite simple

[code]
<?
$hiddenvalue = $_POST['rc'];

echo '$hiddenvalue';
?>
[/code]

Also take the '=' out of your php hidden value

Share this post


Link to post
Share on other sites
The same way you get teh values of other form elements. The variable rc will be passed in the $_POST or $_GET array depending on which method you use to submit the form.

If you are trying to retrieve it in that manner now and not getting anything try replacing <?=$rcid;?> with <?php echo $rcid; ?> I know its longer but I hate shorthand php ;)

If that is still failing make sure rcid is set - you can do that quickly by changing type from hidden to text and see if it has an initial value.

Share this post


Link to post
Share on other sites
The $_post function willonly work if you place it in the file that is you're form action.

Here is a basic example:

form.php

[code]
<form name="form1" method="post" action="showname.php">
<input name="firstname" type="text" id="firstname">
<input name="lastname" type="text" id="lastname">
<input name="rc" type="hidden" id="rc" value="<? echo '$rcid' ?>">
<input type="submit" name="Submit" value="Submit">
</form>
[/code]

showname.php
[code]
<?php
$firstname = $_post['firstname'];
$lastname = $_post['lastname'];
$rcid = $_post['rc'];

echo '$firstname, $lastname';
echo ' the hidden value in the form is $rcid';
?>[/code]

That is the basic way but it all depends where your getting the $rcid from. Are u getting it from a database?

Share this post


Link to post
Share on other sites
[!--quoteo(post=386326:date=Jun 21 2006, 06:43 AM:name=Betty)--][div class=\'quotetop\']QUOTE(Betty @ Jun 21 2006, 06:43 AM) [snapback]386326[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I need to use that value in the same form..... And when i'm using $_POST['rc'] it's not giving me the value
[/quote]

Where does the value come from? Is it declared as a variable in 'this' script? Is it created in another script and passed to this script in a form or via a link?

Share this post


Link to post
Share on other sites
Actually i have two text boxes region and type. I have to select a value from region( Whose values r in database) and based on tht value the type has to change.
For eg: If there are 2 regions North n South . And each region has it's own types. These values are stored in the database.
When I select region as north in the first listbox I should have the values "123" and "456".
When i select region as South in the first list box then it should be giving me drop down as "xyz","pqr".
These "123,"456","xyz","pqr" are stored in the database with their own region id's.

Share this post


Link to post
Share on other sites
So your wanting to autofil a field with values from a database based on what the user selects in the previous box? i.e North or South??

Share this post


Link to post
Share on other sites
Then you dont use sql for that you use javascript like so:

[code]
<script language="Javascript">

function autofillin(frm)
{
     if("North" == frm.region.value)
     {
          frm.type.value = "123";
          frm.type.value = "456";
     }
     if("South" == frm.region.value)
     {
          frm.type.value = "abc";
          frm.type.value = "def";
     }
    
}

</script>
<body>
<form name="frm" method="post" action="">
<td>Region</td>
<td><select onchange="autofillin(this.form)" name="region">
<option value="North">North</option>
<option value="South">South</option>
</select>
<td>Type</td>
<td><select name="type" id="type">
</select>
</form>
[/code]

Share this post


Link to post
Share on other sites
benji87,
I have to use the database b'coz there is a stand alone application and the client should be able to change the value types of a particular region i.e. add / delete "123","456".

Can you please give me other solution please... ??
U caN still use Javascript but only with the database...

Share this post


Link to post
Share on other sites

×

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.