• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 559
  • Last Modified:

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

0
Shaye Larsen
Asked:
Shaye Larsen
  • 4
  • 3
1 Solution
 
HonorGodCommented:
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
sunithnairCommented:
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
 
Shaye LarsenAuthor Commented:
Genius! Thanks a ton!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now