1

Hi i use this PHP script http://www.stevedawson.com/scripts/text-counter.php

And to make it appear on my html page i use this ajax script.

<script>

$.ajax({
    type:'GET',
    url:'http://www.solariserat.se/count.php',
    data:'',
    success: function(data){
            $('#container').html(data);
    }
});

</script>

Together with this html code

<div id="container">    
<?php include "count.php"; ?>
</div>

And it works perfect and it displays the counted numbers inside the div.

But i want it to be displayed as value inside a input tag Is this possible, and how do i do it?

I know this is wrong but you get my point what i want to do =)

<input value="count.php">
4
  • Why are you using JavaScript (it's not "ajax script") to begin with? There's no reason to use client script here at all. Commented Dec 17, 2014 at 18:08
  • What would the point of an input tag be? Unless you're going to be submitting that number somewhere as part of a form, it'd just be visual clutter. You could style a regular div/span as an input-like box if you need. Commented Dec 17, 2014 at 18:11
  • I need to submit the number in a form. Commented Dec 17, 2014 at 18:30
  • Matti, the only way i get this numbers to show is thru this script unless i name the file .php instead of .html, but then other functions dont work. Commented Dec 17, 2014 at 18:34

3 Answers 3

3

This should work:

<input value="<?php include "count.php"; ?>">

However a cleaner approach would be to include the count value in the PHP page that is rendering the <input> so you can do something like this:

<input value="<?= count ?>">
Sign up to request clarification or add additional context in comments.

3 Comments

This works if the file is named .php is it possible to make it work even if the filename is a .html?
It's a complicated "no", the naming of the file is what informs your web server to pass it through a PHP interpreter. If you changed the configuration of your web server (most likely Apache) you could have any request to a .html file pass through mod_php but this has other side effects (mostly performance and memory)
Though honestly most websites I've seen if they use PHP use it for every page that returns HTML so it wouldn't be any slower than the site you are already running (so not that big of a deal).
0

you should be using php tag for this :

<input value="<?php include "count.php"; ?>">

i'll suggest do not use short tags until and unless you are handling them properly.

if you want to show some value use:

<input value="<?php echo $count; ?>">// here count is a variable.

Comments

0

I manage to get the values inside a input field so i can now send it with a form and submit button.

Maybe it's not a good locking solution, but it works.

I made an iframe that shows a .php page and made a input field like this

<input value="<?php include "count.php"; ?>">

And then i made a script placed in parent .html page like this

 function boahaga()  {

    var myphp = window.frames["invoice"].document.getElementById ( "myidbo" ).value, 
        result = document.getElementById('fakturanr_from'),
        myResult;

    {
      myResult = myphp;
      result.value = (myResult);
    }


}

And inside the body tag i run script onload.

<body onload="boahaga()">

Now the input on the parent .html page is filled correct with the .php page input value.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.