Results 1 to 4 of 4

Thread: VBSript - Fancy radio buttons

  1. #1
    Join Date
    Mar 2009
    Posts
    6

    VBSript - Fancy radio buttons

    Hi guys

    I have been trying to figure this out for a couple of days now. I am trying to make fancy radio buttons but dynamically using VBScript. I don't want to use JavaScript.

    I am actually writing an HTA and want this functionality. I have attached the code and put it below. I get it as far as displaying a picture in place of the radio button but nothing happens when I click on it.

    <html>
    <head>
    <title>My HTML application</title>
    <HTA:APPLICATION
    APPLICATIONNAME="My HTML application"
    ID="MyHTMLapplication"
    SCROLL="no"
    INNERBORDER="no"
    VERSION="1.0"
    />
    <style type="text/css">
    <!--
    .radEC {
    padding: 0 0 0 0;

    background: url(radioEC.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    .radEU {
    padding: 0 0 0 0;

    background: url(radioEU.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    .radDC {
    padding: 0 0 0 0;

    background: url(radioDC.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    .radDU {
    padding: 0 0 0 0;

    background: url(radioDU.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    input.styled {
    display: none;
    }
    -->
    </style>
    </head>

    <script language="VBScript">

    Sub Window_OnLoad
    subInit
    End Sub

    Sub subInit

    Dim inputs, span(), a

    Set inputs = document.getElementsByTagName("input")

    a = -1

    For Each rad In inputs
    If rad.type = "radio" And rad.className = "styled" Then
    a = a + 1
    ReDim Preserve span(a)
    Set span(a) = document.createElement("span")
    span(a).id = "rad" & a
    If rad.Disabled = True Then
    If rad.Checked = True Then
    span(a).className = "radDC"
    Else
    span(a).className = "radDU"
    End If
    Else
    If rad.Checked = True Then
    span(a).className = "radEC"
    Else
    span(a).className = "radEU"
    End If
    End If
    rad.parentNode.insertBefore span(a),(rad)
    span(a).onClick = Chr(34) & "funClear'"& rad.name & "','" & span(a).id & "','" & a & "'" & Chr(34)
    End If
    Next

    End Sub

    Function funClear(rad, span, value)
    Dim radio
    Set objRad = document.getElementByID("rad")
    Set objSpan = document.getElementByID("span")
    For Each radio In objRad
    If radio.checked And radio.value = value Then
    objSpan.className = "radDU"
    radio.checked = False
    Else
    objSpan.className = "radDC"
    radio.checked = True
    End If
    Next
    End Function

    Sub subTest
    MsgBox "Hello"
    End Sub

    </script>

    <body bgcolor="white">

    <!--Add your controls here-->

    <input type="textbox" name="txbTest1" />
    <input type="radio" name="radTest1" value="1" class="styled" />

    <br />

    <span id="testSpan" onClick="subTest">Test</span>

    <!--{{InsertControlsHere}}-Do not remove this line-->

    </body>
    </html>
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by milnet; 10-05-2010 at 06:51 PM. Reason: Forgot to add pictures.

  2. #2
    Join Date
    Dec 2007
    Posts
    1,736

    Re: VBSript - Fancy radio buttons

    Response.Write "<TD align=""left"">" & NewPrice * VarConvert & " <input type=""radio"" name=""WhichPrice"" value = " & v(i, 1) & " onclick=""RadioItem(" & v(i, 1) & ")""></TD>"

    Response.Write "<TD align=""left"">" & NewPrice * VarConvert & "<input type=""radio"" name=""WhichPrice"" value=" & v(i, 1) & " onclick=""RadioItem(" & v(i, 1) & ")""></TD>"

    Next..

    v(i, 1) could be either

    'toup1' record 1
    'toup2' record 2
    'toup3' record 3

    ...my vbscript reads as follows

    <script language="vbscript">

    Function RadioItem(Item)

    If document.Baco.WhichPrice(0).checked Then
    Baco.YachtTxt.Value = document.Baco.WhichPrice(0).value
    Else
    Baco.YachtTxt.Value = document.Baco.WhichPrice(1).value
    End If

    End Function
    </script>

  3. #3
    Join Date
    Mar 2009
    Posts
    6

    Re: VBSript - Fancy radio buttons

    Thanks JAMES_911. What I want to do though is make everything dynamic so that I can just dump the code into any script and it will change the radio buttons (or even check boxes).

    Any ideas?

    I am going to continue working on it today and hopefully make some headway.

  4. #4
    Join Date
    Mar 2009
    Posts
    6

    Re: VBSript - Fancy radio buttons

    I managed to figure it out. Code as follows:


    <html>
    <head>
    <title>My HTML application</title>
    <HTA:APPLICATION
    APPLICATIONNAME="My HTML application"
    ID="MyHTMLapplication"
    SCROLL="no"
    INNERBORDER="no"
    VERSION="1.0"
    />
    <style type="text/css">
    <!--
    .radEC {
    background: url(radioEC.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    .radEU {
    background: url(radioEU.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    .radDC {
    background: url(radioDC.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    .radDU {
    background: url(radioDU.png) no-repeat;
    width: 15px;
    height: 15px;
    }
    input.styled {
    display: none;
    }
    -->
    </style>
    </head>

    <script language="VBScript">

    Sub Window_OnLoad
    subInit
    End Sub

    Sub subInit

    Dim inputs, span(), a, rad

    Set inputs = document.getElementsByTagName("input")

    a = -1

    For Each rad In inputs
    If rad.type = "radio" And rad.className = "styled" Then
    a = a + 1
    ReDim Preserve span(a)
    Set span(a) = document.createElement("span")
    span(a).id = rad.name & rad.value
    If rad.Disabled = True Then
    If rad.Checked = True Then
    span(a).className = "radDC"
    Else
    span(a).className = "radDU"
    End If
    Else
    If rad.Checked = True Then
    span(a).className = "radEC"
    Else
    span(a).className = "radEU"
    End If
    End If
    rad.parentNode.insertBefore span(a),(rad)
    span(a).onClick = GetRef("funClear")
    End If
    Next

    End Sub

    Function funClear
    Dim strGroup, strRad, objects, object
    strGroup = me.nextSibling.name
    strRad = me.nextSibling.value
    Set objects = document.getElementsByName(strGroup)
    For Each object In objects
    If object.value = strRad And object.checked = False Then
    object.checked = True
    object.previousSibling.className = "radEC"
    Else
    object.checked = False
    object.previousSibling.className = "radEU"
    End If
    Next
    End Function

    </script>

    <body bgcolor="white">

    <!--Add your controls here-->

    <input type="radio" name="radTest1" value="1" class="styled" />
    radTest1 1
    <input type="radio" name="radTest1" value="2" class="styled" />
    radTest1 2
    <input type="radio" name="radTest1" value="3" class="styled" />
    radTest1 2<br />
    <input type="radio" name="radTest2" value="1" class="styled" />
    radTest2 1
    <input type="radio" name="radTest2" value="2" class="styled" />
    radTest2 2

    <!--{{InsertControlsHere}}-Do not remove this line-->

    </body>
    </html>

Similar Threads

  1. Replies: 6
    Last Post: 01-07-2011, 10:21 PM
  2. BBM Fancy Smiley Icons a virus???
    By Jagadbandu in forum Portable Devices
    Replies: 3
    Last Post: 20-09-2010, 03:02 PM
  3. Retrieve information with radio buttons
    By CitricAcid in forum Software Development
    Replies: 4
    Last Post: 13-05-2009, 03:11 PM
  4. Sony Vaio Pocket: The Fancy Mystery Netbook Leaked
    By Cyk in forum Portable Devices
    Replies: 2
    Last Post: 29-12-2008, 09:32 AM

Tags for this Thread

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
  •  
Page generated in 1,713,489,998.73076 seconds with 18 queries