Javascript Help

Started by Skooble, July 18, 2010, 10:02:40 PM

Previous topic - Next topic

Skooble

I'm writing a Javascript for a website I am working on. But with the little experience I have, it's proving difficult.

I want the user to enter a term into the text box, and then click the button to change a variable in the html.

So something like:

<HTML>
<HEAD>
<script LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -
function MsgBox (textstring) {
alert (textstring) }
// - End of JavaScript - -->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT NAME="text1" TYPE=Text>
<INPUT NAME="submit" TYPE=Button VALUE="Search" onClick="ASSIGN AS VARIABLE TO USE IN HTML OF WEBSITE?">
</FORM>
</BODY>
</HTML>

So that it changes the variable of the html:

<iframe src="example.com keyword=VARIABLE></iframe>

But I'm not sure how I could go about doing this. Is it even possible?

DrPete

it depends what exactly you are trying to change. the keywords in javascript and the keywords in HTML often do not match up the way you would expect them to

see http://www.w3schools.com/jsref/default.asp and the associated examples at http://www.w3schools.com/htmldom/dom_examples.asp - picking those apart should get you where you need to be
[div align=\\\"center\\\"] My Tetris Friends profile [url=http://kingo

Skooble

Quote from: DrPete
it depends what exactly you are trying to change. the keywords in javascript and the keywords in HTML often do not match up the way you would expect them to

see http://www.w3schools.com/jsref/default.asp and the associated examples at http://www.w3schools.com/htmldom/dom_examples.asp - picking those apart should get you where you need to be

Alrighty. Basically I want this:

<iframe src="http://www.bing.com/twitter/maps/embed?version=1.0&eid=1231925959&keyword=%23selling+variable&lat=37.4453392028809&lon=-96.0642547607422&z=3" width="350" height="350" scrolling="no" frameborder="0"></iframe>

where the user enters the variable. Maybe I don't even need JS.

DrPete

something like this is what you want:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>lol</title>
    <script type="text/javascript" charset="utf-8">
        function foo() {
            document.getElementById("searchframe").src =
                "http://www.bing.com/twitter/maps/embed?version=1.0&eid=1231925959&keyword="
                + document.getElementById("searchterms").value +
                "&lat=37.4453392028809&lon=-96.0642547607422&z=3";
        }
    </script>
</head>
<body>
<p>
<input id="searchterms" type="text" value="search terms" />
<input type="button" onclick="foo();" />
</p>

<iframe id="searchframe" style="width:350; height:350;" src="about:blank"
    scrolling="no" frameborder="0" />

</body>
</html>
[div align=\\\"center\\\"] My Tetris Friends profile [url=http://kingo

Skooble

Quote from: DrPete
something like this is what you want:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>lol</title>
    <script type="text/javascript" charset="utf-8">
        function foo() {
            document.getElementById("searchframe").src =
                "http://www.bing.com/twitter/maps/embed?version=1.0&eid=1231925959&keyword="
                + document.getElementById("searchterms").value +
                "&lat=37.4453392028809&lon=-96.0642547607422&z=3";
        }
    </script>
</head>
<body>
<p>
<input id="searchterms" type="text" value="search terms" />
<input type="button" onclick="foo();" />
</p>

<iframe id="searchframe" style="width:350; height:350;" src="about:blank"
    scrolling="no" frameborder="0" />

</body>
</html>


PERFECT. Thank you so much.