Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamic Jsp form content Question

Posted on 2004-03-27
26
Medium Priority
?
348 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:Gar04
  • 14
  • 12
26 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10696439
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
 

Author Comment

by:Gar04
ID: 10696481
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
 
LVL 92

Expert Comment

by:objects
ID: 10696524
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Gar04
ID: 10699302
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
 

Author Comment

by:Gar04
ID: 10699681
hey
i am not sure how to change the code above to suit my needs
can you help?
gaz
0
 

Author Comment

by:Gar04
ID: 10699762
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
 
LVL 92

Expert Comment

by:objects
ID: 10700041
> document.all("CycleID").innerText = text;

shouldn't that be:

document.all("CycleID").innerText = textcyc;
0
 

Author Comment

by:Gar04
ID: 10700367
u r right
i spotted that earlier
sorry i had posted that comment first
gaz
0
 

Author Comment

by:Gar04
ID: 10700419
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
 

Author Comment

by:Gar04
ID: 10700427
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
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 10700463
> 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
 

Author Comment

by:Gar04
ID: 10700673
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
 
LVL 92

Expert Comment

by:objects
ID: 10700703
> document.all("CycleID").innerText = text;

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

Author Comment

by:Gar04
ID: 10700721

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

yes, i have changed this already to

document.all("CycleID").innerText = textcyc;
0
 
LVL 92

Expert Comment

by:objects
ID: 10700749
No thats setting innerText of CycltID, not the input field named 'textcyc'
0
 

Author Comment

by:Gar04
ID: 10700760

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

documents.all("textcyc").innerText = textcyc;
0
 
LVL 92

Expert Comment

by:objects
ID: 10700776
try something like:

document.form[0].textcyc.value = textcyc;
0
 

Author Comment

by:Gar04
ID: 10700853
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
 
LVL 92

Expert Comment

by:objects
ID: 10700874
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
 

Author Comment

by:Gar04
ID: 10700878
<<<<<<<<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
 
LVL 92

Expert Comment

by:objects
ID: 10700891
give your forms names and use:

document.formname.textcyc.value = textcyc;

or pass the form to the js function.

0
 

Author Comment

by:Gar04
ID: 10700912
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
 

Author Comment

by:Gar04
ID: 10700925
excellent

cheers again

gaz
0
 
LVL 92

Expert Comment

by:objects
ID: 10700930
> i was wondering if there is another way

another way would be to submit the form whenever an option selected.
0
 
LVL 92

Expert Comment

by:objects
ID: 10700931
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question