Click to See Complete Forum and Search --> : setting variable inline a script line


premanands
03-10-2003, 01:15 PM
I am building a dynamic JS form.
I created three drop down fields in the body as follows

1. BS graduation date
2. MS graduation date
3. Phd graduation date

<form NAME="selectdate">
<script> gradDate("BS");</SCRIPT><br>
<script> gradDate("MS");</SCRIPT><br>
<script> gradDate("PH");</SCRIPT>
</FORM>

the function gradDate will create the dropdown box for month and year.
I am also creating 3 hidden input fields.
I create date objects from the month and date drop down fields and assign the date to the hidden fields so that I can pass on to another page.

form.[hiddenfield].value = (grad.getMonth()+1) + "/" +grad.getDate() + "/" + (grad.getFullYear());

i declared hiddenfield as a variable. how can I put the variable inbetween "form" and "value"

thanks in advance
Prem

AdamBrill
03-10-2003, 01:30 PM
Did you make the hidden field like this?

<input type=hidden name=hiddeninput>

If so, then you would change the value like this:

document.selectdate.hiddeninput.value = "whatever";

where selectdate is the name of your form. Is that what you wanted? If not, please try to explain better...

premanands
03-10-2003, 01:48 PM
I am sorry i didnt explain clearly.
I have 2 drop boxes for each graduation date.
I create dates out of them like this...

//Start function
function makeDate(hiddenDate){
form2 = document.selectdate;
grad = new Date (form2.[BS]yy.value,form2.[BS]mm.value,1);

form2.hiddenDate.value = (grad.getMonth()+1) + "01" + "/" + (grad.getFullYear());

}

//End function

Notice, i pass the name of the hidden field.
I create the three hidden fields dynamically in another function
like this...
document.write("<INPUT TYPE='Hidden' NAME='hiddenDate'>");

the [BS] is hard coded. actually .. i want it this way...
"[variabe]mm" together as a string.

I want the final output like this
form2.BS.value = '05/01/2003', for example.

thanks
Prem

premanands
03-10-2003, 01:58 PM
i have the file here

premanands
03-10-2003, 02:12 PM
I got a work around. This is fine.
But if i could insert a variable in place of BS,MS and PH.. i could save 6 lines.
Please tell me an efficient one.
---------------------------------

function makeDate()
{
Bgrad = new Date(form2.BSyy.value,form2.BSmm.value-1,1);
Mgrad = new Date(form2.MSyy.value,form2.MSmm.value-1,1);
Pgrad = new Date(form2.PHyy.value,form2.PHmm.value-1,1);

form2.BSDate.value = (Bgrad.getMonth()+1) + "/" +"01" + "/" + (Bgrad.getFullYear());
form2.MSDate.value = (Mgrad.getMonth()+1) + "/" +"01" + "/" + (Mgrad.getFullYear());
form2.PHDate.value = (Pgrad.getMonth()+1) + "/" +"01" + "/" + (Pgrad.getFullYear());

alert(form2.BSDate.value);
alert(form2.MSDate.value);
alert(form2.PHDate.value);

}
--------------------------------

thanks again
Prem

premanands
03-10-2003, 03:02 PM
I got a work around. This is fine.
But if i could insert a variable in place of BS,MS and PH.. i could save 6 lines.
Please tell me an efficient one.
---------------------------------

function makeDate()
{
Bgrad = new Date(form2.BSyy.value,form2.BSmm.value-1,1);
Mgrad = new Date(form2.MSyy.value,form2.MSmm.value-1,1);
Pgrad = new Date(form2.PHyy.value,form2.PHmm.value-1,1);

form2.BSDate.value = (Bgrad.getMonth()+1) + "/" +"01" + "/" + (Bgrad.getFullYear());
form2.MSDate.value = (Mgrad.getMonth()+1) + "/" +"01" + "/" + (Mgrad.getFullYear());
form2.PHDate.value = (Pgrad.getMonth()+1) + "/" +"01" + "/" + (Pgrad.getFullYear());

alert(form2.BSDate.value);
alert(form2.MSDate.value);
alert(form2.PHDate.value);

}
--------------------------------

thanks again
Prem

AdamBrill
03-10-2003, 04:16 PM
I'm sorry... I didn't understand what you were asking. :( I think this is what you want:eval('form2.'+TheVariable+'Date.value = (Bgrad.getMonth()+1) + "/" +"01" + "/" + (Bgrad.getFullYear())')
Just put your variable in there and see if that works. Let me know if you need more help... :)

premanands
03-10-2003, 04:48 PM
Yes... this is what I was looking for..
Thank you very very much!
I am not into JS.. thats the problem.
I use it only when I need.