开发者

javascript validation- rbColorId object is still detected

function submitcheck()
{

var f = document.for开发者_高级运维m1;

if (f.rbTemplate!= null)    
{
    ...
        alert('Please choose template');
        return false;
    ...
}

if (f.rbColorId!= null)
{
    ...
        alert('Please choose template color');
        return false;
    ...
}
}



function ShowColor()
{
    var f= document.form1;
    iTemplate= getSelectedRadioValue(f.rbTemplate);

    var params= "iTemplate="+iTemplate;
    var url= "ajaxColor.php";
    doShowOutput(params, url, retrieveColorsAvailableForThisTemplate);
}


function retrieveColorsAvailableForThisTemplate()
{
    if(httpObject.readyState == 4)
    {
        document.getElementById('showtime').style.display="";
        document.getElementById('showtime').innerHTML= httpObject.responseText;
    }
}



    <input type='radio' name='rbTemplate' id=1 value=1 onclick='ShowColor();'>
<img src="template1.jpg" />

<br />

    <input type='radio' name='rbTemplate' id=2 value=2 onclick='ShowColor();'>
<img src="template2.jpg" />    



    <div id=showtime></div>    

when click on rbTemplate id=1, ajax query will return the available colors for this template into id=showtime

eg:

<table>
<tr>
<td bgColor="#FF0000"><input type=radio name=rbColorId id=1 value=1></td>
<td bgColor="#FF0007"><input type=radio name=rbColorId id=2 value=2></td>
<td bgColor="#FF0003"><input type=radio name=rbColorId id=3 value=3></td>
</tr>

</table>

when click on rbTemplate id=2, ajax return the output as simple message into id=showtime, because this template actually don't have any color selection)

eg: "<p>this template don't have any color</p>"

Problem now is :

Step 1: after I click on rbTemplate id=1 and without select color, then click submit (javascript will prompt me to select color),

Step 2: then I repeat again by clicking on rbTemplate id=2, click submit again, at this time, it shouldn't prompt for color selection, because this second template don't have color. BUT javascript prompt still appear. JS validation still able to detect f.rbColorId (maybe from cache or...)... Help...

Help


As you are just outputting the result from the Ajax call, I'd say you need to change your logic in ajaxColor.php

But if you don't really need the color thing, why not remove the event completely?

<input type='radio' name='rbTemplate' id=2 value=2 />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜