views:

269

answers:

2

I'm looking for help on how to code the following:

I want to create a pop-up or Javascript item that allows users to accept the terms of completing an offer for me. Once they have accepted the terms, I would like that offer that they agreed to do to go under the account in a section or tabled labeled "Offers".

Please advise on how to code this. If I'm not descriptive enough, please let me know.

+1  A: 

You can use javascripts confirm. It will create a dialogue which will allow a user to press "Ok" or "Cancel". You can implement the following:

<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
    var answer = confirm("Do you agree to the terms of Service?")
    if (answer){
     window.location = "http://yoursite.com/offers.html";
    }
    else{
     alert("You must agree to continue")
    }
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Continue">
</form>
</body>
</html>

If you want this dialogue to appear when the page loads you can put onLoad="confirmation()" in the body tag. And alternative to a javascript confirmation box would be something along the lines of the following, I know some people really don't like popups and confirmations:

<input type="button" onclick="window.location='http://yoursite.com/offers.html';" value="Agree">
<input type="button" onclick="alert('You must agree to the terms of service');" value="Disagree">
Sam152
Thank you for such a speedy response!Is there a way I can get the name of that offer to appear under the user as pending or completed? For example: User accepts the terms of service for the offer> the offers name now appears in a table or other field on the "offers.html" page.
Sure, instead of directing the user to http://yoursite.com/offers.html you could point them to http://yoursite.com/offers.html?offer=Free Goats . You could then pick up the value on offers.html using php or whatever server side solution you are employing.
Sam152
A: 

Instead of an intrusive pop-up, why not have a checkbox that the user has to check in order to continue? If the checkbox isn't checked, then the form either won't submit or an error message could appear, telling the user (s)he didn't accept the terms.

Unless there's a specific reason you need to use JavaScript, I would try to stay away from JavaScript for functionality like this, especially considering that users can just turn JavaScript off.

For example (using JavaScript to prevent the form from submitting):

<form name="offerForm" action="/offer" method="post" onsubmit="return this.elements['agreeTerms'].checked;">
    <!-- the rest of your form goes here -->
    <input type="checkbox" name="agreeTerms" id="agreeTerms" value="1" /> <label for="agreeTerms">I agree to the terms.</label><br />
    <input type="submit" value="Submit Offer Form" />
</form>

On the server side, I'm assuming you have a relational database behind everything. Let's say you have a users table, an offers table, and a users_offers bridge table to denote which users have accepted which offers.

Using the example above, you would only add a new record to the users_offers bridge table if agreeTerms came back with a value of "1". If the checkbox isn't checked, then agreeTerms won't have a value.

If you could edit your question with specifics concerning your situation (server-side language you use, basic database table information, etc.), I'll be able to fill in some more details.

Christopher Parker