Submit form and Set Values with JavaScript

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

LVL 1
Shaye LarsenAsked:
Who is Participating?
 
sunithnairConnect With a Mentor Commented:
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

0
 
HonorGodSoftware EngineerCommented:
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

0
 
Shaye LarsenAuthor 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...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
sunithnairCommented:
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

0
 
Shaye LarsenAuthor Commented:
Thanks.

Now the error says,
"document.forms[0] is undefined"
0
 
Shaye LarsenAuthor 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

0
 
sunithnairCommented:
Try
document.forms["LinkElementEdit"]

Open in new window

0
 
Shaye LarsenAuthor Commented:
Genius! Thanks a ton!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.