0

I have a text input search form for support tickets. If the user inputs a ticket id (checked using a PHP if statement), the background color of the search box is changed to yellow (using a PHP echo) to highlight the search text entered. This part works.

I would like to also change the source value of an iframe as part of the PHP if condition like this:

    <td align="left">
        <input type="text" name="ticket" id="ticket" placeholder="Ticket" value="<?php echo $this->state->ticket;?>" class="input-mini search-query" onchange="document.adminForm.submit();"
        <?php if ($this->state->ticket != "")
            {
            echo 'style="background-color: yellow;"';
            echo '<script language="javascript">';
            echo 'document.getElementById("ticketIframe").contentWindow.document.location.href="http://myurl.com"';
            echo '</script>';       
            }?>/>
    </td>

The javascript function (document.getElementById...) displays on the page rather than executing. I tried a simple javascript alert, but got the same result.

Suggestions?

1
  • id say the poor browser gave up trying to correct the code. Close your input > Commented Jun 26, 2016 at 0:55

1 Answer 1

2

Need to close the input tag before you insert script tag. You simply are generating invalid html that looks like:

<input <script></script> />

You get unexpected results when html is invalid

Sign up to request clarification or add additional context in comments.

9 Comments

thats not valid html
@Dagon isn't that what i said?
sorry, i thought that was what you suggested changing it to
Closing the input made a javascript alert work properly, thank you, but my iframe source is still not working. Ideas?
Is the iframe src on same domain as page? Would throw error in your console if it isn't. If all you want is to change url....change the actual iframe element src instead of trying to go inside it
|

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.