?
Solved

OnChange Submit Form if value = 1 otherwise don't...

Posted on 2013-05-15
2
Medium Priority
?
446 Views
Last Modified: 2013-05-15
Hello,

My JavaScript is rubbish!

I have the following cod, which is a slider.  I use the same include file on two different pages - one I want to submit the form when the slider is changed, and that works fine, but the other I do not want the slider OnChange to submit the form, and for the user to submit it manually.

This is possibly an easy one for you JS experts - I want the line: document.forms['form1'].submit(); to be ignored if a variable, set in ASP Classic = 1 otherwise do not submit.

Here's my full code (and thanks in advance!):

<script type="text/javascript" charset="utf-8">
jQuery("#Slider2").slider
			(
			{
			from: 0,  
			to: 10000000,  
			heterogeneity: ['25/500000', '50/1000000', '75/5000000'],
			scale: [0, '|', '500k', '|' , '1m', '|', '5m', '|', '+10m'],
			limits: false,
			step: 50000,
                calculate: function( value ){
                    var a;
                    if(value<500000){
                        a=value;}
                    if(value>=500000 && value<1000000){
                        a=100000*(Math.floor(value/100000));}
                    if(value>=1000000 && value<=10000000){
                        a=1000000*(Math.floor(value/1000000));}
                    return (a);
                  },
			dimension: '',
            callback: function(value)
                {
                    jQuery("#sale-slide-min").val(jQuery("#Slider2").slider("calculatedValue").split(";")[0]);
                    jQuery("#sale-slide-max").val(jQuery("#Slider2").slider("calculatedValue").split(";")[1]);
					document.forms['form1'].submit();
                }
			}
			);
			</script>

Open in new window

0
Comment
Question by:Nico2011
[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
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 39167517
Hi,
your final requirement statement does not make sense:
IF value == 1 then do no submit else do no submit
therefore I assume if Value== 1 then do submit else no submit

Javascript cannot access ASP variables, therefore you will have to create e.g. a hidden form element with the value like:
<% if here comes your asp code then
Reponse.Write("<input type=""hidden"" id=""DoSubmit"" value=""1"" />")
%>


Then you can check:
var shouldSubmitOccur =jQuery("#DoSubmit").val();

if (shouldSubmitOccur == 1) {
document.forms['form1'].submit();
}

HTH
Rainer
0
 

Author Closing Comment

by:Nico2011
ID: 39167541
Hi Rainer,

Thanks very much - works perfectly.

Have a good day!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 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