dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: PHP (+javascript?) button to change text w/o reloading page

  1. #1
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287

    Question PHP (+javascript?) button to change text w/o reloading page

    Hello all

    So, right now I'm designing a site with php, and I wanted to add a textbox with arrows on either side which, when clicked, will change the text in the textbox without having to reload the page.

    The textbox's text is also going to be loaded from an external *.txt document. I was thinking of having different messages separated by 'at signs' which would be extracted, then explode the 'at signs' to put the data in an array, which could then be scrolled through, via the arrow buttons said above. (If there's a more efficient way, let me know.) The array would have a changing length.

    I would try to figure it out with Google, but I don't know what to search...I remember learning this years and years ago, but I don't have a clue anymore.

    Thanks!
    --SumWunGye

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    These doesn't necessarily have anything to do with PHP. Unless you happen to be using AMFPHP or some kind of PHP-Actionscript serializer class in your flash movie, then Flash is going to receive the data from a text file or PHP as one string of characters. If you devide your content using & instead of @ then Flash can automatically split it for you but you'd need to assign name-value paris like this.

    Code:
    var1=value1&var2=value2&var3=value3
    Perhaps you could give a little more info about what you are trying to do and why you think you need php?
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    here is a simplistic javascript example to populate a textbox from vars in the script.
    I am not sure whether this is what you wanted...

    Code:
    <script>
    var texts = Array('this is first text<br>multiline', 'another text');
    function showtext(n)
    {       document.forms.form1.ta.innerHTML = texts[n];
    }
    </script>
    <form name=form1>
    <textarea name=ta rows=5 cols=50></textarea><br>
    <input type=button value=text1 onclick='showtext(0)'>
    <input type=button value=text2 onclick='showtext(1)'>
    </form>
    Musicman

  4. #4
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    @ Sneakyimp

    I'm only really using php for the loading of the variables to be put into the textbox; I know the actual replacement of the text requires no php; I'm just saying that's the page type.

    @ Musicman

    Thanks! That was really close to what I had in mind; I'm glad you could understand..

    Is there any way for the user to be unable to type/enter/delete information from the textbox? aka not really a textbox, but just text in an html table.

    Thanks again, guys
    --SumWunGye

  5. #5
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    a textarea does not seem to have a readonly property. You can use the innerHTML with a simple <div> instead of a textarea, so if you can use css style properties to make the div look like a textarea, you are fine

    Musicman

  6. #6
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    Thanks! The InnerHTML was exactly what I needed
    --SumWunGye

  7. #7
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    Sorry, one more thing...

    Say I have an array of 5 objects in javascript. I have a button that says "prev" and another, saying "next." how can i make it so that "prev" makes InnerHTML show the previous item in the array, while "next" uses InnerHTML to show the next in the array, while stopping at the last item and going no further?

    Thanks again
    --SumWunGye

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center