SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dinamically change a text field value

    Hello!
    I wonder if some one could help.
    I am developing a "search page" in jsp. It works fine now, and the results are showed into a form.
    Now ,the data of this form can be updated by the user.

    The problem is that the form has two select boxes , and if the value of these select boxes change , another text field in the form should be updated with a certain new information.
    I mean the first select box has two options , OPTION A and OPTION B.
    If the user change it to OPTION A, the text field in the form should be updated with a value ( a different value from the drop down list).
    If the OPTION is B, the text field value will depend on the second select box choice.
    I want to control this using Javascript...but for the moment I can not change the default value of the text box by a new one!!!
    I am trying to do it , jus calling to a function update(level) on the onchange event and this function is like follows:
    Code:
    function update(level)
    {
     	document.EscalationID.escalationmanager.value = hola;
     	document.EscalationID.submit();
    }
    but never happens with the text field!!!! Why I can not refresh the text field with a new value???

  2. #2
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is hola a variable or should it not be
    Code:
    function update(level)
    {
     	document.EscalationID.escalationmanager.value = "hola";
     	document.EscalationID.submit();
    }

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, it was a mistake while posting code...but I have tried it with the " " and nothing happens!
    the problem is taht the text field has a default value ( it takes it from teh database) and with the onchange evnet I can not change it again!!!

  4. #4
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when do you trigger the function ?

  5. #5
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I call the function in the onchange event of the select boxes.
    Here I post some code ( I am also using jsp to populate the combo boxes)
    Code:
    <script language="javaScript">
    
    self.resizeTo(700,700) 
    
    <!--
    
    function getSelected( selectbox ) 
    {
       for (i=0;i<selectbox.length;i++)
          if (selectbox.options[i].selected) return selectbox.options[i];
    }
    
    function update(level)
    {
     	
     	document.EscalationID.escalationmanager.value = "hola";
     	document.EscalationID.submit();
     
    }
    // -->
    </script>
    And here I put the code for the select boxes:
    Code:
    <P>Escalation ID: <INPUT TYPE="text" NAME="EscalationId"  VALUE="<%= EscalationId %>" READONLY>
    <P>Type of Escalation : <SELECT NAME="escalationType" onchange="javascript:update(1)">
     
    <%
    ResultSet rst2 = QueryID.EscalationType();
     
    while (rst2.next())
    {
    	String option = rst2.getString(1);
              
    %>
    	<option <%=option.equals(EscalationType)?"selected":""%>><%=option%></option>
    	<%
    }
    rst2.close();
    %>
    </SELECT><P>
     
     
     
    Customer : <SELECT NAME="customer" onchange="javascript:update(2)">
    <%
    ResultSet rst3 = QueryID.Customer();
     
    while (rst3.next())
    {
    	String option = rst3.getString(1);
              
    %>
    	<option <%=option.equals(CUSTOMER)?"selected":""%>><%=option%></option>
    	<%
    }
    rst3.close();
    %>
    </SELECT><P>

  6. #6
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I first though you wer trying to modify value of input type text...

    you are modifying value of option, not selectedIndex ...

  7. #7
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again,
    I am trying to modify the value of the text box (called escalationmanager).
    The text box , should change its value according to the selection chosen in the select box....
    Since I am just trying to change the text field value ( I mean, for the moment not analyze which option has been selected), I am calling the Javascript function update(level) in the onchange event of both select boxes.
    The form is called EscalationID , the text field is called escalationmanager and I think that the text field value should change when I call the function update (level) Doesn´t it?

    Code:
    <script language="javaScript">
    <!--
    
    function getSelected( selectbox ) 
    {
       for (i=0;i<selectbox.length;i++)
          if (selectbox.options[i].selected) return selectbox.options[i];
    }
    function update()
    {
    	document.EscalationID.escalationmanager.value = "hola";
     	document.EscalationID.submit();
    }
    // -->
    </script>
    HTML Code:
    <FORM NAME="EscalationID" METHOD="POST">
    <P> Escalation Manager : <INPUT TYPE="text" NAME="escalationmanager" VALUE="<%=EscalationManager%>" SIZE ="60">[
    <P>Type of Escalation : SELECT NAME="escalationType" onchange="javascript:update(1)" >

  8. #8
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There must be something wrong somwhere in your code because this works perfectly :

    Code:
    <FORM NAME="EscalationID" METHOD="POST"> 
    <P> Escalation Manager : <INPUT TYPE="text" NAME="escalationmanager" VALUE="coucou" SIZE ="60">
    </form>
    <script>
    document.EscalationID.escalationmanager.value="hello"
    </script>

  9. #9
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I finally realized where was the error...
    The problem were that in with the update function I submited the form again , and that caused a new query to the database ( the jsp code) and this was the reason that the text field value never changed.
    I have removed the line
    Code:
    document.EscalationID.submit();
    from the update function and now it works perfectly!!
    Thanks a lot for your help!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •