SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Manchester
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forms and images

    I see that there is a problem using images to submit forms and I am struggling with the same but the examples I have found use nice clean javascript and I can't see anything similar to mine for my shop.

    I am using the following...
    <FORM NAME="itemsform">
    Blub about the product

    <INPUT TYPE="value" NAME="id<% =RS("code_no") %>quant" VALUE="1" SIZE=3 style="font-family: Verdana, Geneva, Helvetica; font-weight: regular; font-style: regular; font-size: 10px; color: #000000; height:18px">
    <INPUT NAME="id<% =RS("code_no") %>number" TYPE="Hidden" VALUE="<% =RS("code_no") %>">
    <INPUT TYPE="button" NAME="<% =RS("code_no") %>add" VALUE="<%=txt_buy_now%>" class="button" onclick="top.center.cart.addItem('<% =RS("item") %>','<% =RS("price") %>', document.itemsform.id<% =RS("code_no") %>quant.value, document.itemsform.id<% =RS("code_no") %>number.value, '<% =RS("shipping") %>')">

    If I use an image as per the text below it adds the item fine but doesn't return the page search. Instead I get a blank page.

    <INPUT TYPE="value" NAME="id<% =RS("code_no") %>quant" VALUE="1" SIZE=3 style="font-family: Verdana, Geneva, Helvetica; font-weight: regular; font-style: regular; font-size: 10px; color: #000000; height:18px">
    <INPUT NAME="id<% =RS("code_no") %>number" TYPE="Hidden" VALUE="<% =RS("code_no") %>"><br>
    <INPUT NAME="<% =RS("code_no") %>add2" TYPE="image" class="button" onclick="top.center.cart.addItem('<% =RS("item") %>','<% =RS("price") %>', document.itemsform.id<% =RS("code_no") %>quant.value, document.itemsform.id<% =RS("code_no") %>number.value, '<% =RS("shipping") %>')" VALUE="<%=txt_buy_now%>" src="/images/addtobasket.gif" width="113" height="30">


    Anyone any idea where I am going wrong...

    Thanks

  2. #2
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey can you use the [ CODE ] forum feature to post your code? That way it will be formatted properly and I won't have to manually indent everything.


  3. #3
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that clicking on the button is submitting the form, and I think what you really want it to do is just to process your onclick event. You are getting a blank page because after your onclick event is run, the form is submitted.

    You can solve this problem in a couple of ways:
    1. Add return false; at the end of your onclick event
    2. Change the input type=image to a regular img tag with an onclick event.


    Hope this help,
    Charles

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Manchester
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    You are without a shadow of a doubt a STAR!!

    Sorry about the code bit, I didn't know about that so have tried it below along with the code that worked if anyone ever has the same problem...


    Code:
    <INPUT TYPE="value" NAME="id<% =RS("code_no") %>quant" VALUE="1" SIZE=3 style="font-family: Verdana, Geneva, Helvetica; font-weight: regular; font-style: regular; font-size: 10px; color: #000000; height:18px">
     <INPUT NAME="id<% =RS("code_no") %>number" TYPE="Hidden" VALUE="<% =RS("code_no") %>"><br>
    <input type="image" src="../images/addtobasket.gif" name="id<% = rs("code_no")%>add" value="<%=txt_add%>" onClick="top.center.cart.addItem('<% = rs("item")%>','<% = rs("price")%>', document.itemsform.id<% = rs("code_no")%>quant.value, document.itemsform.id<% = rs("code_no")%>number.value, '<% =RS("shipping") %>'); return false;">
    Hows that??


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
  •