Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Another simple JQuery question
Old 03-15-2010, 04:27 AM Another simple JQuery question
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
Could somebody tell me what is wrong with this script

Code:
$('input.make_purchase').click(
        message = "Hello";
        function(){
            if(message){alert(message); return false;};
         }
    );
The simple idea is to disable the "Make Purchase" input button
and return an alert message.

For some reason it doesnt like the way I assigned the "message" variable.
Returns error message

Code:
missing ) after argument list
        message = "Hello";\n
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-15-2010, 05:35 AM Re: Another simple JQuery question
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
Ok. Fixed. This works.

Code:
$('input.make_purchase').click(function(){
        
    
            var message = 'Hello';
            if(message){alert(message); return false;};
         }
    );
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-15-2010, 10:34 AM Re: Another simple JQuery question
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
OK. I've got this far.
It all works except I'm not sure how to finish.

After clicking the "OK" on the dialogue box I want the form which calculates the shopping cart to submit and run the PHP "post" method.

The form has a class of "update_now":


Code:
$('input.make_purchase').click(function(){
            var coupon_string = $('input#coupon_num').val();
            var coupon_value = $('span.my_coupon_discount').text();
            if(coupon_string&&(coupon_value=='$0')){alert("Oops. You forgot to update your shopping cart before checking out.\n\n Just click 'OK' to do it now.\n\nThank You!"); return false;};
        }
    );
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-15-2010, 11:47 AM Re: Another simple JQuery question
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
The jQuery submit() method is both an event handler, or if not passed an argument, will submit a form automatically. http://api.jquery.com/submit/

Also, you could do it just as easily in plain JavaScript:
Code:
document.getElementById('my-form').submit();
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-15-2010, 12:30 PM Re: Another simple JQuery question
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
Thanks. If I chain this:

Code:
if(coupon_string&&(coupon_value=='$0'))
{alert("Message!"); 
return false; 
$('my-form').submit();};
Will it pause when it hits the Alert and then continue with submitting the form after clicking OK?

Thats what is really stumping me right now.
Do I need to wrap the Alert in another function?
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-15-2010, 01:09 PM Re: Another simple JQuery question
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
The alert will pause the execution, when you hit "ok" the following lines will be executed. However, the line 'return false;" will stop the submit() from happening since it causes the function to exit, so this line should appear at the end.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-18-2010, 12:26 AM Re: Another simple JQuery question
TWD
TWD's Avatar
King Spam Talker

Posts: 1,112
Trades: 0
Thanks a bunch Wayfarer!
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-18-2010, 10:55 AM Re: Another simple JQuery question
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
You're welcome
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Another simple JQuery question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26037 seconds with 12 queries