...

View Full Version : Cant get this javascript to parse right!



jediman
03-11-2004, 04:48 PM
I am having major problems with this code:


code:



function GetFormHTML()
{
thiscount = counter();
var htmlStr = '';
htmlStr += '<table><tr><td>Sensor Type</td><td> Address</td><td> Formula</td></tr></table>';
for (var i=0;i<gFieldValues.length;i++)
htmlStr += '<table><tr><td><input type="text" name="myoptions" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>"> <input type="text" name="multifield" value="' + gFieldValues[i] + '"> <input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';
htmlStr += '<input type="button" value="New Type" onClick="AddField()">';

return htmlStr;

}

Php code


$blah=$_POST['thiscounter'];
$this=$_POST['myoptionpass'];
for($z=0; $z<$blah; $z++)
{

print($this[$z]);

}


What I need to to do,is when i hit a submit button at the end it sends the values over to a php page, and that php code is used to get the values (of myoptions right now) as each field is added dynamically. The counter itself passes fine, but I cant get each individual myoptions to go through. Does anyone see what I am doing wrong? Do I need to create some sort of new array to hold the field values through each pass? I am at a loss and need to get this done asap! Please help! Thanks!
PS...the javascript is on one page, and the php on another :)
Also note that these arrays are dynamic, so doing like upwards of 500 static things to hold the vars isnt viable. I know its an array problem, I just cant figure it out! BTW im new here, hiiiiii :)

sad69
03-11-2004, 06:48 PM
Try changing:
name="myoptions"

to:
name="myoptions[]"

and see how that works out for you.

Hope that helps,
Sadiq.

jediman
03-11-2004, 07:47 PM
function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;
else
getFieldValue[k]=formObj.myoptions.value;
}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}



doesnt work becuase of that...any other hints ?:rolleyes:

sad69
03-11-2004, 08:02 PM
I don't get it. What doesn't work because of what?

jediman
03-11-2004, 08:09 PM
Check out the php in the top post there. Whats not working is the myoptions field isnt passing to the php page correctly. I can get like the very last data entered into the last field but that is it. I havent been able to get the array working right so that, say i have like 10 fields added in total, that the 10 different things show up instead of just the very last one. Thats what I dont get :-/

sad69
03-11-2004, 08:15 PM
What's myoptionpass?

Hear me out: what I'm proposing is that in your input's names should be myoption[]. Then in your PHP, try accessing the array like so:


foreach($_POST["myoption"] as $index => $val) {
print("myoption[".$index."] = ".$val."<br>");
}


That should do it.

Let me know what happens,
Sadiq.

jediman
03-11-2004, 08:22 PM
I hear what your saying, but the code i have wont allow for myoptions[] because of the way its retreiving everything. see that other code i posted like two posts up there.

If i can get that to go with where it retains the values and adds a new line i think its all good to go, thats what i cant figure out otherwise, otherwise your suggestion does seem to be working.

It tells me in the error when i try to hit the add type button that myoptions.value is null or not an object.

sad69
03-11-2004, 10:49 PM
Is this stuff online anywhere? Because I don't really understand your could.

You make it sound like you're creating new fields dynamically, I but I don't see any DOM stuff. You're making reference to a lot of other variables and functions, and I don't know what they do.

So I'm sorry that I can't be of further help because I don't understand what's going on, what the errors are and what they mean in this context (because I don't see enough to know what the context is) to help you.

So until you provide more code I'm at a loss. It almost seems to me that you may have to re-work a bunch of your code to accomodate this.

Sadiq.

jediman
03-11-2004, 10:51 PM
<script LANGUAGE="JavaScript">
var mycount = 0;
function counter()
{

mycount++;

return mycount;
}


// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{

if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
}
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}
function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload[i]();

for (var j=0;j<gSafeOnload.length;j++)
gSafeOnload[j]();

for (var k=0;k<gSafeOnload.length;k++)
gSafeOnLoad[k]();


}


//
// Main Form Functions
//

// This array holds our form values when we need to regenerate the form
var gFieldValues = new Array(1);

var gFieldValue = new Array(1);

var getFieldValue = new Array(1);



for (var i=0;i<gFieldValues.length;i++)
gFieldValues[i]="";

for (var j=0;j<gFieldValue.length;j++)
gFieldValue[j]="";

for (var k=0;k<getFieldValue.length;k++)
getFieldValue[k]= "";


function GetFormHTML()
{
thiscount = counter();
var htmlStr = '';
htmlStr += '<table><tr><td>Sensor Type</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Formula</td></tr></table>';
for (var i=0;i<gFieldValues.length;i++)
htmlStr += '<table><tr><td><input type="text" name="myoptions[]" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>">&nbsp;<input type="text" name="multifield" value="' + gFieldValues[i] + '">&nbsp;<input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';
htmlStr += '<input type="button" value="New Type" onClick="AddField()">';

return htmlStr;

}


function GetFormObj()
{
var returnObj = null;

if (IE4plus)
{
returnObj = document.dynoform;
}
else if (NS4)
{
returnObj = document.formlayer.document.dynoform;
}
else if (NS6)
{
returnObj = document.getElementById("dynoform");
}
return returnObj;
}

function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}


function UpdateForm()
{
var htmlStr = GetFormHTML();
if (IE4plus)
{
document.all.formlayer.innerHTML = htmlStr;
}
else if (NS4)
{
document.formlayer.document.open();
document.formlayer.document.write(htmlStr);
document.formlayer.document.close();
}
else if (NS6)
{
document.getElementById("formlayer").innerHTML = htmlStr;
}
}

function IncludeForm()
{

var htmlStr = GetFormHTML();

if (IE4plus || NS6)
{
document.write('<DIV ID=formlayer name=formlayer STYLE="position:relative; WIDTH=400px; HEIGHT=50px">' + htmlStr + '</DIV>');
}
else if (NS4)
{
// Because NS needs floating layers, we need a placeholder graphic to force anything
// below the layer content to leave whitespace for the layer. The position of this
// graphic is also used in determining the position of the layer.
document.write('<img name="formlocation" border="0" width="400" height="200" src="images/spacer.gif">');

}

}

//
// Netscape 4.x Ineptness
//
function HandleOnload()
{
if (NS4)
{
var width = document.formlocation.width;
var height = document.formlocation.height;

nL=new Layer(width);
nL.name = "formlayer";
nL.left=document.formlocation.x;
nL.top=document.formlocation.y;
nL.bgColor = "white";
nL.clip.width=width;
nL.clip.height=height;
nL.document.open();
nL.document.write(GetFormHTML());
nL.document.close();
nL.visibility = 'show';

document.formlayer = nL;

}
}

function HandleResize()
{
location.reload();
return false;
}

if (NS4)
{
SafeAddOnload(HandleOnload);
window.captureEvents(Event.RESIZE);
window.onresize = HandleResize;
}


</script>

theres the javascript :)

jediman
03-12-2004, 02:50 PM
Any takers? I need to get this going as soon as humanly possible, and im at a lost, and I am hoping someone could help :-/

Willy Duitt
03-12-2004, 03:11 PM
If you are only getting the last entry of the gFieldValues array.
Your script is not stepping thru the array properly.
Try this:
function GetFormHTML(){
thiscount = counter();
var htmlStr = '';
htmlStr += '<table><tr><td>Sensor Type</td><td> Address</td><td> Formula</td></tr></table>';

var i = 0;
while (i<gFieldValues.length){
htmlStr += '<table><tr><td><input type="text" name="myoptions" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>"> <input type="text" name="multifield" value="' + gFieldValues[i] + '"> <input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';
htmlStr += '<input type="button" value="New Type" onClick="AddField()">';

return htmlStr;
}
}

.....Willy

Edit: Removed my unneeded changes to the lenth.

jediman
03-12-2004, 03:23 PM
Still doesnt work, with that -1 the fields dont even show for one thing, and then even before that its telling me that multified[...] is like null or not an object. IT was working except for the part down wher eit gets and stores the values every time you click add type, since it complained about the myoptions.value being null or not an object.


function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}


thats what im talkinga bout. If i change myoptions to myoptions[] to step trhough which dOES work if it stops complaining that is... i cant see how to fix it from saying that myoptions.value is null or not an object...

Willy Duitt
03-12-2004, 03:39 PM
Then perhaps it is time to puplish a test page so someone can actually run your codes and see what is happening. If you were getting the value of the last gFieldsValue then the while loop should have resolved your problem of missing the others.

......Willy

jediman
03-12-2004, 03:46 PM
http://jediman.no-ip.com:82/test/pubtest.html

jediman
03-12-2004, 04:13 PM
Plus in that code you posted, where does i increment ? I tried using i++; but with and without it i get errrors. Let me know if youve taken a look at the page.

Willy Duitt
03-12-2004, 04:17 PM
I do not see how anything ever worked since you have never opened the form and named it. Also, when you first defined myoptions you named it (myoptions[]) but then later refer to it as (myoptions).

I added the opening form tag and fixed the myoptions and got the script to fire and add rows. However, once that was working you now have a problem with multifields not being defined.

That's all the time I have.
Good Luck;
.....Willy

Working changes highlighted in red
Line 88: htmlStr += '<table><tr><td>Sensor Type<form name="dynoform"></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Formula</td></tr></table>';
Line 89: for (var i=0;i<gFieldValues.length;i++)
Line 90: htmlStr += '<table><tr><td><input type="text" name="myoptions" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>">&nbsp;<input type="text" name="multifield" value="' + gFieldValues[i] + '">&nbsp;<input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';

jediman
03-12-2004, 04:25 PM
Actually it was defined just cut it out acccidentally


<script LANGUAGE="JavaScript">
var mycount = 0;
function counter()
{

mycount++;

return mycount;
}


// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{

if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
}
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}
function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload[i]();

for (var j=0;j<gSafeOnload.length;j++)
gSafeOnload[j]();

for (var k=0;k<gSafeOnload.length;k++)
gSafeOnLoad[k]();


}


//
// Main Form Functions
//

// This array holds our form values when we need to regenerate the form
var gFieldValues = new Array(1);

var gFieldValue = new Array(1);

var getFieldValue = new Array(1);



for (var i=0;i<gFieldValues.length;i++)
gFieldValues[i]="";

for (var j=0;j<gFieldValue.length;j++)
gFieldValue[j]="";

for (var k=0;k<getFieldValue.length;k++)
getFieldValue[k]= "";


function GetFormHTML()
{
thiscount = counter();
var htmlStr = '';
htmlStr += '<table><tr><td>Sensor Type</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Formula</td></tr></table>';
for (var i=0;i<gFieldValues.length;i++)
htmlStr += '<table><tr><td><input type="text" name="myoptions[]" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>">&nbsp;<input type="text" name="multifield" value="' + gFieldValues[i] + '">&nbsp;<input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';
htmlStr += '<input type="button" value="New Type" onClick="AddField()">';

return htmlStr;


}



function GetFormObj()
{
var returnObj = null;

if (IE4plus)
{
returnObj = document.dynoform;
}
else if (NS4)
{
returnObj = document.formlayer.document.dynoform;
}
else if (NS6)
{
returnObj = document.getElementById("dynoform");
}
return returnObj;
}

function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}


function UpdateForm()
{
var htmlStr = GetFormHTML();
if (IE4plus)
{
document.all.formlayer.innerHTML = htmlStr;
}
else if (NS4)
{
document.formlayer.document.open();
document.formlayer.document.write(htmlStr);
document.formlayer.document.close();
}
else if (NS6)
{
document.getElementById("formlayer").innerHTML = htmlStr;
}
}

function IncludeForm()
{

var htmlStr = GetFormHTML();

if (IE4plus || NS6)
{
document.write('<DIV ID=formlayer name=formlayer STYLE="position:relative; WIDTH=400px; HEIGHT=50px">' + htmlStr + '</DIV>');
}
else if (NS4)
{
// Because NS needs floating layers, we need a placeholder graphic to force anything
// below the layer content to leave whitespace for the layer. The position of this
// graphic is also used in determining the position of the layer.
document.write('<img name="formlocation" border="0" width="400" height="200" src="images/spacer.gif">');

}

}

//
// Netscape 4.x Ineptness
//
function HandleOnload()
{
if (NS4)
{
var width = document.formlocation.width;
var height = document.formlocation.height;

nL=new Layer(width);
nL.name = "formlayer";
nL.left=document.formlocation.x;
nL.top=document.formlocation.y;
nL.bgColor = "white";
nL.clip.width=width;
nL.clip.height=height;
nL.document.open();
nL.document.write(GetFormHTML());
nL.document.close();
nL.visibility = 'show';

document.formlayer = nL;

}
}

function HandleResize()
{
location.reload();
return false;
}

if (NS4)
{
SafeAddOnload(HandleOnload);
window.captureEvents(Event.RESIZE);
window.onresize = HandleResize;
}


</script>

</HEAD>

<BODY>
<b>Enter Sensor Data</b>
<br>
<form id="dynoform" name="dynoform" action="addnewsensor2.php" method="POST">



<script LANGUAGE="JavaScript">
IncludeForm();



</script>

<input type="submit" value="Submit">
</form>

</BODY>
</HTML>


the reason for chaing myoptions to myoptions[] is in the php page:


foreach($_POST["myoptions"] as $index => $val) {
print("myoption[".$index."] = ".$val."<br>");
}



see that way itll post to the php correctly for each field added (at this point the myoptions)

Thats the purpose of this script. So thats why the trouble arrises. Whenever anything in that main part changes, the part where it gets and retains the values is barking about problems, and ive tried changing them and I cant figure them out. I really dont know much javascript, and im trying to learn as much as possible in the shortest amount of time for work.

Willy Duitt
03-12-2004, 04:49 PM
Originally posted by jediman
Plus in that code you posted, where does i increment ? I tried using i++; but with and without it i get errrors. Let me know if youve taken a look at the page.

The while is a loop initself.

eg: while i < gFieldsValue.length

Will step thru and add each gFieldValue to your htmlStr until i reaches the gFieldsValue length. There was no reason to try and add i++

.....Willy

jediman
03-12-2004, 04:52 PM
Ok but it still gives me errors, about where its retaining values? Any way to figure that out, cause im at a loss, and ive been at this for a week , and i really need to finish this :(

sad69
03-12-2004, 05:52 PM
Holy that's some ugly code!

First of all I noticed that I saw some PHP code... I don't think I'm supposed to be able to see any PHP code on the client-side...

Line 88 (on the client-side at least), seems to be giving the php errors, so you may want to take a second look there...

I also don't see where you're creating your <form> tag. You're referring to dynoform somewhere but I don't think you've ever created it, so that's why you're getting an error.

So what's up with that. You're New Type button throws me an error, is that the error you're stuck on right now?

Good luck,
Sadiq.

jediman
03-12-2004, 06:06 PM
<form id="dynoform" name="dynoform" action="addnewsensor2.php" method="POST">



<script LANGUAGE="JavaScript">
IncludeForm();



</script>

<input type="submit" value="Submit">
</form>




There is the form, and yes, as far as the add new type thats whats holding me up. Checout where it does the addnewfield. It first stores the info already entered. Since your suggestion of making myoptions myoptions[] the addfield routine doesnt like it, and thats the part i am stuck at, even though it looks pretty ugly it works for what I need, sans getting that to go. If someone could help me with that,i'd by so darned happy!

sad69
03-12-2004, 06:17 PM
Ok this is what I did:


<script LANGUAGE="JavaScript">
IncludeForm();
alert(document.body.innerHTML);
</script>

And I didn't see any form stuff, just the closing tag. I think that's your whole problem, because you're trying to access multiform through dynoform, but dynoform hasn't been declared. Unless the code on your local machine is different from the code on your server....

But that's the first thing you want to look at fixing -- I don't know how or what's wrong, but the code you posted has the <form...>, but the code from your server does not.

After that, you'll want to look at what's going wrong in that the <?php ... ?> tags are showing up.

Good luck,
Sadiq.

jediman
03-12-2004, 06:47 PM
<script LANGUAGE="JavaScript">
var mycount = 0;
function counter()
{

mycount++;

return mycount;
}


// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{

if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
}
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}
function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload[i]();

for (var j=0;j<gSafeOnload.length;j++)
gSafeOnload[j]();

for (var k=0;k<gSafeOnload.length;k++)
gSafeOnLoad[k]();


}


//
// Main Form Functions
//

// This array holds our form values when we need to regenerate the form
var gFieldValues = new Array(1);

var gFieldValue = new Array(1);

var getFieldValue = new Array(1);



for (var i=0;i<gFieldValues.length;i++)
gFieldValues[i]="";

for (var j=0;j<gFieldValue.length;j++)
gFieldValue[j]="";

for (var k=0;k<getFieldValue.length;k++)
getFieldValue[k]= "";


function GetFormHTML()
{
thiscount = counter();
var htmlStr = '';
htmlStr += '<table><tr><td>Sensor Type</td><td> Address</td><td> Formula</td></tr></table>';
for (var i=0;i<gFieldValues.length;i++)
htmlStr += '<table><tr><td><input type="text" name="myoptions[]" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>"> <input type="text" name="multifield" value="' + gFieldValues[i] + '"> <input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';
htmlStr += '<input type="button" value="New Type" onClick="AddField()">';

return htmlStr;


}



function GetFormObj()
{
var returnObj = null;

if (IE4plus)
{
returnObj = document.dynoform;
}
else if (NS4)
{
returnObj = document.formlayer.document.dynoform;
}
else if (NS6)
{
returnObj = document.getElementById("dynoform");
}
return returnObj;
}

function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}


function UpdateForm()
{
var htmlStr = GetFormHTML();
if (IE4plus)
{
document.all.formlayer.innerHTML = htmlStr;
}
else if (NS4)
{
document.formlayer.document.open();
document.formlayer.document.write(htmlStr);
document.formlayer.document.close();
}
else if (NS6)
{
document.getElementById("formlayer").innerHTML = htmlStr;
}
}

function IncludeForm()
{

var htmlStr = GetFormHTML();

if (IE4plus || NS6)
{
document.write('<DIV ID=formlayer name=formlayer STYLE="position:relative; WIDTH=400px; HEIGHT=50px">' + htmlStr + '</DIV>');
}
else if (NS4)
{
// Because NS needs floating layers, we need a placeholder graphic to force anything
// below the layer content to leave whitespace for the layer. The position of this
// graphic is also used in determining the position of the layer.
document.write('<img name="formlocation" border="0" width="400" height="200" src="images/spacer.gif">');

}

}

//
// Netscape 4.x Ineptness
//
function HandleOnload()
{
if (NS4)
{
var width = document.formlocation.width;
var height = document.formlocation.height;

nL=new Layer(width);
nL.name = "formlayer";
nL.left=document.formlocation.x;
nL.top=document.formlocation.y;
nL.bgColor = "white";
nL.clip.width=width;
nL.clip.height=height;
nL.document.open();
nL.document.write(GetFormHTML());
nL.document.close();
nL.visibility = 'show';

document.formlayer = nL;

}
}

function HandleResize()
{
location.reload();
return false;
}

if (NS4)
{
SafeAddOnload(HandleOnload);
window.captureEvents(Event.RESIZE);
window.onresize = HandleResize;
}


</script>

</HEAD>

<BODY>
<b>Enter Sensor Data</b>
<br>
<form id="dynoform" name="dynoform" action="addnewsensor2.php" method="POST">



<script LANGUAGE="JavaScript">
IncludeForm();



</script>

<input type="submit" value="Submit">
</form>

</BODY>
</HTML>
[code]
please focus on that...code is all there just scroll up a bit.....
Ignore the server. I have that code showing up as php because its NOT a php page and just html, otherwise i would have called it pubtest.php for it not to show, but thats not the point or the problem. The problem is::::
[code]
function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}



more importantly getFieldValue[k] statements....when I change myoptions to myoptions[] , that last bit of code here complains about the fact that its stating myoptions.value is null or not an object. What do i redo on that so that it stops complaining about it? Thats the problem, thats what I need to fix. I dont want to come across as rude or anythng, and I really do appreciate the help, but it seems like I keep posting over and over and eveyrones ignoring what im saying, so lastly:


for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}

complains about myoptions.value , aafter that else being null or not an object...how do i fix it? saying formObj.myoptions[].value and such doesnt seem to fix it... THAT is what I need to fix! PLease focus and help me with that! I dont care about the rest of the code since it works! Thank you!

sad69
03-12-2004, 07:00 PM
Ok rude-boy! lol

formObj is actually null, that's what I'm trying to say in my previous post, that's why it won't find myOptions and whatever else.

This is all because there's no <form> tag. Go to your webpage and try pressing New Type. Look at the error, then view the source and you'll see what I'm talking about.

Correct me if I'm wrong, but if you're trying to reference anything through formObj, everything is going to be null because it doesn't exist.

Sadiq.

sad69
03-12-2004, 07:04 PM
Oops, I didn't see your "inline" message there, it all looked like code.

So you're wanting me to look at the code you're posting, and ignore the website?

I'm looking right now.........

Sadiq.

sad69
03-12-2004, 07:06 PM
Ok, change:


getFieldValue[k]=formObj.myoptions.value;

to:


getFieldValue[k]=formObj.elements["myoptions[]"].value;


And that fixed it for me...

Sadiq.

jediman
03-12-2004, 07:07 PM
Ok, I stuck the form delcaration back in there so heres what it looks like now totally


<script LANGUAGE="JavaScript">
var mycount = 0;
function counter()
{

mycount++;

return mycount;
}


// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{

if (IEmac && IE4) // IE 4.5 blows out on testing window.onload
{
window.onload = SafeOnload;
gSafeOnload[gSafeOnload.length] = f;
}
else if (window.onload)
{
if (window.onload != SafeOnload)
{
gSafeOnload[0] = window.onload;
window.onload = SafeOnload;
}
gSafeOnload[gSafeOnload.length] = f;
}
else
window.onload = f;
}
function SafeOnload()
{
for (var i=0;i<gSafeOnload.length;i++)
gSafeOnload[i]();

for (var j=0;j<gSafeOnload.length;j++)
gSafeOnload[j]();

for (var k=0;k<gSafeOnload.length;k++)
gSafeOnLoad[k]();


}


//
// Main Form Functions
//

// This array holds our form values when we need to regenerate the form
var gFieldValues = new Array(1);

var gFieldValue = new Array(1);

var getFieldValue = new Array(1);



for (var i=0;i<gFieldValues.length;i++)
gFieldValues[i]="";

for (var j=0;j<gFieldValue.length;j++)
gFieldValue[j]="";

for (var k=0;k<getFieldValue.length;k++)
getFieldValue[k]= "";


function GetFormHTML()
{
thiscount = counter();
var htmlStr = '';
htmlStr += '<form id="dynoform" name="dynoform" action="addnewsensor2.php" method="POST"><table><tr><td>Sensor Type</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Formula</td></tr></table>';
for (var i=0;i<gFieldValues.length;i++)
htmlStr += '<table><tr><td><input type="text" name="myoptions[]" value="'+ getFieldValue[i] +'"><input type="hidden" value="<?php $_POST[myoptions[thiscount]];?>"><input type="hidden" value="<?php $_POST[thiscount];?>">&nbsp;<input type="text" name="multifield" value="' + gFieldValues[i] + '">&nbsp;<input type="text" name="address" value="'+ gFieldValue[i] + '"></td><tr></table><input type="hidden" name="thiscounter" value="' + thiscount + '">';
htmlStr += '<input type="button" value="New Type" onClick="AddField()">';

return htmlStr;


}



function GetFormObj()
{
var returnObj = null;

if (IE4plus)
{
returnObj = document.dynoform;
}
else if (NS4)
{
returnObj = document.formlayer.document.dynoform;
}
else if (NS6)
{
returnObj = document.getElementById("dynoform");
}
return returnObj;
}

function AddField()
{

// Save previously entered data here
var formObj = GetFormObj();

for (var i=0;i<gFieldValues.length;i++)
{
if (gFieldValues.length>1)
gFieldValues[i]= formObj.multifield[i].value;

else
gFieldValues[i]= formObj.multifield.value;

}

for (var j=0;j<gFieldValue.length;j++)
{
if(gFieldValue.length>1)
gFieldValue[j]=formObj.address[j].value;

else
gFieldValue[j]=formObj.address.value;
}

for (var k=0;k<getFieldValue.length;k++)
{
if(getFieldValue.length>1)
getFieldValue[k]=formObj.myoptions[k].value;

else
getFieldValue[k]=formObj.myoptions.value;



}


// Create the new field
gFieldValues[gFieldValues.length]="";
gFieldValue[gFieldValue.length]="";
getFieldValue[getFieldValue.length]="";
UpdateForm();

}


function UpdateForm()
{
var htmlStr = GetFormHTML();
if (IE4plus)
{
document.all.formlayer.innerHTML = htmlStr;
}
else if (NS4)
{
document.formlayer.document.open();
document.formlayer.document.write(htmlStr);
document.formlayer.document.close();
}
else if (NS6)
{
document.getElementById("formlayer").innerHTML = htmlStr;
}
}

function IncludeForm()
{

var htmlStr = GetFormHTML();

if (IE4plus || NS6)
{
document.write('<DIV ID=formlayer name=formlayer STYLE="position:relative; WIDTH=400px; HEIGHT=50px">' + htmlStr + '</DIV>');
}
else if (NS4)
{
// Because NS needs floating layers, we need a placeholder graphic to force anything
// below the layer content to leave whitespace for the layer. The position of this
// graphic is also used in determining the position of the layer.
document.write('<img name="formlocation" border="0" width="400" height="200" src="images/spacer.gif">');

}

}

//
// Netscape 4.x Ineptness
//
function HandleOnload()
{
if (NS4)
{
var width = document.formlocation.width;
var height = document.formlocation.height;

nL=new Layer(width);
nL.name = "formlayer";
nL.left=document.formlocation.x;
nL.top=document.formlocation.y;
nL.bgColor = "white";
nL.clip.width=width;
nL.clip.height=height;
nL.document.open();
nL.document.write(GetFormHTML());
nL.document.close();
nL.visibility = 'show';

document.formlayer = nL;

}
}

function HandleResize()
{
location.reload();
return false;
}

if (NS4)
{
SafeAddOnload(HandleOnload);
window.captureEvents(Event.RESIZE);
window.onresize = HandleResize;
}


</script>

</HEAD>

<BODY>



<script LANGUAGE="JavaScript">
IncludeForm();



</script>

<input type="submit" value="Submit">
</form>

</BODY>
</HTML>

Still gives me the error though. Any clue on that then? Cause im still totally lost that it would still give that to me then :-/

sad69
03-12-2004, 07:12 PM
Maybe you didn't read my last reply?

Sadiq.

jediman
03-12-2004, 08:01 PM
oops posted before the reply came up :P gonna check to see if it works :-D

jediman
03-12-2004, 08:15 PM
Yes yes that works! ALLRIGHT!! WEEEHA!! Thank you so much! I can then now apply the same thing to the other two fields and have that submitted too! Thank you SO much :)

sad69
03-12-2004, 08:20 PM
No probs..

Sadiq.

Willy Duitt
03-13-2004, 12:02 AM
I doont spek non english? :rolleyes:

....Willy

jediman
03-13-2004, 12:39 AM
No no, you do :) sorry

actually just one more thing



function formyoptions()
{
foreach($_POST["myoptions"] as $index => $val)
{

print("myoption[".$index."] = ".$val.",");
formultifield();
foraddress();

}
}

function formultifield()
{
foreach($_POST["multifield"] as $index => $val)
{
print("multifield[".$index."] = ".$val.",");
}
}
function foraddress()
{
foreach($_POST["address"] as $index => $val)
{
print("address[".$index."] = ".$val.";<br>");
}
}

been toying with it. having trouble parsing it so it does the myoptions,multifield,address; then the new line...the values all pass just i cant figure out the correct loop for it using the foreach.

sad69
03-13-2004, 01:06 AM
I don't understand what you're trying to do.

Do you want:
myoption[0] multifield[0] address[0]
myoption[1] multifield[1] address[1]
myoption[2] multifield[2] address[2]
...

In that case:


foreach($_POST["myoptions"] as $index => $val) {
print("myoptiosn[".$index."] = ".$myoptions[$index].",");
print("multifield[".$index."] = ".$multifield[$index].",");
print("address[".$index."] = ".$address[$index].";<br>");
}


If not, post exactly what you're looking for (btw, php questions should go in the PHP forum, not in this Javascript forum...).

Hope that helps,
Sadiq.

jediman
03-13-2004, 01:30 AM
Perfect thank you! Thats exactly what I needed :) You have all been a great help :) :) :thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup:

jediman
05-13-2004, 05:06 PM
Can anyone tell me why the latest internet explorer 6 patches break this script? It wont send data right now.

What is the corect way of identitfying internet explorer 6?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum