...

View Full Version : Javascript Form not working in Firefox



gravy
07-14-2009, 04:43 PM
I have this javascript and I can not get it to work in firefox or chrome.
It works fine in IE, need help with what I am doing wrong...


<script type="text/javascript">
<!-- Begin
function createForm(number) {
data = "";
inter = "'";
if (number < 21 && number > -1) {
for (i=1; i <= number; i++) {
if (i < 10) spaces="&nbsp; &nbsp;";
else spaces="&nbsp;";
data = data + "Image " + i + " :" + spaces
+ "<input type='file' id='userfile' size='50' name=" + inter
+ "image[]" + inter + "'><br>";
}
if (document.layers) {
document.layers.cust.document.write(data);
document.layers.cust.document.close();
}
else {
if (document.all) {
cust.innerHTML = data;
}
}
}
else {
window.alert("Please select up to 20 entries.");
}
}
// End -->
</script>


Javascript is triggered with


<form name="counter">
Number of Uploads <input type=text name=number size="2">
<input type="button" value="Update" onClick="createForm(counter.number.value);">
</form>
<form name="newad" method="post" enctype="multipart/form-data" action="upload.php" onSubmit="return submitForm(this.Submit)">
<span id=cust style="position:relative;"></span>


Any help is greatly appreciated! :D

Philip M
07-14-2009, 05:13 PM
document.layers has not been supported since Netscape 4. Use of the non-standard document.all anywhere in a script is a clear indication that the script was originally written for IE4 :eek: although it is still supported in IE7.

Change your script to:-


<script type="text/javascript">

function createForm(number) {
data = "";
inter = "'";
if (number < 21 && number > -1) {
for (i=1; i <= number; i++) {
if (i < 10) {spaces = "&nbsp; &nbsp;"}
else {spaces = "&nbsp;"};
data = data + "Image " + i + " :" + spaces
+ "<input type='file' id='userfile' size='50' name=" + inter
+ "image[]" + inter + "'><br>";
}
document.getElementById("cust").innerHTML = data;
}
else {
window.alert("Please select up to 20 entries.");
}
}

</script>


The <!--and //--> hiding tags have not been necessary since IE3. They invariably indicate ancient (as here) code.

Take my advice, I don't use it anyway.

gravy
07-14-2009, 06:55 PM
Thanks man,
I have never writen javascript, so I am clueless on it.
You have talent my friend, I appreciate your help.
The code works perfectly!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum