Jump to content

Java Script Pop Up Message


danny_woo

Recommended Posts

Hi guys,

 

So i got this problem with my form. It's a simple form for subscribing to a part of my website.

 

Basically the form consists of 2 input fields, one is 'Name' and the other is 'Email Address'

and the submit button is an image.

 

The problem I have is at the bottom of my form I have two options:

 

<label><input type="radio" name="subscription_status" value="radio" id="subscription_status_0")>Subscribe</label>

 

(This selection is for users to Subscribe to the service) and next i have:

 

<label><input type="radio" name="subscription_status" value="radio" id="subscription_status_1")>Subscribe</label>

 

(This selection is for users to Unsubscribe to the service)

 

What i want to do is if the user selects the "Subscribe" option and then his submit I want a message to popup saying something like "Thank you for subscribing".

 

However if the user selects the "Unsubscribe" option and then hits submit I want a message to popup saying something like "Your subscription has been canceled".

 

At the moment I can only work out how to get one message to popup when you hit the submit button. I need to understand how i can display the right message for the right selection.

 

I hope someone can help us out on this one, I'm really new to java script so please go easy on me!

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/263664-java-script-pop-up-message/
Share on other sites

You would check the value of the input selected,  then pop-up your message. Make the value for each radio different.

 

<label><input type="radio" name="subscription_status" value="0" id="subscription_status_0")>Subscribe</label>
<label><input type="radio" name="subscription_status" value="1" id="subscription_status_1")>Subscribe</label>

 

Something like this would work in jQuery (I haven't tested it):

 

$('#yourFormId').submit(function() {
var myValue = $('input[name="subscription_status"]:checked').val();
  if(myValue == 0){
    //popup message 0 here 
  }
  else{
    //popup message 1 here
  }
return false;
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.