Undefined error when running jQuery

Hi everyone,

I’m trying to use some jQuery to build the action url in a form element. The code can be viewed here:

When I run the code, I’m getting an “Undefined” error. I wondered if anyone could help me troubleshoot this?

Thanks in advance.

<script type="text/javascript" src="/CatalystScripts/ValidationFunctions.js"></script>

you’re trying to load relative-URL javascript files inside a fiddle.

Thanks for the reply. I’ve removed that line for now but it’s still not working. When I type into name input field the action url should be built and display in the html but it’s not doing this. Are you able to help further?

Without that line present, code executes as expected.
Define your problem better?

The form element looks like this:

<form id="catwebformform18913" name="catwebformform18913" method="post" onsubmit="return checkWholeForm18913(this)" enctype="multipart/form-data">

When the jQuery runs it should look like this:

<form id="catwebformform18913" name="catwebformform18913" method="post" onsubmit="return checkWholeForm18913(this)" enctype="multipart/form-data" action="/FormProcessv2.aspx?WebFormID=36833&OID=13364325&OTYPE=1&EID=0&CID=0">

It should build the url by concatenating “actions”, url + params.

It doesn’t do this but I’m unsure why.

It does for me.

Have you told the fiddle to Run again after removing the offending line?

Yeah I have. I type something into the name field then press run but nothing happens. Is that what you did?

Open Inspector panel, focussed on Form element.
Remove the offending line of HTML.
Click the Run button.
Type a single character into any form field.
Observe that the Form element now has an action attribute.

Sorry I can’t see the inspector - can you let me know where it is?

I mean your browser’s inspector tool. F12, in most browsers.

Yes you’re right - that one did work. Could you check this other one for me as this one doesn’t work:

I’d really appeciate it.

Your form tag does not have an ID.

Yeah I thought that might have been the case. Can I make it work without the ID? I’m quite new to jQuery and I’m trying to adapt some code.

Normally forms use a unique id as there doesn’t tend to be a good reason for the same form code to be used in multiple places on the page.

You can do without a unique id though. You can use document.forms[0] to get the first form that’s on the page.

Or in jQuery terms, $("form") (or if there are multiple forms, you can target specific forms with $("form")[0] etc)

Thanks for both comments.

Or in jQuery terms, $("form") (or if there are multiple forms, you can target specific forms with $("form")[0] etc)

So can you let me know how the jQuery would need to be adjusted. Again I’m sorry but I’m really struggling with this.

Actually there are 3 different forms on the page so I don’t think I’ll be able to do that.

I added an ID but it still is not working. Can you view the code at this new fiddle?

Sorry it’s working now - I forgot the third idea in the jQuery. Thanks so much to both of you for your help.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.