PDA

View Full Version : [RESOLVED] HELP passing values to JS function


Reiss
07-08-2009, 07:46 AM
Hi All,
Im new to javascript, but I've learned to write a function that copies the values of 1 text input (day1_00) to another (day2_00)

like this -

function data_copy()
{
document.itinerary.day2_00.value=document.itinerary.day1_00.value;
}
<a href="#" onclick="data_copy()">&copy;</a>


The above code works fine, but what I would like to do is make the function more dynamic as I have to repeat it a lot but can't seem to find the correct syntax for something like this -


function data_copy(day1,day2)
{
document.itinerary.(day1).value=document.itinerary.(day2).value;
}
<a href="#" onclick="data_copy(day1_00,day2_00)">&copy;</a>

obviously the above doesn't work, so how do I pass the values and use them in my function?
many thanks

Jon Hanlon
07-08-2009, 07:40 PM
document.itinerary[day1].value=document.itinerary[day2].value;

<a href="#" onclick="data_copy('day1_00','day2_00')">&copy;</a

Reiss
07-09-2009, 03:15 AM
Perfect!
I really need to learn some basic Javascript, wasted so much time trying brackets,braces,dots, plus signs every damn combination I could think of!

Thanks Jon Hanlon