1

I'm attempting to echo a div tag within a HTML form value. Im unable to display the contents of the div tag without messing up the form value.

<?php echo '<div id="demo"></div>';?>


Form value...

<input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">


What's outputted... (What's echoed inside the form value should be the current longitude and latitude)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Geolocation search</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script id="data" type="text/javascript" src="js/search.js" xmlData="data/data.xml"></script>
</head>
<body onload="getLocation()">
<div id="controller">
  <label>Search Term:
    <input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">
  </label>
  <label>
    <select name="category" id="category">
      <option value="name">Name</option>
    </select>
  </label>
  <input name="Search" type="button" id="searchButton" value="Search">
</div>
<div id="result">&nbsp;</div>

<?php echo '<div id="demo"></div>';?>

<script>
var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML=" " + position.coords.latitude + 
  "<br> " + position.coords.longitude;  
  }
</script>
</body>
</html>

Is there soem other way to echo out the longitude and latitude from the that's loaded within the echo statement?

12
  • I think you need to reread the question and explain it better. Commented Dec 9, 2012 at 1:23
  • @WebnetMobile.com I don't understand... Is that pertinent to my question? Commented Dec 9, 2012 at 1:24
  • @OneOfOne I'm not sure how else to explain it. Commented Dec 9, 2012 at 1:24
  • Dare I ask what is the purpose of having a <div> as the value of an input? Commented Dec 9, 2012 at 1:26
  • 1
    @Pxlc ...Why are you now echoing javascript in the input?(It won't work it's just text, the same as the div!) THINK! Don't echo anything in the input value. Just change the input id from "term" to "demo". If you want more help just open a new question. Commented Dec 9, 2012 at 2:21

4 Answers 4

2

it's the "

change

<input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">

to

<input type="text" id="term" value="<?php echo "<div id='demo'></div>";?>">
Sign up to request clarification or add additional context in comments.

3 Comments

It works! I must have missed the double quote. One thing though, all that is echoed is the actual <div> tag not the current location. boomerang.pxlc.me/_old/index.html?
i have no idea what that is.
if my answer helped you, please choose it as the answer.
0

You have double quotes around the word demo that are closing your value.

Try:

<?php echo "<div id='demo'></div>";?>

3 Comments

Shouldn't it be <?php echo "<div id='demo'></div>";?> ?
And that will give it a value? Because right now it just prints out the div tag.
@Pxlc Maybe I am misunderstanding that particular issue and what you are trying to do. Might be better to post that as a new question.
0
     <label>Search Term:
        <input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">
     </label>

What i see from the above script is, you used a double quote to represent your attribute value.. and then single quote to handle the php echo value, then used a double quote again inside the div which makes the php code invalid because it stops its reading by the double quote you used. you might as well concatenate your php script or use an escape character for the string to be valid "\"

    <label>Search Term:
        <input type="text" id="term" value="<?php echo '<div id=\'demo\'></div>'; ?>" />
    </label>

    <?php echo "<div id='demo'></div>"; ?>

And may i just ask... What are you trying to echo out of the value? Is it really the div tag?

1 Comment

Thank you! Not the div itself. The javascript I provided displays the longitude and the latitude of the current location displayed in the div "demo". That's what I want in the value.
0

Its because the HTTP headers, which you are sending like above, are telling the browser to expect a file to be downloaded. They are not telling browser to expect HTML content (default). Therefore the content you are sending in an echo is not getting displayed.

Both won't work together correctly although I'm sure you can find any work around but the point is that you only need those echo's while debugging so you can disable the mentioned header call while debugging and once everything is set, enable that again so file can download.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.