Vous êtes sur la page 1sur 3

<script> setTimeout('waitForRadioButtonsCreation(\'MyProjectWorkingMode\')',100); function waitForRadioButtonsCreation(ddlCaption) { if (getPromptSelectField(ddlCaption) && document.

getElementById(ddlCaption + ' Div')) createRadioButtonsFromDropDownList(ddlCaption); else setTimeout('waitForRadioButtonsCreation(\'MyProjectWorkingMode\')',100); } function jumpParents (elem,num) { for (j=0; j<num; j++) { elem = elem.parentElement; } return elem; } // get the ddl by the caption of the prompt function getPromptSelectField (caption) { var selects = document.getElementsByTagName("SELECT"); for (i=0; i<selects.length; i++) { if (selects[i].id) { if (selects[i].id.substring(0,4) == 'saw_') { // found prompt caption, see if it's the one we're looking for if (jumpParents(selects[i],2).firstChild.innerText == caption) { return selects[i]; } } } } } function getPromptGoButton (caption) { // find the caption's span var spans = document.getElementsByTagName('SPAN'); var captionSpan; for (j=0; j<spans.length; j++) { if (spans[j].innerText == caption) { captionSpan = spans[j]; break; } } // go to the button var tr = jumpParents(captionSpan, 6); return tr.childNodes[1].firstChild.firstChild.firstChild.firstChild.firstChild ; // return the span, father of the anchor } function createRadioButtonsFromDropDownList(ddlCaption) { ddl = getPromptSelectField(ddlCaption); var options = new Array(); // the options in the ddl for (i=0; i<ddl.childNodes.length; i++) { // collect options from the ddl options[i] = ddl.childNodes[i].innerText; } // hide the ddl and create the radio buttons ddl.style.display = 'none'; var radioButton;

var text; for (i=0; i<options.length; i++) { radioButton = document.createElement("<input type='radio' name='" + ddlCapti on + "_group' />"); radioButton.id = 'radio' + ddlCaption + i; radioButton.setAttribute("type","radio"); radioButton.setAtribute("group",'group_' + ddlCaption); radioButton.value = options[i]; text = document.createTextNode(options[i]); ddl.parentElement.appendChild(radioButton); ddl.parentElement.appendChild(text); } // check the right radio button var currentMode = document.getElementById(ddlCaption + 'Div').innerText; // we 'll select the right radio button by this value var radioButtons = ddl.parentElement.getElementsByTagName('INPUT'); for (i=0; i<radioButtons.length; i++) { if (radioButtons[i].value == currentMode) { radioButtons[i].checked = true; break; } } // beautifiers jumpParents(ddl,2).style.textAlign = 'right'; jumpParents(ddl,7).childNodes[1].style.verticalAlign = 'middle'; jumpParents(ddl,2).firstChild.style.display = 'none'; jumpParents(ddl,2).removeChild(jumpParents(ddl,2).childNodes[1]); jumpParents(ddl,7).childNodes[1].style.verticalAlign = 'bottom'; //ddl.parentElement.dir = 'rtl'; // for right-to-left users // replace the GO button with new one. The new will set the user's option in t he ddl and call the original go button var goButton = getPromptGoButton(ddlCaption); var goButtonClone = goButton.cloneNode(true); // true to also clone the childr en goButton.id = ddlCaption + 'GoButton'; goButton.style.display = 'none'; goButtonClone.firstChild.href = 'javascript:goFromRadioButtons(\'' + ddl.id + '\',\'' + goButton.id + '\');'; goButtonClone.firstChild.onclick = 'javascript:goFromRadioButtons(\'' + ddl.id + '\',\'' + goButton.id + '\');'; goButton.parentElement.appendChild(goButtonClone); } function goFromRadioButtons (ddlId, goButtonId) { // find which radio button is selected, select the matching option in the ddl and click on the original go button var ddl = document.getElementById(ddlId); var radioButtons = ddl.parentElement.getElementsByTagName('INPUT'); for (i=0; i<radioButtons.length; i++) { if (radioButtons[i].checked) { ddl.selectedIndex = i; break; } } document.getElementById(goButtonId).firstChild.click(); }

</script>

Vous aimerez peut-être aussi