Jump to content


Photo

Getting Hidden values


  • Please log in to reply
10 replies to this topic

#1 bettyatolive

bettyatolive
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 09:13 AM

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

<input type=hidden name=rc value=<?=$rcid;?>

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



#2 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 09:25 AM

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

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

echo '$hiddenvalue';
?>

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

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 21 June 2006 - 09:28 AM

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.

follow me on twitter @PHPsycho

#4 bettyatolive

bettyatolive
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 10:43 AM

I need to use that value in the same form..... And when i'm using $_POST['rc'] it's not giving me the value

#5 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 11:00 AM

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

<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>

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

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

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



#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 June 2006 - 11:01 AM

[!--quoteo(post=386326:date=Jun 21 2006, 06:43 AM:name=Betty)--][div class=\'quotetop\']QUOTE(Betty @ Jun 21 2006, 06:43 AM) View Post[/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?

Legend has it that reading the manual never killed anyone.
My site

#7 bettyatolive

bettyatolive
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 11:13 AM

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.

#8 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 11:24 AM

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??

#9 bettyatolive

bettyatolive
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 11:25 AM

Ya, tht's wht i exactly want.

#10 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 21 June 2006 - 12:36 PM

Then you dont use sql for that you use javascript like so:

<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>


#11 bettyatolive

bettyatolive
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 June 2006 - 12:45 PM

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...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users