SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2003
    Location
    georgia, usa
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript newbie - creating a form based on conditional

    Hi all

    I'm trying to let a variable value select what form is displayed.

    <script language="javascript" type="text/javascript">
    <!--
    {
    var p="$90.00"
    if (p == '$90.00')
    {
    document.write(p)
    <form action="https://xxx.xxx.xxx/cgi-bin/script" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="user" value="xxxxxxx">
    <input type="hidden" name="item_name" value="item selected">
    <input type="hidden" name="amount" value="90.00">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="image" src="https://xxx.xxx.xxx/button.gif
    </form>
    }

    else if (p == '$130.00'){}

    else if (p == '$165.00'){}

    else if (p == '$175.00') {}

    else
    document.write("ERROR")
    }


    Now - the document.write(p) is to test that the variable is set.
    After each ELSE IF i would have a variation of the form.
    Tell me why this script does not work? Can you tell i'm a neophyte with Java?


    John

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Maryland, USA
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All the lines in the form needed to be written with document.write. I have made the modification to your code and fixed a few syntax errors. The new code is as follows:

    Code:
    <script language="javascript" type="text/javascript"> 
    <!-- 
    { 
    var p="$90.00" 
    if (p == '$90.00') 
    { 
    document.write(p) 
    document.write('<form action="https://xxx.xxx.xxx/cgi-bin/script" method="post"> ')
    document.write('<input type="hidden" name="cmd" value="_xclick"> ')
    document.write('<input type="hidden" name="user" value="xxxxxxx"> ')
    document.write('<input type="hidden" name="item_name" value="item selected"> ')
    document.write('<input type="hidden" name="amount" value="90.00"> ')
    document.write('<input type="hidden" name="no_note" value="1"> ')
    document.write('<input type="hidden" name="currency_code" value="USD"> ')
    document.write('<input type="image" src="https://xxx.xxx.xxx/button.gif"> ')
    document.write('</form> ')
    } 
    
    else if (p == '$130.00'){} 
    
    else if (p == '$165.00'){} 
    
    else if (p == '$175.00') {} 
    
    else 
    document.write("ERROR") 
    } 
    -->
    </SCRIPT>


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
  •