Javascript redirection in Article

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
cff
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Oct 24, 2018 10:49 am

Javascript redirection in Article

Post by cff » Wed Nov 07, 2018 2:43 pm

Hi,

I have some joomla articles to display my prices table. I need several articles to display several prices (for simple coupon system).

So I have my main price articles with a COUPON field form.

Code: Select all

<form class="form-inline" name="myForm" action="/index.php?option=com_content&view=article&id=15&Itemid=229"
onsubmit="return validateForm()" method="post">
<label for="fname">Code Promo:</label>
<input type="text" name="fname" value="PROMO2018">
<input class="btn btn-success" type="submit" value="Valider ce code">
</form>
If user doesn't type PROMO2018, there is an error popup. Otherwise, user is redirected by form to my other prices article with disount applied.

Code: Select all

<script>
function validateForm() {
    var x = document.forms["myForm"]["fname"].value;
    if (x != "PROMO2018") {
        alert("Le code PROMO n'est pas bon. Désolé. :-( ");
        return false;
    }
}
</script>
This tiny javascript hack let me managing my sales with a simple 1 coupon system for my product.

I would like now to work with several coupons. In fact, I need a 2nd one for another discount. So it will redirect to another joomla article prices with other prices.

So I wrote this javascript:

Code: Select all

<script>
function validateForm() {
    var x = document.forms["myForm"]["fname"].value;
    if (x == "PROMO2018") {
       document = "index.php?option=com_rsform&view=rsform&formId=8&Itemid=484";
        
    }
	else
	{	
		if (x == "ETUDIANTBDX") 
		{
			  location = "index.php?option=com_rsform&view=rsform&formId=4&Itemid=232";
		
		}
		else
		{
			alert("Le code PROMO n'est pas bon! Veuillez essayer un autre svp.");
			return false;
		}
	}
	
	
	

}
</script>
But it doesn't work! :-(


Does anyone can tell me why user is not redirected to appropriate page when submiting coupon form.

THanks for your help.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 35847
Joined: Sat Apr 05, 2008 9:58 pm

Re: Javascript redirection in Article

Post by Webdongle » Sun Nov 11, 2018 1:50 am

What are you trying to achieve?
There may be a better approach.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein


Post Reply

Return to “Joomla! 3.x Coding”