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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax Only Submits One Forum.

Status
Not open for further replies.

Cablekid

Programmer
Mar 25, 2008
1
US
Help.

So Far My Script Works Perfect. It is suppose to be a multihost image upload. and my script allows it to add keywords. Alright But Theirs One Problem if more than one image is uploaded the code just repated it self and shows the both images.. So right now if i have
Code:
<form action="javascript:insert()" method="post">
<input name="keyword" type="text" id="keyword" value=""/>
<input name="name" type="text" id="name" value="<# FILENAME #>"/>
<input type="submit" name="Submit" value="Insert"/>
<div id="insert_response"></div>

It works fine. But if i upload 2 images
Code:
<form action="javascript:insert()" method="post">
<input name="keyword" type="text" id="keyword" value=""/>
<input name="name" type="text" id="name" value="<# FILENAME #>"/>
<input type="submit" name="Submit" value="Insert"/>
<div id="insert_response"></div>
Code:
<form action="javascript:insert()" method="post">
<input name="keyword" type="text" id="keyword" value=""/>
<input name="name" type="text" id="name" value="<# FILENAME #>"/>
<input type="submit" name="Submit" value="Insert"/>
<div id="insert_response"></div>

Wont Work. Just submits the first one. Whats the best way to fix this.

Heres the other codes
Code:
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var keyword= encodeURI(document.getElementById('keyword').value);
var name = encodeURI(document.getElementById('name').value);

// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?site_url='+site_url+'&name=' +name+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Keyword added".
document.getElementById('insert_response').innerHTML = 'Keyword added:'+response;
}
}
Code:
<? 	require_once "./source/includes/data.php";

if(isset($_GET['keywordl']) && isset($_GET['name'])){
$keyword= $_GET['keyword'];
$name= $_GET['name'];
$insertKeyword_sql = "UPDATE `mmh_file_storage` SET `keyword` = '{$keyword}' WHERE `filename` = '{$name}'";
$insertKeyword= mysql_query($insertKeyword_sql) or die(mysql_error());
echo $keyword;
} else {
echo 'Error! Please fill all fileds!';

}
?>
 
Whats the best way to fix this.
Validate your markup first. You have multiple id attributes sharing the same value in the code you give. This is plain wrong and will result in strange behaviour.

So, start by visiting the w3 validation service, and start with an even playing field!

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top