Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grab input value by using php

Status
Not open for further replies.

hunt00

Technical User
Mar 6, 2005
79
US
How can i grab the hidden input innerHTML value in php?

HTML:
<input type="hidden" name="temp" id="temp" value="<?=$a?>" />

PHP:
tried
1. print("<script language = 'javascript'>document.write(parent.outer_form.temp.innerHtml)</script>");

2. print("<script language = 'javascript'>document.getElementById('temp').innerHTML</script>");

3. setup temp value as $a in js, and echo directly in php

None worked.....Could someone give me some directions?

Thanks!
 
if you are trying to get the value of the hidden field whilst on the page that the field is placed, why not just look at the source code?

if you must have a js method try echoing this:

Code:
echo <<<EOF
<button onClick="alert(document.getElementById('temp').value);">
 Show Value
</button>
EOF;
 
This results in a popup to show the value when clicking on button. Is there anyway that could get the result just like in a print out. In my code, if temp value exists, the current field value needs to be replaced by that hidden temp value.
 
Code:
echo <<<EOF
<input type="hidden" name="temp" id="temp" value="<?=$a?>" />
<br/>
<input type="text" name="currentfield" id="currentfield"  />
<br/>
<button onClick="document.getElementById('currentfield').value = document.getElementById('temp').value;">
 Check Hidden Value
</button>
EOF;

but this seems rather tortuous. if you know (in your php) code that the variable $a is populated why don't you just shove the value into the field you want before sending the code to the browser?
 
It sounds like you're trying to grab that value using PHP, where it would still be assigned as $a, so it could be conditionally accessible with:
Code:
<?php
if ($a<>""){ echo $a; }
?>
Maybe I'm not quite understanding what you're trying to do, does this help?
 
hmm, i dont see my temp value display in the current field...

Maybe i am too much into my own thoughts that didnt explain clearly.

The current field is displaying the data getting from server which is using php and display thru php directly as soon as it has that data. This current field is on one of the tabs. I need to check if user has a temp value, if yes, the current field will display this temp value before it saved back to server when switching tabs .

So i setup this temp field and js could get that field value, but i cant get this to php display......

Thanks very much!
 
Definitely not quite understanding. An example of the code you're working with would probably help. The way I see it is that if you're processing a page with PHP, and you have a value in $a that is a temp value affecting the value of input fields based on whether or not it has data in it. Combining my suggestion with jpadie's you would have:
Code:
<input type="text" name="currentfield" id="currentfield" value="<?php if ($a<>""){ echo $a; } ?>" />
So as the page is generated, if there was a value in $a it would be the value in the text input called currentfield, and if it was empty the value would be set to "" (nothing). Does this help?
 
PHP:
//$has_saved pass from server, trying to replace $has_saved with $a

if ($a != "") $field->Value = $a;
else $field->Value = $has_saved;

HTML:
<input type="hidden" name="saved" id="saved" value="<?=$has_saved?>" />
<input type="hidden" name="temp" id="temp" value="<?=$a?>" />

JS:
This function is called when switching tabs by onunload
function checkit() {
//from server
saved = parent.document.outer_form.saved.value;

//temp user input, but in the field display
$a = window.eFrame.eArea.document.body.innerHTML;

//pass this display field to hidden temp field for passing to php....
if ($a != "" && $a != saved) {
parent.document.outer_form.temp.value = $a;
}
}


 
I'm trying hard to help you but not too clear on the dynamics you have going on here. When someone "switches tabs" I assume they are clicking on a link and technically naviagting to a new page? It would be possible to cause a javascript form submittal when someone switches tabs, which would make the fields on the page accessible to the PHP processing as the new tab is loaded via $_POST['temp'] and $_POST['saved'].

Are you saying your JS section is on a different page, which is interacting with the PHP and HTML sections via iFrames? Perhaps I'll not be able to help you but I'll keep trying!
 
Thanks very much, there!

HTML is on one page which has all the tabs hidden value that pass thru server for different uses, also html page setup the switching tabs by using a JS function.

I'm stuck at this tab which needs to keep users temp typed value if it exists, so that when user switching to other tabs, this temp typed value wont be overwritten by the saved one when he comes back. <---Before click Save on the HTML page

This tab JS is above its PHP, in the same file. Trying to grab this temp value, so i setup the hidden field, when temp value exists, it goes to this field. Then the php will grab from this temp hidden field, and replace the save value. Otherwise, when switching tabs, user will lose what he has typed in <--before save.
 
i don't understand this function
Code:
 This function is called when switching tabs by onunload
 function checkit() {
     //from server
   saved = parent.document.outer_form.saved.value;
 
     //temp user input, but in the field display
   $a = window.eFrame.eArea.document.body.innerHTML;

     //pass this display field to hidden temp field for passing to php....
   if ($a != "" && $a != saved) {
      parent.document.outer_form.temp.value = $a;
   }
 }

if this is javascript then it is malformed as JS does not use $ signs for naming variables.
further the conditional test against saved will not work unless saved is a variable itself.

your problem does not seem to be php related as you are correctly getting the $a value into the hidden field (as evidenced by the alert script i pasted in above). It is therefore javascript related, most likely. i suggest you try posting into the JS forum for more help.
 
hmm, the js works fine. It grabs the user typed value. It does the compare and put it to the hidden field if exists, which assigned with $a value. Just that I am not sure how php could get it.
 
To answer that question the only way I can think to get a JS variable to a PHP script is through a posted form field. Since PHP runs server-side it doesn't have access to anything that happens after a page is loaded by the client until the information is sent back somehow, as in a form post.
 
Thanks GREATLY for all your help in short time! Make me not feeling alone to find the solution! Good news as for my thankness is it shows now. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top