Jump to content

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;
});

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.