Forums

Custom Code Result Positioning

hopemanjohn 10 Dec, 2012
Hi,

Can anyone help me?

I have a very simple form which has just 2 fields, (tracker_1 and name_1) and a submit button which saves to a database and redirects the user after submit.

My problem is that I require to run a small custom code within the form to produce a ten digit number. I can get it to work and display the result of the custom code at the start of the form but what I want is for the result to be displayed within the (tracker_1) field instead.

Any ideas?

This is the custom code:

<!DOCTYPE html>
<html>
<style type="text/css">
#demo {text-align: center}
</style>
<body>
<p id="demo">Your Tracker Code Is<br>
<script>
 document.write( Math.floor((Math.random()*10000000000)+1) );
</script>
</p>
</body>
</html>


Can anyone suggest how to load it into the tracker_1 field instead of displaying it as above.
GreyHead 10 Dec, 2012
Hi John,

Give the tracker_1 input an ID of tracker_1 if it isn’t already set.

Drag a Load JS action into the On Load event of your form and add this code to it:
window.addEvent('domready', function() {
  $('tracker_1').value = Math.floor((Math.random() * 10000000000) +1));
});

Bob
hopemanjohn 10 Dec, 2012
Hi Bob,

I have tried that but I just get an empty box!!

The Java Script does not return and enter a value.

John
GreyHead 10 Dec, 2012
Hi John,

Please post a link to the form so I can take a quick look.

Bob
GreyHead 11 Dec, 2012
Hi John,

I made some small changes to the script which is working OK without the template. See
your_domain.com/index.php?option=com_chronoforms&chronoform=silver_register&tmpl=component


With the template you are loading two different versions of JQuery as well. They both need to be put into noConflict mode if you plan to use MooTools and ChronoForms on the site. Please see this FAQ

Bob
hopemanjohn 11 Dec, 2012
Hi Bob,

Thanks again for your prompt reply.

I thought that it was the proverbial clash between MooTools and jQuery so I have reverted to my tried and tested jQuery free template and everything works great.

I am sure that for the many designers, like me, who have limited programming skills and if you are going to use Chronoforms as a core component, then it is easier to use a non jQuery based template if you can find one. They are not easy to find and if you have to pay for them it can be a costly mistake if you get it wrong.

However, for some of the less skilled designers out there, here are some words of caution:

1: Beware of template design software such as Artisteer. They use jQuery in their template designs. To use them with some of the better joomla components, you will require to introduce code patches to get them to work. Don’t get me wrong, Artisteer is a good template design software product, highly recommended, but beware it uses jQuery libraries.

2: If after downloading a new component or module you find that your core structural components, such as chronoforms do not operate as they did before, or their validation stops working or some of your JS scripts fail to work then you probably have a MooTools/ jQuery clash. Just step back through your installations until you find the culprit.

3: It is always a good idea when developing a site, if you are like me not very experienced, to keep on your site one of the standard joomla templates. They do not use jQuery and are great for switching to if you are trying to investigate problems.

Thanks again Bob
John H.
GreyHead 12 Dec, 2012
Hi John,

Thank-you, useful comments. I'll probably add them to a FAQ shortly.

There is some progess on the jQuery front, a year or so ago it was rare to find jQuery on a Joomla! site, now it is becoming very common and Joomla! 3.0 has included the jQuery library in the core code for the first time and it is loaded alongside MooTools (but set in noConflict mode). I've no idea what lead to this decision (it seems a bit odd to use both libraries unless MooTools is now deprecated).

Max has worked to make ChronoForms jQuery friendly and either the current release or the next one* should be OK working alongside jQuery without needing jQuery in noConflict mode.

Bob

* I know that he has had a beta version for a few weeks, not sure if it has been released yet.
This topic is locked and no more replies can be posted.