SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast JCsuperstar's Avatar
    Join Date
    Mar 2005
    Location
    Many places.
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing text onFocus?

    Hello,

    I'm new to javascript and I have a question.

    I have an indeterminate number of instances of prices that need to switch between 2 prices depending on which of 2 radio buttons is selected. The javascript is 'echoed' with php and the same javascript appears for every product.

    Here's the radio buttons:

    HTML Code:
    <input type='radio' name='New'  checked value=''/> New
    <input type='radio' name='New' value='' />
    Here is javascript code I'm using: ($price and $refurb are php variables)

    Code:
    <script type=\"text/javascript\" language=\"JavaScript\">
    				if (document.choices.New[0].checked == true) {
            			var price = \"$price\"
            			}
      				 if (document.choices.New[1].checked == true) {
           				var price = \"$refurb\"
            			}
             			document.write(price)
    </script>
    I can get the right pricing to appear upon loading depending upon which radio button I have checked by default but I can't get it to change.

    Does anybody have any suggestions?

    Thanks
    Colin

  2. #2
    SitePoint Enthusiast JCsuperstar's Avatar
    Join Date
    Mar 2005
    Location
    Many places.
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also,

    When I use code like this:

    HTML Code:
    <input type='radio' name='New'  checked value='' onclick='return PriceDeterminator();'/> New
    <input type='radio' name='New' onclick='return PriceDeterminator();' value='' />
    Code:
    <script type=\"text/javascript\" language=\"JavaScript\">
    				function PriceDeterminator() {
    				if (document.choices.New[0].checked == true) {
            			var price = \"$price\"
            			}
      				 if (document.choices.New[1].checked == true) {
           				var price = \"$refurb\"
            			}
             			document.write(price)
             			}
    				</script>
    It loads a new page and displays the last product's price.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •