SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot Rio's Avatar
    Join Date
    Nov 2001
    Location
    United Kingdom
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with FORM

    Hello guys,

    I have a part of html form like this one below...
    Code:
    <form name="Subscribe" action="https://select.worldpay.com/wcc/purchase" method="post" />
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="4">
      <tr>
        <td colspan="3"><img src="../images/common/logo_popwin.gif"></td>
      </tr>
      <tr>
        <td colspan="3">Select Subscription Type</td>
      </tr>
      <tr>
        <td class="BlueSmall">Individual</td>
        <td>
          <input name="amount" type="radio" value="1" />Selection One
        </td>
        <td>
          <input name="amount" type="radio" value="2" />Selection Two
        </td>
      </tr>
      <tr>
        <td>Corporate</td>
        <td>
          <input name="amount" type="radio" value="3" />Selection Three</td>
        <td">
          <input name="amount" type="radio" value="4" />Selection Four
        </td>
      </tr>
      <tr>
        <td>Other Amount</td>
        <td colspan="2">
          <input name="amount" type="text" class="Input190" onFocus="AmountClear(this)"
    ... which works with this JavaScript to uncheck the radio buttons when a user onFocus on the text field.
    Code:
    function AmountClear(amountField) {
      if (amountField) {
        for (i=0; i<document.Subscribe.amount.length; i++) {
          if (document.Subscribe.amount[i].value != "") {
            document.Subscribe.amount[i].checked = false
          }
        }
      }
    }
    Is it possible to write a script to clear the text field when a user checks one of the radio buttons? The trouble here is both radio buttons and text field have a same name "amount". This is because the form is submitted to a third party online payment system which I can't change and I have to use the name "amount" for transaction to happen. Please help.

  2. #2
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use the id to identify the element in the script that should solve your problem.

    e.g.

    Code:
    <script>
    function X()
    {
      Input = document.getElementById("Clear");
    }
    </script>
    <input id="Clear" />
    Sorry haven't more time to explain, but give the elements you need to know about an id and then you can have different ids. Then you can get hold of any element by using its id and manipulate it.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  3. #3
    SitePoint Zealot Rio's Avatar
    Join Date
    Nov 2001
    Location
    United Kingdom
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dale.

    I didn't have to use getElementById(), though. Maybe I got it wrong somewhere but it didn't work with it. Instead I assigned id attribute to input tag in question and did

    document.FormName.idname.value='';

    and hey presto! Radio buttons clears the text field.

    Thanks a million for sorting me out.

  4. #4
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah that works, but I don't think its cross-browser compatible.
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  5. #5
    SitePoint Zealot Rio's Avatar
    Join Date
    Nov 2001
    Location
    United Kingdom
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a good point. I haven't tested on NS 4.x yet. Works fine so far on NS7.0 on Mac.

    I wonder what I did wrong with using getElementById() in the first place.


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
  •