2009-06-16 6 views
3

Voici le Script-Pourquoi une classe CSS JavaScript brise-t-elle ce script?

<script language=javascript> 
function apply() 
{ 
    document.form1.sub.disabled=true; 
    if(document.form1.chk.checked==true) 
    { 
    document.form1.sub.disabled=false; 
    } 
    if(document.form1.chk.checked==false) 
    { 
    document.form1.sub.enabled=false; 
    } 
} 
</script> 

Si j'utilise cette html il n'a pas work--

<input class="field checkbox" type="checkbox" name="chk" onClick="apply()" value="accept" /> 

Cependant, cela ne pas non plus work--

<input class="field" type="checkbox" name="chk" onClick="apply()" value="accept" /> 

Mais cela fonctionne -

<input class="checkbox" type="checkbox" name="chk" onClick="apply()" value="accept" /> 

Donc, si la classe "field" est là, elle brise le JS. Bien sûr que je peux l'enlever, mais je veux savoir pourquoi ça ne marche pas?

Merci!

EDIT Désolé, les gens, voici toute la page. Le CSS contrôle juste la position de l'élément, il ne devrait pas interférer avec le JS autant que je sache ...? -

<?php 
session_start(); 
if(!isset($_SESSION['referrer'])){ 
    //get the referrer 
    if ($_SERVER['HTTP_REFERER']){ 
     $referrer = $_SERVER['HTTP_REFERER']; 
    } else { 
     $referrer = "unknown"; 
} 
//save it in a session 
$_SESSION[’referrer’] = $referrer; // store session data 
} 

//grab campaign var from url 
$campaign = $_GET['campaign']; 

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

<title>Beerfest Packages Sweepstakes - Blue Ridge Country</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script type="text/javascript" src="scripts/wufoo.js"></script> 
<link rel="stylesheet" href="css/structure.css" type="text/css" /> 
<link rel="stylesheet" href="css/form.css" type="text/css" /> 
<link rel="stylesheet" href="css/theme.css" type="text/css" /> 
<script language=javascript> 
function apply() 
{ 
    document.form1.sub.disabled=true; 
    if(document.form1.chk.checked==true) 
    { 
    document.form1.sub.disabled=false; 
    } 
    if(document.form1.chk.checked==false) 
    { 
    document.form1.sub.enabled=false; 
    } 
} 
</script> 
</head> 

<body id="public"> 

<img id="top" src="images/top.png" alt="" /> 
<div id="container"> 

<h1><a href="">Wufoo</a></h1> 

<form class="wufoo" action="insert.php" method="post" name="form1"> 

    <div class="info"> 
     <h2>Register to Win &amp; Subscribe to Blue Ridge Country</h2> 
     <div>Now's your chance to not only register to win our free beerfest tickets and getaway, but also receive the #1 magazine in the Blue Ridge Mountains!</div> 
    </div> 

    <ul> 

    <li class="section first"> 
     <h3>Your information</h3> 
     <div>Whether you're registering to win or subscribing to the magazine (or both!) we need your info!</div> 
    </li> 

    <li> 
    <label class="desc">Name <span class="req">*</span></label> 
     <span> 
     <input class="field text" size="8" value=""/> 
     <label>First</label> 
     </span> 

     <span> 
     <input class="field text" size="3" value=""/> 
     <label>M.I.</label> 
     </span> 

     <span> 
     <input class="field text" size="14" value=""/> 
     <label>Last</label> 
     </span> 
    </li> 
    <li> 
    <label class="desc">Email <span class="req">*</span></label> 
     <div> 
     <input class="field text medium" type="text" name="email" maxlength="100" value="" /> 
     </div> 
     <p class="instruct">Don't worry, we won't spam you, share or sell your email address!</p> 
    </li>  
    <li> 
    <label class="desc">Address <span class="req">*</span></label> 
     <div> 
     <input class="field text medium" type="text" maxlength="100" value="" /> 
     </div> 
    </li> 
    <li> 
     <span> 
     <input class="field text" size="15" value="" /> 
     <label>City</label> 
     </span> 

     <span> 
     <input class="field text" size="2" value="" /> 
     <label>State</label> 
     </span> 

     <span> 
     <input class="field text" size="5" maxlength="10" value="" /> 
     <label>Zip</label> 
     </span> 
    </li> 

    <li> 
    <label class="desc">Phone <span class="req">*</span></label> 
     <span> 
     <input class="field text" type="text" size="3" maxlength="3" value=""/> - 
     <label>Area</label> 
     </span> 

     <span> 
     <input class="field text" type="text" size="8" maxlength="8" value=""/> 
     <label>Phone</label> 
     </span> 
    </li>  

    <li class="section"> 
     <h3>Legal mumbo jumbo</h3> 
     <div>Don't worry, you're almost done and this is the last bit we need from you!</div> 
    </li> 

    <li> 
    <label class="desc">Official Rules <span class="req">*</span></label> 
     <div> 
     <textarea rows="10" cols="50" class="field textarea medium" readonly="readonly" style="font-size: 0.8em;">1. To enter, complete an online request by submitting this completed form. Or, send a stamped, self-addressed envelope to: "Blue Ridge Country Beerfest Promotion," Leisure Publishing, PO Box 21535, Roanoke, VA 24018, requesting an entry form. Limited to one entry per household. Entries must be received by June 30, 2009. 2. Reservation procedures to come with notification of winning. Package not available during holidays and special events. Notification of prizes will be sent to winners at the email address on the entry form. The odds of winning will depend upon the number of entries. 3. All prizes will be awarded to winners selected by random drawing from all valid entries received. Drawing will be conducted by Leisure Publishing Inc., an independent publisher, whose decisions are final on all matters relating to this sweepstakes. Winners will be notified by email to the address provided on the entry form. Only one prize to a family or household. Due to the nature of this competition, you must be 21 or older to win. Proof of age will be required prior to receiving free tickets to alcohol-related events. 4. Sweepstakes is open to all residents of the U.S. and Canada except advertisers, their employees, their advertising and promotion agencies, and the families of each. Void wherever taxed, restricted or prohibited by law. Prizes are not transferable; may not be exchanged or substituted; cannot be redeemed for cash; must be taken in their entirety; no substitutions permitted. Taxes, if any, are the responsibility of the individual winners. 5. Entry in sweepstakes constitutes permission to use winners’ names and photograph for advertising and publicity purposes, without further compensation to winners. For names of prize winners, send a stamped, self-addressed envelope to: "Blue Ridge Country Beerfest Promotion" — Winners, P.O. Box 21535, Roanoke, VA 24018.</textarea> 
     </div> 
    </li> 

    <li class="section"> 
     <h3>Subscribe/Win!</h3> 
     <div>While you don't have to subscribe to win, we hope you will!</div> 
    </li> 

    <li> 
    <label class="desc">Sweepstakes Selection</label> 
     <div class="col"> 
     <span><input id="choice1" name="mc" class="field radio" type="radio" value="Robots" checked="checked" /> 
     <label class="choice" for="choice1">Robots</label></span> 

     <span><input id="choice2" name="mc" class="field radio" type="radio" value="Monkeys"/> 
     <label class="choice" for="choice2">Monkeys</label></span> 
     </div> 
    </li> 

    <li> 
    <label class="desc">Official Rules</label> 
     <div class="col"> 
     <span><input class="checkbox" type="checkbox" name="chk" onClick="apply()" value="accept" /> 
     <label class="choice">I accept the terms and conditions from the "Official Rules" above.</label></span> 
     </div> 
    </li>  

    <li class="buttons"> 
     <input id="saveForm" class="btTxt" type="submit" name="sub" value="Submit" disabled="disabled" /> 
    </li> 
    </ul> 

    <div style="display: none;"> 
     <input type="hidden" name="referrer" value="<?php echo $referrer; ?>" /> 
     <input type="hidden" name="campaignID" value="<?php echo $campaign; ?>" /> 
    </div> 

</form> 

</div> 
+2

Pouvez-vous poster le CSS? – Maciek

+0

Quel est le message d'erreur? – womp

+1

Les trois versions du HTML fonctionnent pour moi sur FF3. D'autres informations sont nécessaires - quel navigateur utilisez-vous? Quel est le CSS? A quoi ressemble le reste de votre page? –

Répondre

3

Sans attendre votre édition, je peux presque garantir que le problème se trouve dans un autre morceau de code JS sur votre page qui est en train de changer l'état autre chose que vous pensez qu'il est. Je ne vois tout simplement pas que cela puisse être lié à CSS. Je vous conseille de vérifier le DOM et de parcourir la méthode exécutée dans firebug.

Et FWIW Je vais aussi parier que votre fonction doit être réécrite:

function apply() 
{ 
    with(document.form1) { sub.disabled = !chk.checked; } 
} 
Questions connexes