How to change a buttons value based on user selections

Posted on 2011-10-12
Last Modified: 2012-05-12
Have some HTML code . The HTML consists of some textboxes such as name, company,email, address and a dropdown list containing 3 items ( a,b and c).

When the listbox has been released I am looking for JavaScript/php to check that all textboxes contain something, email is valid , and the 'value ' of the submit button at the bottom contains the listbox value multiplied by 10 dollars - for example button says
<buy at $30>.
any ideas much appreciated
Question by:plambkin1
    LVL 24

    Accepted Solution

    JQuery has a great validation plugin. See
    LVL 107

    Assisted Solution

    by:Ray Paseur
    Agree with mankowitz -- jQuery rocks.

    But that said, you will still have to validate all of the data fields all over again on the server side after the form is submitted.  Nice people will not cause you a problem, but hack-bots will copy your form, create a raw post string, bypass all of the javascript and inject toxic venom directly into your server-side script.  Your script needs to be able to withstand receiving garbage, viruses, etc. from the external input.

    There is a mantra about it: Accept Only Known Good Values.  That does not mean "exclude bad values" -- the hackers can think of more bad values than you can exclude.  Instead it means test for data types and reasonability.  If you expect to receive an email address from the form, check that it is well-formed and routable.  If you expect an integer, test to see that it is, in fact, an integer. Etc, etc.  Most professionals would have a sanitize filter for every possible form input.

    So go ahead and use jQuery validation - it's great tool for making your site attractive and easy to use.  Just don't mistake it for anything like any kind of security!

    Best of luck with your project, ~Ray

    Author Comment

    Is Jquery difficult to learn - How many hours are required?

    Thanks a million.
    LVL 107

    Assisted Solution

    by:Ray Paseur
    Among my colleagues jQuery is not considered difficult to learn.  It's one of those lightbulbs that shines brightly, like when a PHP novice discovers the power of strtotime().  But my colleagues are professional programmers who do this stuff every day.  Their general consensus goes something like this, "jQuery implements the good parts of JavaScript and makes it easy to use."

    Make a Google search for learn jquery and you're off to the races.  I can't really tell you how many hours are needed to learn it because I don't know your background.  If you understand the principles of computer science and you are already fluent in JavaScript and object-oriented design patterns it will come to you quickly, just a matter of practicing with the syntax.  In any case, good examples abound.  It is a very popular thing!

    Author Closing Comment

    Great - thanks a million

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    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…

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now