Andrew V
Andrew V

Reputation: 522

How can I change the content of an iframe with form post

Ok so I have this code :

<body>
    <div id="top_bar">
        <a target="content_frame" href="main/index.php"> Home | </a>
        <a target="content_frame" href="faq/index.html"> FAQ | </a>
        <a target="content_frame" href="contact/index.html"> Contact </a>
        <div id="search">
            <form method="POST" action="/php/search.php">
                Search: <input type="text" name="search_box">
                <input id="search_button" type="submit" value="Search">
            <form>
        </div>
    </div>
    <iframe name="content_frame" src="main/index.php"></iframe>
</body>

And the webpage looks something like this: My webpage

How do I make it so when someone writes something in the search_box and presses ENTER it doesn't change the whole page but it acts on the iframe instead?

Upvotes: 0

Views: 376

Answers (1)

Thomas Boulund
Thomas Boulund

Reputation: 38

Setting the target attribute of the form should do the job :)

<form method="POST" action="/php/search.php" target="content_frame">
    Search: <input type="text" name="search_box">
    <input id="search_button" type="submit" value="Search">
<form>

Upvotes: 1

Related Questions