We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Submit form and Set Values with JavaScript

Medium Priority
657 Views
Last Modified: 2012-06-27
I am submitting a java form with links and javascript and setting the values at the same time.

When I do this I get an error from FireFox that says, "document.LinkElementEdit is undefined".
And another that says, "all is not defined".

Here is my code below. On the links you only really need pay attention to the href and onclick events, the others do unrelated functions.
<form name="LinkElementEdit" target="link_nav3" method="post" action="<%= response.encodeURL("DynamicLinkElementAddExecuteServlet") %>">
 
<%@ include file="/includes/error_message.jsp" %>
<input type="hidden" name="action" value="">
<input type="hidden" name="success" value="<%= response.encodeURL("DynamicPagesEditServlet?action=&success=m1_dynamic_link_3rd.jsp&element_ID=22&error="+ request.getServletPath()+"&"+com.ideaorbit.servlets.DynamicPagesEditServlet.HTTP_REQUEST_FIELD_KEY_ABOUT_PAGE_ID+"="+ResponseBean.getDynamicPagesID(0)+"&"+com.ideaorbit.servlets.DynamicLayoutsEditServlet.HTTP_REQUEST_FIELD_KEY_ABOUT_LAYOUT_ID+"="+ResponseBean.getDynamicLayoutsID(0) ) %>">
<input type="hidden" name="error" value="<%= request.getServletPath() %>">
 
<input id="placementLocal" style="visibility:hidden;" type="hidden" name="<%= com.ideaorbit.servlets.DynamicLinkElementAddExecuteServlet.HTTP_REQUEST_FIELD_KEY_DYNAMIC_LINK_ELEMENT_PLACEMENT %>" value="" />
<input id="placementPage" style="visibility:hidden;" type="hidden" name="<%= com.ideaorbit.servlets.DynamicLinkElementAddExecuteServlet.HTTP_REQUEST_FIELD_KEY_DYNAMIC_LINK_ELEMENT_PLACEMENT_PAGE %>" value="" />
 
<a id="link_to_map" onClick="document.getElementById('placementLocal').value=top; document.getElementById('placementPage').value=all;" href="javascript:document.LinkElementEdit.submit();" target="link_nav3" onMouseOver="extAreaOver('site_template','top'); document.getElementById('topBullet').style.color='red';" onMouseOut="extAreaOut('site_template','top'); document.getElementById('topBullet').style.color='transparent';">Top</a><span id="topBullet" class="bulletOn">&larr;</span><br>
<a id="link_to_map" onClick="document.getElementById('placementLocal').value=header; document.getElementById('placementPage').value=page;" href="javascript:document.LinkElementEdit.submit();" target="link_nav3" onMouseOver="extAreaOver('site_template','header'); document.getElementById('headerBullet').style.color='red';" onMouseOut="extAreaOut('site_template','header'); document.getElementById('headerBullet').style.color='transparent';">Header</a><span id="headerBullet" class="bulletOn">&larr;</span><br>
 
</form>

Open in new window

Comment
Watch Question

HonorGodSoftware Engineer
CERTIFIED EXPERT

Commented:
document.all is an IE thing.

You probably want to use something like:
var field = document.getElementById( 'LinkElementEdit' )
if ( field ) {
 ...
} else {
  alert( 'Field not found: id="LinkElementEdit"' )
}

Open in new window

Author

Commented:
Thank you for your help

 I don't have a document.all? I have .value=all.

I tried getting the name of the form and it found it just fine...
Try this
<form name="LinkElementEdit" target="link_nav3" method="post" action="<%= response.encodeURL("DynamicLinkElementAddExecuteServlet") %>">
 
<%@ include file="/includes/error_message.jsp" %>
<input type="hidden" name="action" value="">
<input type="hidden" name="success" value="<%= response.encodeURL("DynamicPagesEditServlet?action=&success=m1_dynamic_link_3rd.jsp&element_ID=22&error="+ request.getServletPath()+"&"+com.ideaorbit.servlets.DynamicPagesEditServlet.HTTP_REQUEST_FIELD_KEY_ABOUT_PAGE_ID+"="+ResponseBean.getDynamicPagesID(0)+"&"+com.ideaorbit.servlets.DynamicLayoutsEditServlet.HTTP_REQUEST_FIELD_KEY_ABOUT_LAYOUT_ID+"="+ResponseBean.getDynamicLayoutsID(0) ) %>">
<input type="hidden" name="error" value="<%= request.getServletPath() %>">
 
<input id="placementLocal" style="visibility:hidden;" type="hidden" name="<%= com.ideaorbit.servlets.DynamicLinkElementAddExecuteServlet.HTTP_REQUEST_FIELD_KEY_DYNAMIC_LINK_ELEMENT_PLACEMENT %>" value="" />
<input id="placementPage" style="visibility:hidden;" type="hidden" name="<%= com.ideaorbit.servlets.DynamicLinkElementAddExecuteServlet.HTTP_REQUEST_FIELD_KEY_DYNAMIC_LINK_ELEMENT_PLACEMENT_PAGE %>" value="" />
 
<a id="link_to_map" onClick="document.getElementById('placementLocal').value='top'; document.getElementById('placementPage').value='all';" href="javascript:document.forms[0].submit();" target="link_nav3" onMouseOver="extAreaOver('site_template','top'); document.getElementById('topBullet').style.color='red';" onMouseOut="extAreaOut('site_template','top'); document.getElementById('topBullet').style.color='transparent';">Top</a><span id="topBullet" class="bulletOn">&larr;</span><br>
<a id="link_to_map" onClick="document.getElementById('placementLocal').value='header'; document.getElementById('placementPage').value='page';" href="javascript:document.forms[0].submit();" target="link_nav3" onMouseOver="extAreaOver('site_template','header'); document.getElementById('headerBullet').style.color='red';" onMouseOut="extAreaOut('site_template','header'); document.getElementById('headerBullet').style.color='transparent';">Header</a><span id="headerBullet" class="bulletOn">&larr;</span><br>
 
</form>

Open in new window

Author

Commented:
Thanks.

Now the error says,
"document.forms[0] is undefined"

Author

Commented:
I changed my link to the example below, added an id to the form, and now I only get the error that says,

"all is undefined"


href="javascript:" onClick="document.getElementById('placementLocal').value=top; document.getElementById('placementPage').value=all; document.forms['LinkElementEdit'].submit();"

Open in new window

Try
document.forms["LinkElementEdit"]

Open in new window

Try this. Always put text in quotes
href="#" onClick="document.getElementById('placementLocal').value='top'; document.getElementById('placementPage').value='all'; document.forms['LinkElementEdit'].submit();"

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Genius! Thanks a ton!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.