Dynamic Jsp form content Question

hello

i have a form that i am using to present data
that i want the user to pick and on submit send the data to a query

the data being presented by the form is also dynamic (hopefully)

there are three objects on the form i am having bother with that are bond to a recordset

the objects are CycleID | dropdown list of Number type|,  Cycle Start |text box of text type| and
Cycle End |text box of type text|

The problem is that i want the user to be able to pick the CycleID number from the dropdown list and have the Cycle start and Cycle End boxes automatically/Dynamically display the corresponding data
i am using dreamweaver

How can i do this????

Gaz
Gar04Asked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
> how do i tie this function in with the cycleid dropdown list and in turn with the text field???
> <select name="selectcyc" size="1" >

 <select name="selectcyc" size="1" onchange="updateText(this.options[this.selectedIndex].value)">

0
 
objectsCommented:
you'll either need to re-submit your form to populate the fields.
Or use some javascript to fill in the values.

Are the vlues available on the page?
0
 
Gar04Author Commented:
the last two are i.e.
Cycle start and Cycle end
 in the database they look like this:
number        text                   text
CycleID        CycleStart        CycleEnd
1                  01/01              14/01
2                  15/01              28/01
and so on

i created a recordset from a query that pulls them from the database
so the recordset is available to the page
after that i don't know!

Gaz
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
objectsCommented:
Using js you'd use something like:

<script language="Javascript">
 
   function change()
   {
      update your fields appropriately here
   }

</script>

<select name="abc" onchange="Javascript:change()">
...
0
 
Gar04Author Commented:
Hey i have tried a couple of combinations of this but i am a bit
confused as to where exactly i call the js function
i can't get it to work
can you point me in the right direction??
pls
Gaz

p.s. do i need to change the cycleid name below from "selectCyc1" to "optionValue"???????

this is the dropdown list object that the user changes to effect the
change in the textfield
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 <select name="selectCyc1" size="1" >
                <%
while (rsCyc.next())
{
   Object next = rsCyc.getObject("CycleID");
   String value = (next==null ? "" : next.toString());
%>
                <option value="<%= value %>"><%= value %></option>
                <%}%>
              </select>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

This is the form textfield object that i would like to change as the above cycle id number
is changed by the user on the mouse onchange.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<input name="textcyc" type="text" size="20" >
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

this is the script function to change the value
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<SCRIPT LANGUAGE="JavaScript">
function updateText(optionValue) {
    textcyc = "Start - End'"
    if (optionValue == 1) {
         textcyc = "01/01 - 14/01"
    }
    else if (optionValue == 2) {
         textcyc = "15/01 - 28/01"
    }
    else if (optionValue == 3) {
         textcyc = "29/01 - 11/02"
    }
    else if (optionValue == 4) {
         textcyc = "12/02 - 25/02"
    }
    else if (optionValue == 5) {
         textcyc = "26/02 - 11/03"
    }
    else if (optionValue == 6) {
         textcyc = "12/03 - 25/03"
    }
    else if (optionValue == 7) {
         textcyc = "26/03 - 08/04"
    }
    else if (optionValue == 8) {
         textcyc = "09/04 - 22/04"
    }
    else if (optionValue == 9) {
         textcyc = "23/04 - 06/05"
    }
    else if (optionValue == 10) {
         textcyc = "07/05 - 20/05"
    }
    else if (optionValue == 11) {
         textcyc = "21/05 - 03/06"
    }
    else if (optionValue == 12) {
         textcyc = "04/06 - 17/06"
    }
    else if (optionValue == 13) {
         textcyc = "18/06 - 01/07"
    }
    else if (optionValue == 14) {
         textcyc = "02/07 - 15/07"
    }
    else if (optionValue == 15) {
         textcyc = "16/07 - 29/07"
    }
    else if (optionValue == 16) {
         textcyc = "30/07 - 12/08"
    }
    else if (optionValue == 17) {
         textcyc = "13/04 - 26/08"
    }
    else if (optionValue == 18) {
         textcyc = "27/08 - 09/09"
    }
    else if (optionValue == 19) {
         textcyc = "10/09 - 23/09"
    }
    else if (optionValue == 20) {
         textcyc = "24/09 - 07/10"
    }
    else if (optionValue == 21) {
         textcyc = "08/10 - 21/10"
    }
    else if (optionValue == 22) {
         textcyc = "22/10 - 04/11"
    }
    else if (optionValue == 23) {
         textcyc = "05/11 - 18/11"
    }
    else if (optionValue == 24) {
         textcyc = "19/11 - 02/12"
    }
    else if (optionValue == 25) {
         textcyc = "03/12 - 16/12"
    }
    else if (optionValue == 26) {
         textcyc = "17/12 - 31/12"
    }
   
document.all("CycleID").innerText = text;
}
</SCRIPT>


<P ID="CycleID">This is your initial display.</P>

<FORM><select name="textcyc" onchange="updateText(this.options[this.selectedIndex].value)">
<option value=1>option1</option><option value=2>option2</option><option value=3>option 3</option>
<option value=4>option 4</option><option value=5>option 5</option><option value=6>option 6</option>
<option value=7>option 7</option><option value=8>option 8</option><option value=9>option 9</option>
<option value=10>option 10</option><option value=11>option 11</option><option value=12>option 12</option>
<option value=13>option 13</option>option value=14>option 14</option><option value=15>option 15</option>
<option value=16>option 16</option><option value=17>option 17</option><option value=18>option 18</option>
<option value=19>option 19</option><option value=20>option 20</option><option value=21>option 21</option>
<option value=22>option 22</option><option value=23>option 23</option><option value=24>option 24</option>
<option value=25>option 25</option><option value=26>option 26</option>


          </select>
</FORM>
0
 
Gar04Author Commented:
hey
i am not sure how to change the code above to suit my needs
can you help?
gaz
0
 
Gar04Author Commented:
this is basically what the form objects look like:
             _____                    ______
cycle id |_____|         dates |_____|

cycle id is a dropdown list with values 1 to 26

when the user selects 1, dates should dynamically display 01/01 - 14/01
when the user selects 2, dates should dynamically display 15/01 - 28/01
and so on

i have tried to implement this by using the code in the last comments but i can't get it to work
pls
help
Gaz  
0
 
objectsCommented:
> document.all("CycleID").innerText = text;

shouldn't that be:

document.all("CycleID").innerText = textcyc;
0
 
Gar04Author Commented:
u r right
i spotted that earlier
sorry i had posted that comment first
gaz
0
 
Gar04Author Commented:
how do i tie this function in with the cycleid dropdown list and in turn with the text field???

CycleID List:
 <select name="selectcyc" size="1" >
                <%
while (rsCyc.next())
{
   Object next = rsCyc.getObject("CycleID");
   String value = (next==null ? "" : next.toString());
%>
                <option value="<%= value %>"><%= value %></option>
                <%}%>

Text box:

 <input name="textfield2" type="text" size="20">
0
 
Gar04Author Commented:
the example above gives this
with a <select name, but isn't that only for a list/menu object??
i am a little confused as always!!

<FORM><select name="textcyc" onchange="updateText(this.options[this.selectedIndex].value)">
<option value=1>option1</option><option value=2>option2</option><option value=3>option 3</option>
<option value=4>option 4</option><option value=5>option 5</option><option value=6>option 6</option>
<option value=7>option 7</option><option value=8>option 8</option><option value=9>option 9</option>
<option value=10>option 10</option><option value=11>option 11</option><option value=12>option 12</option>
<option value=13>option 13</option>option value=14>option 14</option><option value=15>option 15</option>
<option value=16>option 16</option><option value=17>option 17</option><option value=18>option 18</option>
<option value=19>option 19</option><option value=20>option 20</option><option value=21>option 21</option>
<option value=22>option 22</option><option value=23>option 23</option><option value=24>option 24</option>
<option value=25>option 25</option><option value=26>option 26</option>


          </select>
</FORM>
0
 
Gar04Author Commented:
so this is what i did and nothing is working:

<select name="selectcyc" size="1" onchange="updateText(this.options[this.selectedIndex].value)">
                <%
while (rsCyc.next())
{
   Object next = rsCyc.getObject("CycleID");
   String value = (next==null ? "" : next.toString());
%>
                <option value="<%= value %>"><%= value %></option>
                <%}%>
              </select>

and the text field :

<input name="textcyc" type="text" size="20">
0
 
objectsCommented:
> document.all("CycleID").innerText = text;

isn't it the textcyc field that you want to set?
0
 
Gar04Author Commented:

>document.all("CycleID").innerText = text;

yes, i have changed this already to

document.all("CycleID").innerText = textcyc;
0
 
objectsCommented:
No thats setting innerText of CycltID, not the input field named 'textcyc'
0
 
Gar04Author Commented:

So is this correct?????????:

documents.all("textcyc").innerText = textcyc;
0
 
objectsCommented:
try something like:

document.form[0].textcyc.value = textcyc;
0
 
Gar04Author Commented:
well that seems to work now
 thanks a lot
sorry about the confusion
i borrowed and modified the code
i am still a novice but am learning and you guys r a great help


one more question (you don't have to answer this if yu think that it is a seperate issue, i will open another thread and award more points
just let me know)
could i have a similar piece of code that pulls the data from a recordset as opposed to
just typed in values like the last ???????

<SCRIPT LANGUAGE="JavaScript">
function populateField(optionValue) {
    textcyc = "locations"
    if (optionValue == 1) {
         recordset1                           >>>>>>>>>>>>> would i have to have code here to access the database and retrieve the results?????
         that populates field
    }
    else if (optionValue == 2) {
              recordset2
              that populates field

    }
    else if (optionValue == 3) {
              recordset3
              that populates field
    }
    else if (optionValue == 4) {
              recordset4
              that populates field
    }

   
document.all("locationsfield").innerText = whatever recordset;
}
</SCRIPT>
0
 
objectsCommented:
javascript runs on the clients, whereas your jsp runs on the server so no you cannot do that.
Instead you would need to load all possible data required from the database (for all options), and have your js display the appropriate data.
I think one of the questions i posted earlier has an example of something similiar.
0
 
Gar04Author Commented:
<<<<<<<<document.form[0].textcyc.value = textcyc;

i have four small forms on this page that i hope can all use this
if i change it to the above will it effect the forms at all??
gaz
0
 
objectsCommented:
give your forms names and use:

document.formname.textcyc.value = textcyc;

or pass the form to the js function.

0
 
Gar04Author Commented:
cheers for the
answer
i don't think that i will attempt to implement that just yet
i should know enough by now to know that js is client side and jsp server
i was just curious
there is just too much data to do that the way you just showed me and i was wondering if there is another way
i will check out those examples

thanks again
i will send your points in a mo
Gaz
0
 
Gar04Author Commented:
excellent

cheers again

gaz
0
 
objectsCommented:
> i was wondering if there is another way

another way would be to submit the form whenever an option selected.
0
 
objectsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.