PDA

View Full Version : how can i pass span'id to .js page



msg2ajay
08-27-2007, 02:28 AM
Code: ( text )
<html>
function dscptAction(){
var obj = document.getElementsByTagName("span");
for(i=0;i<obj.length;i++){
............
.........
.....
}

<body>
<span>
<table >
<tr>
<td>
<select value="" onclick="dscptAction()">
</option value="1">1</option>
</option value="2">2</option>
</td>
</tr>
</table>
</span>
<span id ="dscpt">
<table>
</table>
</span>
<span id ="addr">
<table>
</table>
</span>
</body>
</html>


i am want to place my javascript{"dscptAction()"} function to the .js file, In this case how can i pass the 'span'Id to javascript.

for example:



Code: ( text )
<html>
<script language="javascript" src="../../js/module.js"></script> // this contains my dscptAction() function....
<head>


</head>
<body>
<span id="name">
<table >
<tr>
<td>
<select value="" onclick="dscptAction()">
</option value="1">1</option>
</option value="2">2</option>
</td>
</tr>
</table>
</span>
<span id ="dscpt">
<table>
</table>
</span>
<span id ="addr">
<table>
</table>
</span>

</body>
</html>





thx,
Ajay

???
08-27-2007, 03:10 AM
How are you passing it? You're not even using parameters. I think you could do: An external file:


function dscptAction(span){
var obj = document.getElmentsByTagName(span);
for(i=0;i<obj.length;i++){
............
.........
.....
}
}/*You forgot this one...*/

Then add:


onclick="dscptAction('theSpan');"

I think that would work, but I don't even understand what you're trying to do.

msg2ajay
08-27-2007, 03:43 AM
my module.js file
----------------


<script type="text/javascript>

function doDscptAction(field, span){
var dscptVal= field.value;
var obj = span;
for(i=0;i<obj.length;i++){
if (dscptVal == '001'){
document.getElementById("enq").style.display="inline";
document.getElementById("nam").style.display="inline";
document.getElementById("cpActno").style.display="none";
document.getElementById("trandt").style.display="none";
}
</script>


my html code:
--------------


<html:html>
<head>
<script language="javascript" src="../../js/module.js"></script>
<head>
<body>

<tr>
<td width="13%" class="labeltext">Transaction Code</td>
<td width="1%" class="blanktext">:</td>
<td colspan="4" class="blanktext">
<html:select property="dscpt" styleClass="dropdown" value="${X00.dscpt}" onchange="doDscptAction(this,spanid)">// iam trying to pass this,spanid here
<html:option value="001">001 - Agent1 </html:option>
<html:option value="002">003 - Nostro </html:option>
</html:select>
</td>
</tr>
</table>

<span id="trans" style="display:none">
<table width="100%">
<tr>
<td width="13%" class="labeltext">Transaction Type</td>
<html:select property="transtype" styleClass="dropdown" value="${X00.transtype}"onclick="forex(this)">
<html:option value=""></html:option>
<html:option value="02">02 - SENEX</html:option>
<html:option value="04">04 - ONLINE</html:option>
</html:select>
</td>
</tr>
</table>
</span>
</body>
</html:html>