Solved

after changing the form action url using jquery display a different page for each action url

Posted on 2014-11-04
10
385 Views
Last Modified: 2014-11-06
I am currently using jQuery to change the form action url that comes for the select box selected option. I am able to set the action url to the page I want to but after hitting the submit button it won't go to that page.

here is a test page I created on my test site.

http://dev.cotinthenet.com/ELIST.html

here is my mark for setting the action url. As you can see I even set up a alert to make sure its setting the action url but for some reason after hitting the submit button it won't go that page

what am I missing?

Thanks

<script type="text/javascript">
$(document).ready(function(){
 //Function to change Form Action
	$("#listid").change(function(){
		var selected = $(this).children(":selected").text();
		switch(selected){
		case "My Site - Local Customers":
		$("#mc-embedded-subscribe-form").attr('action','//dev.cotinthenet.com/Thanks.html?u=c6e41e6e28b15275e4f53f9b1&amp;id=668339742e');
		alert("Form Action is Changed to '//dev.cotinthenet.com/Thanks.html?u=c6e41e6e28b15275e4f53f9b1&amp;id=668339742e'\n Press Subscribe to Confirm");
		break;		
		case "My Site - Internet Customers":
		$("#mc-embedded-subscribe-form").attr('action','//dev.cotinthenet.com/Thanks1.html?u=c6e41e6e28b15275e4f53f9b1&amp;id=3f8006144b');
	    alert("Form Action is Changed to '//dev.cotinthenet.com/Thanks1.html?u=c6e41e6e28b15275e4f53f9b1&amp;id=3f8006144b'\n Press Subscribe to Confirm");
		break;		
		case "My Site - Tourists":
		$("#mc-embedded-subscribe-form").attr('action','//dev.cotinthenet.com/Thanks2.html?u=c6e41e6e28b15275e4f53f9b1&amp;id=ac67cc21c4');
		alert("Form Action is Changed to '//dev.cotinthenet.com/Thanks2.html?u=c6e41e6e28b15275e4f53f9b1&amp;id=ac67cc21c4'\n Press Subscribe to Confirm");
		break;		
		default:
		$("#mc-embedded-subscribe-form").attr('action','#');
		
	}		
	});
	
	});
</script>

Open in new window

0
Comment
Question by:niceoneishere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40422702
The alert is worthless for diagnostics. you are just setting it with a hard coded value.  You have to alert the contents of the action property of the form.  

Cd&
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 40422710
Thanks for replying and Yes I know the alert is for debugging. Yes I want to set the hard coded values. Its works for what i am trying to achieve. I just need to know why its not taking to the page after hitting the submit button

Appreciate it
0
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 40422746
As CD& said, change your alerts to
alert("Form Action is Changed to '" + $("#mc-embedded-subscribe-form").attr('action') + "'\n Press Subscribe to Confirm");

Open in new window


But it seems this page is working. The problem could lie in the page that you're submitting to. What are those pages doing? What status code are they returning?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40422782
Jan,

It has been a long time since we shared a thread.  I hope you are well.

Cd&
0
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 40422809
<off_topic>
All is good with me. I have a 15 month old baby at home now, so that's the biggest thing going on for me now. The rest is pretty much same-o.
</off_topic>
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 40422931
Ok I think I am not explaining myself correctly I am not interested in what's displaying in the alert boxes. I will be removing them. They are there just for debug purpose only. What I am looking for is when an option is selected, get its corresponding url from the case in the script and add that to the form action and display that page.

Whats currently being done is

1) adds the correct url to the form action but its not going to that page.

I am trying to achieve that I need it to go the page after hitting the submit button
Thanks again
0
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 40422964
I was trying to suggest that perhaps it is actually going to the next page, but that the next page is not returning as you expect. Is there a way, on your server, that you can confirm that the resulting URL is actually being accessed? If so, what is the resulting status code of that page? (If the status code is not 200 and/or no content is being returned, then the page may simply not be redrawing after the form submit, since there is nothing to be drawn.)

As a test, in your form, try adding "http:" in front of your form action URLs. If that returns an error message, then you can see that the form is actually being submitted.
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 40422972
yes the resulting page exists its a very simple page one line saying thanks for joining. here is the result page

http://dev.cotinthenet.com/Thanks.html?u=c6e41e6e28b15275e4f53f9b1&id=668339742e

and it does work with or without http

Thanks again
0
 
LVL 5

Accepted Solution

by:
Jan Louwerens earned 500 total points
ID: 40422994
It looks like this code is interfering with your form submit.
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>

Open in new window


Try removing that part, verifying that your submit works, then debugging this script from there. (You should be able to view javascript errors in your browser's console.)
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 40426833
Thanks
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ebay messages api 6 19
HTTPS for signup & login - HTTP for all other pages 10 51
w3c parsing errors 4 20
WordPress Page Content Lost 2 21
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question