Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submitting hidden values on the form with onSelect option

 
anita prat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp pn which I have two drop down lists. I don't have submit button on the form. There is top menu which lists several options, like add User, add Customer which will trigger their respective actions. But before such an action is triggered, the State and Country names from the dropdown need to be selected which will be applied to all the actions . I have tried using hidden values for these state and country values in the dropdown but I am unable to understand how to submit . I have used onSelect option which will trigger a javascript to submit the form. ANd for this form i have written a dummy action which will forward to the same jsp. But not really sure what I am doing is the right way. CAn someone help?
 
Mkunal badgujar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically you are submitting the form two times with each of the onselect. this is annoying experinence for user . Intead checking the both values on either of the select and passing these values on top menu select will help performance. writing a javascript will be lot of coding instead use jquery.

Regards,
kunal
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anita prat wrote: But before such an action is triggered, the State and Country names from the dropdown need to be selected which will be applied to all the actions . I have tried using hidden values for these state and country values in the dropdown but I am unable to understand how to submit .


I am not getting the question. The dropdown values get submitted automatically with the form. There is no need to have them as separate parameters to submit. Is it that the drop-downs are in a form different than the one that is getting submitted?
 
anita prat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the two country and state fields are part of the same form which is renedered upon successful login. They have to be available throughtout the session , the actions that get triggered from the top nav on this form need these values. This is what I have now:
HomeForm : countryName,stateName - String values
countryList,stateList - arrayLists

HomeAction.execute(): HomeForm welcomeForm = (HomeForm)form;
String ctryName = welcomeForm.getCountryName();
String stateName = welcomeForm.getStateName();
ArrayList ctryList = welcomeForm.getCountryList();
ctryList.add(ctryName);
ArrayList stateList = welcomeForm.getStateList();
stateList.add(stateName);

request.getSession().setAttribute("welcomeForm",welcomeForm);
return mapping.findForward("homePage");

In LoginAction: execute():
ValueObject vo = new ValueObject();
HomeForm welcomeForm= new HomeForm();
ArrayList<ValueObject> CtryStateLList = DAO.getStateAndCountryList();
Iterator it = CtryStateList.iterator();

ArrayList<String> stateList = new ArrayList();
ArrayList<String> countryList = new ArrayList();
while(it.hasNext()){
vo = (ValueObject)it.next();

stateList.add(vo.getState());
countryList.add(vo.getCountry());
}

welcomeForm.setStateList(stateList);
welcomeForm.setCountryList(countryList);
request.getSession().setAttribute("welcomeForm", welcomeForm);
return mapping.findForward("homePage");


home.jsp:
<script language="JavaScript" type="text/javascript">
function submitForm(fieldValue1,fieldValue2) {
document.welcomeForm.franchiseName.value=fieldValue1;
document.welcomeForm.countryName.value = fieldValue2;
document.welcomeForm.submit;
}
</script>

<html:form method=" post" action="welcome" >
<input type="hidden" name="stateName" >
<input type="hidden" name="countryName">
<input type="submit" onselect="javascript:submitForm('stateName','countryName');">
<br/><br/><br/>
<div class="form-holder">
<b>Select State</b>
<span>
<!--Select Name-->
<h6>Select Participant Name</h6>
<html:select property="stateList">
<htmlptionsCollection name="welcomeForm" property="stateList" label="stateName" />
</html:select>

<!--Select Country-->
<br />
<h6>Select Participant Country</h6>
<select name="" title="Click to select country">
<option value="france">France</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="tour">four</option>
</select>
 
anita prat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody respond to my question? I am still not able to resolve this.
 
Ravi Khadgi
Greenhorn
Posts: 20
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
anita prat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , Rahul. I implemented what you mentioned in your post, now the issue is when i click the target action from the top nav tab to which the two hidden values on the homepage are submitted to, I get a null pointer in that target action when I try to get these values from the request.

In my target action:
String option = request.getparameter("option");
String state = request.getParameter("state");

these values are null. how do I store these values in the request in that jsp. Because in the input tag the value is not specified, it is blank.

<input type="hidden" name="hiddenOption" value="">

I appreciate your help!
 
Orton K Randy
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use JS to set those hidden parameters. Oh wait that's what you did there or did you? I see this usage in your JS.


when there's no input element with attribute 'id'(id="option" or id="state")?

Try this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic