Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript Submit

Status
Not open for further replies.

Jawa

Programmer
Joined
Feb 21, 2002
Messages
74
Location
US
I am using the following javascript to submit a form via an href and also pass a variable:

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
function doit (selectedtype)
{
document.ecom.Action2.value=selectedtype;
document.ecom.submit();
}
-->
</script>

The call is as follows:
<input type=&quot;hidden&quot; name=&quot;Action2&quot;>
<a href=&quot;javascript:doit('Edit')&quot;>Edit Product</a>


The problem I am having is that sometimes it works and then other times it does not. It almost appears as if CF is missing the Action2 variable when it is being passed.

Does anyone have any experience with this and what I could do to rectify the problem?

Thank you!


 
I have a couple of suggestions, and they all relate to how browsers may interpret your code. I don't have any ideas of how ColdFusion may be to blame.[ol][li]I assume that your form name is &quot;ecom&quot;, since that's how you refer to it in your code. I would recommend using the most basic JavaScript syntax to refer to this form you can, to ensure that it works the way you intend -- in this case, change your references to document.ecom to the original JavaScript syntax document.forms[&quot;ecom&quot;].[/li][li]This may be a no-brainer, but it's caught me more times than I care to admit: make sure there is no form element named &quot;submit&quot; -- this will conflict with the form object's submit() method.[/li][li]Add a value=&quot;&quot; to the <input name=&quot;Action2&quot;> tag. All hidden form fields should have a value attribute by default, but it couldn't hurt.[/li][li]I've had trouble in the past with using the javascript: syntax in the HREF attribute to pass text parameters -- it has to do with certain characters that have special meaning in the HREF attribute. I would recommend either moving the javascript call to the onclick handler of the <a> tag, or else using a simple numerical parameter in the function calls which your function would then decode to put the correct value in the <input> tag's value.[/li][/ol]
Just some ideas out of the blue -- if none of these do it, you might post your entire code, or give more information on specifically what error you get when it doesn't work.
 
Thank you, however no go :(

In any case here if a code snippet:

<form action=&quot;categories2.cfm&quot; method=&quot;POST&quot; name=&quot;ecom&quot;>
<input type=&quot;hidden&quot; name=&quot;Action2&quot;>
<a href=&quot;javascript:doit('View Category and Sub-Category List')&quot;>View Category List</a>
</form>


Then on categories2.cfm

blah blah....
<cfelseif NOT comparenocase(Action2, &quot;View Category and Sub-Category List&quot;)>
<cflocation url=&quot;catlist.cfm?Parent_ID=#Parent_ID#&ShowAll=Yes&quot; addtoken=&quot;No&quot;>

blah blah....blah blah....

I feel as if I have looked this so long that I just don't see the obvious. But you never know!
 
It may be the spaces in the parameter you pass to the doit() function. Since you're never really displaying the value of that parameter, I would shorten all these parameters as much as possible, and definitely eliminate any spaces, punctuation, or special characters.

For example, in the code sample you provided, I would change doit('View Category and Sub-Category List') to doit('viewList') -- then don't forget to change the code on the categories2.cfm page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top