Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JSP Form Problem Input text box

Options
  • 24-05-2007 12:04pm
    #1
    Registered Users Posts: 1,552 ✭✭✭


    Ive 2 forms on the one page.

    A userAddress string is inputted via a textbox on the first form.

    There is a input hidden field in the second form that needs to retrieve the string inputted in the text box on the first form into its value.

    Can this be done?

    Heres some code that shows my problem
    <%
    String userAddress = (null == (userAddress = (String)request.getAttribute("useraddress")) ? "" : userAddress);
     
    %>
     
    <form action="/servPublicArea" method="POST" name="form1" onsubmit="return checkFields();">
    <div id="email">
    		 <input type="text" name="email" value="<%=userAddress%>" size="50">
    	</div>
     
    <div id="release">
    		<input id="submitButton" name="submit" type="submit" value="Release Mail" onclick="this.enabled = false; return true;">
    		       
    		
    	</div>
    </form>
     
    <form action="/servPublicArea" method="POST" name="whitelistform" onsubmit="return checkFields();"> 
    	<input type="hidden" name="view" value="whitelistandrelease">
    	<input type="hidden" name="emailwhitelist" value="<%=userAddress%>">
     
    <div id="release">
    		<br>
    		<input id="submitButton2" name="submit2" type="submit" value="Release Mail and Whitelist Sender" onclick="this.enabled = false; return true;">
    		
    	</div>
     
    </form>
    


Comments

  • Registered Users Posts: 7,678 ✭✭✭Trampas


    Why have you two forms on the one page?


  • Registered Users Posts: 1,552 ✭✭✭quinnd6


    Because Ive 2 buttons performing different actions so I think they need to be in different forms


  • Registered Users Posts: 1,552 ✭✭✭quinnd6


    Maybe Id just be better off having both submit buttons in the same form.

    How do I detect which button is pressed?


  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    quinnd6 wrote:
    Maybe Id just be better off having both submit buttons in the same form.

    How do I detect which button is pressed?

    Regular <input type=submit name="" value=""> buttons put a name=value pair in the query string that has the name of the button and the button text as its value.

    Looking up the parameter will tell you if the button was pressed or not. If getParameter("button1") is null then you know button 1 was not pressed etc.

    If you wanted the buttons to go to different pages then I think you would have to use javascript to achieve this.


  • Registered Users Posts: 1,552 ✭✭✭quinnd6


    Is there something wrong with this?

    <%if(request.getParameter("submitButton")!=null){%>
    <input type="hidden" name="view" value="spamrel">
    <% } %>


  • Advertisement
  • Registered Users Posts: 6,240 ✭✭✭hussey


    A userAddress string is inputted via a textbox on the first form.

    There is a input hidden field in the second form that needs to retrieve the string inputted in the text box on the first form into its value.

    Can this be done?

    easist way is through JS - on your 2nd form, have a method when the user submits the form, copy the Form1.field.value to the Form2.hiddenfield.value etc

    I think the JS is : document.[FormName].[fieldname].value

    ************
    Is there something wrong with this?

    <%if(request.getParameter("submitButton")!=null){%>
    <input type="hidden" name="view" value="spamrel">
    <% } %>
    No - but only if you are posting a form to the jsp


Advertisement