Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Newbie: form question

Status
Not open for further replies.

grahama1970

Technical User
Jan 24, 2004
9
US
I am very new to ajax and javascript :)
I hacked together this 'working' example to dynamically spit out a movie embed into a div. The problem is that I have no idea what the 'gotchas' are when employing Ajax related solutions.

The Question:
Is there any more javascript related error correction that needs to be done ? I am a bit too new to expect the below to work in a real world scenario.

any help/advice is appretiated
g

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"<html xmlns="<head>
<title>rasmusExample.html</title>
<meta name="generator" content="BBEdit 8.0" />

<script type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sndReq(action) {
http.open('get', 'getmovie.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}


function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}

</script>

</head>
<body>
<form>
<p>Pick a Movie:<br />
<select name="empty" onChange="sndReq(this.value)">
<option value="empty">Choose One</option>
<option value="boeing">boeing</option>
<option value="nike">nike</option>
<option value="levis">levis</option>
<option value="yamaha">yamaha</option>
</select>
</p>

</form>
<div id="foo">

</div>

</body>
</html>
 
one thing i noticed:

Code:
 if(response.indexOf('|' != -1)) {

should be

Code:
 if(response.indexOf('|'[red])[/red] != -1) {

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

[banghead]
 
if that is it, I'm stunned :)
anything else ?
many thanks
g
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top