0

I have created a search form with RSForm Pro, unfortunately it isn't working.

The concept is to do a TAG Search all the Fields of the Form (Select and Radio) have values which are part of a URL which has to be build when you press on "suchen" (Fields are depending on each other and the button will only show up when all steps have been completed).

I am using this code trying to accomplish this:

function suchen() {
    var URLBase = "http://ego.pc-helfer.eu/index.php?option=com_tags&view=tag";
    var TrailingFixedData = "&types[0]=1";

    finalURL = URLBase + document.getElementsByClassName('value1').value +
    document.getElementsByClassName('value2').value +         
    document.getElementsByClassName('value3').value + 
    document.getElementsByClassName('value4').value + 
    document.getElementsByClassName('value5').value + TrailingFixedData;
}

But when I press "suchen" the Chrome console tells me:

Uncaught ReferenceError: suchen is not defined

I can see the script is being loaded, but I still get this message.

url of the site: http://ego.pc-helfer.eu/produktsuche/substrattkompass

1
  • FYI document.getElementsByClassName returns a NodeList object. Perhaps you need to write something like this: document.getElementsByClassName('value1')[0].value
    – Farahmand
    Commented Aug 29, 2014 at 12:04

1 Answer 1

0

Remove onclick="suchen()" and use these lines of code:

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('#Suchen').on('click', function() {
        // Your Code Here.
        window.location.replace(finalURL);
    });
});
</script>
2
  • Nice got it to work, although at first it didn't work with document.getElementsByClassName so i had to switch to document.getElementById. Now the URL is being build properly. Now the main issue is that i don't want the form to be reset. So i will probably have to make an Ajax request or isn't this possible?
    – Hyperxx
    Commented Aug 30, 2014 at 9:22
  • AJAX is an option. Another option is to fill the form from URL parameters via javascript or jQuery after the page is loaded. Another option is to create a plugin and fill the form in server side. You will need to write a javascript function to show all parts of the form.
    – Farahmand
    Commented Aug 30, 2014 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.