...

View Full Version : !!Noob needing help!!



earthsiege
07-12-2004, 02:21 PM
hey ppl, :thumbsup:
usually all my work is with Php but recently ive had to get with the times and start using java but im having series of problems.

im writing simple java code that multiplies two numbers together from two fileds but the thing is the two fileds keep are inside a php loop and the field names keep changing as the loop goes foreward (us till with me? :confused: ).
eg.
while $i < $b
<input name="moh$i" etc>
$i++;
endwhile;

.....
is there anyway of doing the same thing in my java script so that the address field change in a loop similair to th one above?

:eek:

LynxGrr
07-12-2004, 03:21 PM
your incrementing $i each time the loop passes through... therefore your input box will be known as moh1 the first time, followed by moh2 the second and so forth....

If you already know this then no.. im not with you! :confused: he he he

earthsiege
07-12-2004, 05:15 PM
no s*** sherlock!lol :mad:
i know that each time the input name changes but my problem is the fact that i need the ame type of thing for the java script but i already tried putting it into a loop which didnt work....

Basscyst
07-12-2004, 06:02 PM
Somthing like this?



<script type="text/javascript">
var i=0;
var b=4;
var str="";
while(i<b)
{
str+='<input type="text" name="moh'+i+'">';
i++;

}
document.write(str);

</script>


Basscyst

PS. It's not nice to be rude to people who are helping you.

earthsiege
07-12-2004, 06:46 PM
I think that i may have put my question forward ina dodgy way.
look weve got two files lets say a&b:
while ($i < $n):
<input name='a$i' onchange="do_math()">;
<input name='b$i'>;
<input name='collection$i'>;
$i ++;
endwhile
okay now we want to have an "onchange" function called do_math() in java script which multiplies a by b but THIS HAS TO BE DONE N-1 times.....
and each a and b is a different value being read of a mysql database.
okay,
wot would it look like ive got somefin like below but it doesnt work, anyone help?
:(
<script language="JavaScript" >
function do_math()
for (i=1; i <= $A; i = i + 1) {
var b = eval(document.step5.a$i.value)
var a = eval(document.step5.b$i.value)
var multi = a * b
document.step5.collection.value= multi;
}
</script>

Basscyst
07-12-2004, 06:58 PM
In your 2nd shown function

This should be all you need:



function do_math(){
for (i=1; i <= $A; i++) {
var b = document.step5.a$i.value
var a = document.step5.b$i.value
var multi = a * b
document.step5.collection.value= multi;
}


In the first function I'm not sure what you are asking do you want that done in JS?

The above should work with no problem assuming there is a clientside value for $A.

Basscyst

earthsiege
07-12-2004, 07:19 PM
thats nearly wot i was thinkin but its still not workin, :(
if theres ne1 else who can help me pls post a reply...sob...sob...sob

glenngv
07-13-2004, 10:23 AM
Is this what you want?


while ($i < $n):
<input name='a$i' onchange="do_math(this,'b$i','collection$i')">;
<input name='b$i'>;
<input name='collection$i'>;
$i ++;
endwhile
...
function do_math(objA, bName, collName){
objA.form.elements[collName].value=objA.value*objA.form.elements[bName].value;
}

earthsiege
07-13-2004, 09:40 PM
yo man,
you are the holy man.
thanks a lot.
dont know why i didnt think of it that way myself...lol
thanks anyway.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum