homepage Welcome to WebmasterWorld Guest from 54.204.182.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Checkbox Problem
the_el_man

5+ Year Member



 
Msg#: 3334862 posted 2:27 pm on May 9, 2007 (gmt 0)

Hi I've tried everything but cannot get this to work.

In a shopping cart, currently the warranty box is not checked by default. I would like it to be checked, but also include the js that it adds for add the warranty price to cart in the onclick part.(see below for code)

<INPUT type="checkbox" name="is_warranties[{$products[product].cartid}]" {if $products[product].is_warranty eq 'Y'}checked{/if} value="Y" onclick="javascript: document.cartform.submit();" />

is this possible? thanks.

 

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 2:35 pm on May 9, 2007 (gmt 0)

Well, the /> on the end says your using XHTML, and you're using, I can't remember the name for it, but I'm calling it a bare property.

With HTML you can have <INPUT ..... checked>, with XHTML it's a little different, you have to use checked="checked". It's like HTML4.01/STRICT but even stricter.

Also tag names have to be lower case (input, not INPUT). Try this...I've broken it down to make it easier to read:

<input type="checkbox"
name="is_warranties[{$products[product].cartid}]"
{if $products[product].is_warranty eq 'Y'}checked="checked"{/if}
value="Y"
onclick="javascript: document.cartform.submit();" />

Your onclick should still work, but if you've changed the default, I guess you'd have to include the warranty in your cart by default also, otherwise the box would be checked but the totals wouldn't match.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 2:44 pm on May 9, 2007 (gmt 0)

hi. Thanks for the speedy reply. New code works same as old. I havent changed default. I am looking for the cart part you talked about now. I'll keep you posted. The site definitely not XHTML. the previous coder was a joke.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3334862 posted 2:57 pm on May 9, 2007 (gmt 0)

It's worth noting that you should NOT be relying on JavaScript alone to add the price. What would happen for users with JavaScript disabled? Instead (or in addition to), your form processing page should handle adding the price if the checkbox is checked.

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 3:09 pm on May 9, 2007 (gmt 0)

Yes Fotiman is right, most retail sites I've used have an 'update cart' button somewhere. If they are JS disabled they'll have to do this.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 3:17 pm on May 9, 2007 (gmt 0)

The site has a "click here if you dont have JS" part.

I cannot work out this box thinng though. Any ideas what I should be searching for?

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 4:11 pm on May 9, 2007 (gmt 0)

ok, you've got:
<input .... checked ....>

But that is preceeded by:
[fixed]{if $products[product].is_warranty eq 'Y'}[/quote]

I'll be quite honest, I have no idea what language that is from, I've never seen that syntax before. But by the looks of it the product list is generated from a loop, $product[...] would appear to be an array, of which .is_warranty tells it if the box is to be checked or not.

I'd suggest looking at the code that adds the item to the cart, and see if it sets a default there, if not add a line to set is_warranty to "Y".

What language is this code? It's no HTML/JS that I've ever seen.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3334862 posted 4:50 pm on May 9, 2007 (gmt 0)


In a shopping cart, currently the warranty box is not checked by default. I would like it to be checked

Do you mean that you would like it to be checked by default? You are currently using a server side language to determine if it should be checked:


{if $products[product].is_warranty eq 'Y'}

Therefore, if you want it to be checked by default, you should make $products[product].is_warranty = 'Y' by default. In other words, change your server side code.


but also include the js that it adds for add the warranty price to cart in the onclick part.

I'll be honest, I don't understand your English here. Could you try rephrasing it so I better understand what you're trying to accomplish?

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 5:09 pm on May 9, 2007 (gmt 0)

Debrowski.. Thanks, I will check tomorrow at work

Fotiman...
Sorry. Its hard to explain.. I'll try again.

1. Currently when you click BUY NOW, it goes to cart and you have the option to check a box for warranty. When you check it, it refreshes (ONClick), and warranty box checks, and on the total price part, you see sub total, warranty (appears when checked), total.

What my boss wants.
Warranty to be on by default. i.e. You have to click to uncheck.

Problems Ive Had.
When I make it check by default, it does not show or add in any way the actual warranty to the total.

Thanks for you time guys.

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 5:11 pm on May 9, 2007 (gmt 0)

Urrrr...didn't I just say that?

Hey Foti, OT slightly, I read up on XHTML vs HTML4.01/STRICT. Apparently it's ill-advised, whilst it works in text/html, it's not technically valid. So it will work as browsers will interpret it into HTML, but when browsers actually support application/xhtml then it will all break.

Obviously the details are far more extended but that's the general gist of it. I'll stay away for now, thanks for the advice!

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3334862 posted 5:31 pm on May 9, 2007 (gmt 0)


Warranty to be on by default. i.e. You have to click to uncheck.

Like I said, in your server side code, you should be setting $products[product].is_warranty to 'Y' when it is initially created. This is a server-side issue.


Problems Ive Had.
When I make it check by default, it does not show or add in any way the actual warranty to the total.

I would suspect that's because you're not actually changing the value of is_warranty to be 'Y' in your server side code. To me, this really sounds like more of a server-side issue than a JavaScript one.

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 6:02 pm on May 9, 2007 (gmt 0)

I agree, this is server-side, so I quote from my earlier post, with a little boldening just in case you didn't notice before....

But by the looks of it the product list is generated from a loop, $product[...] would appear to be an array, of which .is_warranty tells it if the box is to be checked or not.

I'd suggest looking at the code that adds the item to the cart, and see if it sets a default there, if not add a line to set is_warranty to "Y".


Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3334862 posted 6:22 pm on May 9, 2007 (gmt 0)

@Dabrowski

Hey Foti, OT slightly,

Actually, it's VERY off topic in the context of the current thread, but I don't mind. ;-)


I read up on XHTML vs HTML4.01/STRICT. Apparently it's ill-advised, whilst it works in text/html, it's not technically valid. So it will work as browsers will interpret it into HTML, but when browsers actually support application/xhtml then it will all break.

Well, that's not entirely correct (you'd still need to serve the page as application/xhtml+xml before it would break).

If you're serving XHTML, ideally it should be served with the application/xhtml+xml mime type. However, IE6 doesn't support this mime type at all and will just display a DOM tree instead. The only alternative is to serve your XHTML document as text/html. XHTML 1.1 or greater can't be served as text/html (no spec. allows this), so the debate then becomes HTML 4.01 vs. XHTML 1.0.

Essentially, an XHTML 1.0 document that is served as text/html will probably not translate as expected to an application/xhtml+xml mime type. Authors that validate regularly, though, will probably find it easier to make the transition.

If you're serving your XHTML 1.0 document as text/html, one of the main advantages of using XHTML (catching errors early) is lost, because the browser will be treating it as tag soup and doing it's own thing. Since HTML 4.01 contains everything that XHTML 1.0 contains, there is then very little reason to use XHTML 1.0 in the real world and serving it as text/html.

With all that said, over the past few days I've been reconsidering this. I find that there is no longer a need for long convoluted comment/CDATA strings wrapping your <style> and <script> contents (the browsers that needed this are long extinct). Also, I personally try to validate often. So moving from XHTML 1.0 served as text/html to XHTML 1.0 served as application/xhtml+xml would probably not be as painful for me. I would go into such an endeavor expecting to have to make some changes. Likewise, issues like SHORTTAG minimization have proven to not be an issue at all, as there are no browsers that interpret HTML4 like that (nor is it likely that any new browser would suddenly start supporting that).

I no longer feel quite as strongly as I once did about avoiding XHTML 1.0. But at the same time, what's the point if it's just going to be served as HTML anyway? Granted, it can help you develop some slightly better (stricter and cleaner) coding habits to develop in XHTML.

My only other concern is that I don't know yet whether serving an XHTML document with a full DOCTYPE declaration will still put the browser into Quirks mode. If so, that alone would definately be a case for avoiding writing XHTML and serving it as text/html.

To sum up, I'm still sticking with HTML 4.01, but I no longer feel quite as anti-XHTML as text/html. :-)

[edited by: Fotiman at 6:25 pm (utc) on May 9, 2007]

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 7:34 pm on May 9, 2007 (gmt 0)

XHTML 1.1 or greater can't be served as text/html (no spec. allows this), so the debate then becomes HTML 4.01 vs. XHTML 1.0

That's what I found too.

Since HTML 4.01 contains everything that XHTML 1.0 contains, there is then very little reason to use XHTML 1.0 in the real world and serving it as text/html

That's also what I decided.

Likewise, issues like SHORTTAG minimization have proven to not be an issue at all

Apparently, in text/html, a <br /> should be interpreted in HTML4 as <br>&gt; but no browsers are that strict.

I don't know yet whether serving an XHTML document with a full DOCTYPE declaration will still put the browser into Quirks mode.

No, you can use them, you have:
<?xml ....
<!DOCTYPE ....
<html xmlns ....

Apparently that works without triggering quirks.

To sum up, I'm still sticking with HTML 4.01

Agreed. Apparently XHTML 1.0 is a good stepping stone up to XHTML 1.1+, but I don't see the point if there's nothing to gain. I know the theory so I'll just jump straight up when the time comes.

Anyway....back to the point, el_man let us know how you get on.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3334862 posted 9:05 pm on May 9, 2007 (gmt 0)



I don't know yet whether serving an XHTML document with a full DOCTYPE declaration will still put the browser into Quirks mode.

No, you can use them, you have:
<?xml ....

Actually, I think you may be incorrect about that. For one thing, you can't include the <?xml portion cuz IE sucks.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 8:59 am on May 10, 2007 (gmt 0)

I'd suggest looking at the code that adds the item to the cart, and see if it sets a default there, if not add a line to set is_warranty to "Y".

Ok this is out of my depth. I only know how to change / delete JS. I understand bits but I dont know how to add new stuff. Any help would be greatly appreciated.

the add to cart button code is this
{include file="buttons/button.tpl" button_title=$lng.lbl_add_to_cart href=$href title=$title style=$style}

The referenced button.tpl is this
{* $Id: button.tpl,v 1.16.2.2 2005/04/22 11:54:46 max Exp $ *}
{if $config.Adaptives.platform eq 'MacPPC' && $config.Adaptives.browser eq 'NN'}{assign var="js_to_href" value="Y"}{/if}
{if $type eq 'input'}{assign var="img_type" value='INPUT type="image"'}{else}{assign var="img_type" value='IMG'}{/if}
{assign var="js_link" value=$href¦regex_replace:"/^\s*javascript\s*:/Si":""}
{if $js_link eq $href}{assign var="js_link" value="javascript: self.location='`$href`'"}
{else}{assign var="js_link" value=$href}{if $js_to_href ne 'Y'}{assign var="onclick" value=$href}{assign var="href" value="javascript: void(0);"}{/if}{/if}
{if $style eq 'button' && ($config.Adaptives.platform ne 'MacPPC' ¦¦ $config.Adaptives.browser ne 'NN')}
<TABLE border="0" cellspacing="0" cellpadding="0" onclick="{$js_link}" style="cursor: pointer;" valign="middle"{if $title ne ''} title="{$title}"{/if}>
<TR><TD><{$img_type} src="{$ImagesDir}/but1.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}></TD>
<TD class="Button" valign="middle" nowrap><FONT class="Button">&nbsp;{$button_title}&nbsp;</FONT></TD>
<TD><IMG src="{$ImagesDir}/but2.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}></TD></TR>
</TABLE>
{else}
<NOBR><A href="{$href}"{if $onclick ne ''} onclick="{$onclick}"{/if}{if $title ne ''} title="{$title}"{/if}{if $target ne ''} target="{$target}"{/if}><FONT class="FormButton">{$button_title} <{$img_type} {include file="buttons/go_image.tpl" full_url='Y'}></FONT></A></NOBR>
{/if}

Where am I supposed to add the line and what would I need to add. If this is asking too much just say. I appreciate what youve done.

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 11:48 am on May 10, 2007 (gmt 0)

Not at all, I welcome the challenge!

Right, this code would seem to insert a table for the 'Add to Cart' button, based on a couple of images, but with an all important <a> tag which should point at the submit code.

Now, the actual code on the page is either going to be, again I've made this easier to read...

<TABLE border="0" cellspacing="0" cellpadding="0" onclick="{$js_link}" style="cursor: pointer;" valign="middle"{if $title ne ''} title="{$title}"{/if}>
<TR>
<TD><{$img_type} src="{$ImagesDir}/but1.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}></TD>
<TD class="Button" valign="middle" nowrap>
<FONT class="Button">&nbsp;{$button_title}&nbsp;</FONT>
</TD>
<TD>
<IMG src="{$ImagesDir}/but2.gif" width="7" height="14" border="0"{if $title ne ''} title="{$title}"{/if}>
</TD></TR>
</TABLE>

Or....

<NOBR>
<A href="{$href}"{if $onclick ne ''} onclick="{$onclick}"{/if}{if $title ne ''} title="{$title}"{/if}{if $target ne ''} target="{$target}"{/if}>
<FONT class="FormButton">{$button_title} <{$img_type} {include file="buttons/go_image.tpl" full_url='Y'}></FONT>
</A></NOBR>

Depending on some other stuff. Earlier in that horrible code. It's so hard to read isn't it?!

Now, I hope this is getting clearer to you, the submit code will either be in the TABLEs onClick parameter, or the As href parameter, depending which bit of code it uses.

Look this up by viewing page source on the actual site, rather than the actual server side code, and that should give you the location of the page/script that actually adds the item to the cart.

That's the next step, so report back with that.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 12:02 pm on May 10, 2007 (gmt 0)

Hi.

The actual code on the site is

<table border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td><table onclick="javascript: document.orderform_16630_1159189253.submit();" style="cursor: pointer;" valign="middle" border="0" cellpadding="0" cellspacing="0">
<tbody><tr><td><img src="/skin1/images/but1.gif" border="0" height="14" width="7"></td>
<td class="Button" nowrap="nowrap" valign="middle"><font class="Button">&nbsp;Buy Now&nbsp;</font></td>
<td><img src="/skin1/images/but2.gif" border="0" height="14" width="7"></td></tr>
</tbody></table>
</td>

</tr></tbody></table>

I didnt realise we could write in Courier. What does his mean in terms of the solution?

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 12:24 pm on May 10, 2007 (gmt 0)

Hehe, yes you can write in courier, but as you can see it won't run over blank lines!

ok, your table onclick is:
javascript: document.orderform_16630_1159189253.submit();"

So that's what the submit code does. Now look for a form called "orderform_16630_1159189253" (the number will probably be different every time), and look at it's action="" property. This should be the add cart code.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 12:39 pm on May 10, 2007 (gmt 0)

<TD>{include file="buttons/buy_now.tpl" style="button" href="javascript: document.orderform_`$product.productid`_`$product.add_date`.submit();"}</TD>

Ok I believe this is it. Is it simply a case of adding the warranty $ code? Also for some reason Ive found there is a Buy Now and Add to Cart button both do the same.. as I said the previous guy was a joke. He used a package to do it I believe.

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 12:47 pm on May 10, 2007 (gmt 0)

Again, this is a copy of the code above. It is a simple change, it's just finding where to put it that's the hard part!

You need to see where this form submits to, and post the code from that script.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 1:19 pm on May 10, 2007 (gmt 0)

Sorry for the delay. I tried changing the $is_warranty to yes in the following code, as suggested by a friend. Did not work. This code is from cart.php.

[quote]# Add to cart amount of items that is not much than in stock
#
if ($config["General"]["unlimited_products"]=="N" && $added_product["product_type"]!="C")
if ($amount > $added_product["avail"])
$amount = $added_product["avail"];

if ($productid && $amount) {

if ($amount < $added_product["min_amount"]) {
func_header_location ("error_message.php?access_denied&id=31");
}

$found = false;
if (!empty($active_modules["Egoods"]))
$product_distribution = func_query_first_cell("SELECT distribution FROM $sql_tbl[products] WHERE productid='$productid'");
else
$product_distribution = "";
if (!empty($cart) and @$cart["products"] and $added_product["product_type"]!="C") {
foreach ($cart["products"] as $k=>$v) {
if (($v["productid"] == $productid) && (!$found) && ($v["options"] == $product_options) && empty($v["hidden"])) {
if ((float)$v["free_price"]!= $price)
continue;
$found = true;
if (($cart["products"][$k]["amount"] >=1) && (!empty($product_distribution) ¦¦!empty($subscribed_product))){
$cart["products"][$k]["amount"]=1;
$amount=0;
}
$cart["products"][$k]["amount"] += $amount;
$cart["products"][$k]["is_warranty"] = $is_warranty;
}
}
}

if (!$found) {
#
# Add product to the cart
#
if (!empty($price))
# price value is defined by customer if admin set it to '0.00'
$free_price = abs(doubleval($price));

$cartid = func_generate_cartid($cart["products"]);
if(empty($cart["products"]))
$add_to_cart_time = time();
$cart["products"][]=array("cartid"=>$cartid, "productid"=>$productid,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$product_distribution,"is_warranty" => $is_warranty);

if(!empty($active_modules["Product_Configurator"]))
include $xcart_dir."/modules/Product_Configurator/pconf_customer_cart.php";
}[/quote]

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 1:48 pm on May 10, 2007 (gmt 0)

ok, again the code is 2 parts, the top bit checks to see if the item is already in the cart, and amends it if it is.

These 2 lines:
$cart["products"][$k]["amount"] += $amount;
$cart["products"][$k]["is_warranty"] = $is_warranty;

Look like they change the quantity, and set the warranty to default. Else this line:
$cart["products"][]=array("cartid"=>$cartid, "productid"=>$productid,"amount"=>$amount, "options"=>$product_options, "free_price"=>@price_format(@$free_price),"distribution"=>$product_distribution,"is_warranty" => $is_warranty);

Adds a new cart item, as you can see warranty is again set by the default $is_warranty.

As that variable isn't defined in this piece of code, it must come from elsewhere. Looking at the other code if you override this and set it to "Y" instead, that should do it, but you really should find where $is_warranty is coming from and do it there.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 1:54 pm on May 10, 2007 (gmt 0)

I tried setting to Y, no good.

I will post you on results from $is_warranty in a sec.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 1:58 pm on May 10, 2007 (gmt 0)

OK there is

in Cart.tpl
{if $products[product].warranty gt 0}
<BR>
<INPUT type="checkbox" name="is_warranties[{$products[product].cartid}]" {if $products[product].is_warranty eq 'Y'}checked{/if} value="Y" onclick="javascript: document.cartform.submit();" /><strong><a href="pagename.com /pages.php?pageid=14">EXTENDED WARRANTY - STRONGLY RECOMMENDED</a></strong>
{/if}

and in product.tpl

{if $product.warranty gt 0}
<TR><TD colspan="2"><INPUT type="checkbox" name="is_warranty" value="Y"><strong>{$lng.txt_include_warranty}</strong></TD></TR>
{/if}

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 2:50 pm on May 10, 2007 (gmt 0)

Aah, ok. The bit from product.tpl...is that the page that actually displays the product info? What if you set checked on that check box?

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 2:56 pm on May 10, 2007 (gmt 0)

how would I make it default to be on that page? onclick?

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3334862 posted 3:07 pm on May 10, 2007 (gmt 0)

Nope, simpler than that...

<INPUT type="checkbox" name="is_warranty" value="Y" checked>

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 3:07 pm on May 10, 2007 (gmt 0)

Done.

the_el_man

5+ Year Member



 
Msg#: 3334862 posted 3:07 pm on May 10, 2007 (gmt 0)

Done. Sent you a PM

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved